wind-c / comqtt

A lightweight, high-performance go mqtt server(v3.0|v3.1.1|v5.0) supporting distributed cluster
MIT License
972 stars 53 forks source link

Postgres schema #43

Closed alex-savin closed 1 year ago

alex-savin commented 1 year ago

Hey,

Hope you are doing well! Could you please help me to find the best way to create postgres database/tables. If it possible may you share a postgres schema?!

Thank you in advance, Alex

wind-c commented 1 year ago

The table names and column names of the two tables can be customized and then configured in the configuration file. See cmd/config/auth-postgresql.yml.

schema reference:

CREATE TABLE mqtt_user ( id serial PRIMARY KEY, username varchar(32) NOT NULL UNIQUE, password varchar(32) NOT NULL, allow smallint DEFAULT 1 NOT NULL, created timestamp with time zone DEFAULT NOW(), updated timestamp );

allow options: 0 deny, 1 allow

CREATE TABLE mqtt_acl( id serial PRIMARY KEY, username varchar(32) NOT NULL, topic varchar(256) NOT NULL, access smallint DEFAULT 3 NOT NULL, created timestamp with time zone DEFAULT NOW(), updated timestamp );

CREATE INDEX mqtt_acl_username_idx ON mqtt_acl(username);

access options: 0 deny、1 publish (Write)、2 subscribe (Read)、3 pubsub (ReadWrite)