diff --git a/create-schema.sql b/create-schema.sql index f687a14..f8e77be 100644 --- a/create-schema.sql +++ b/create-schema.sql @@ -1,17 +1,33 @@ -CREATE TABLE users ( +CREATE TABLE users_t ( id INTEGER AUTO_INCREMENT, username VARCHAR(25) NOT NULL, pw VARCHAR(512) NOT NULL, super INT(1) NOT NULL DEFAULT 0, PRIMARY KEY (id) ); -CREATE UNIQUE INDEX users_username ON users (username); +CREATE UNIQUE INDEX users_username ON users_t (username); -CREATE TABLE acls ( +CREATE OR REPLACE VIEW users AS + SELECT username, pw, super + FROM users_t; + +CREATE TABLE acls_t ( id INTEGER AUTO_INCREMENT, - username VARCHAR(25) NOT NULL, + user INTEGER NOT NULL, topic VARCHAR(256) NOT NULL, rw INTEGER(1) NOT NULL DEFAULT 1, -- 1 is read, 2 is write, 3 is readwrite, 4 is subscribe - PRIMARY KEY (id) + PRIMARY KEY (id), + CONSTRAINT `fk_book_author` + FOREIGN KEY (user) REFERENCES users_t (id) + ON DELETE CASCADE + ON UPDATE CASCADE ); -CREATE UNIQUE INDEX acls_user_topic ON acls (username, topic(228)); +CREATE UNIQUE INDEX acls_user_topic ON acls_t (user, topic); + +CREATE OR REPLACE VIEW acls AS + SELECT a.topic, a.rw, + u.username + FROM users_t u, acls_t a + WHERE a.user = u.id; + + diff --git a/readme.md b/readme.md index cba8d2e..cde7e81 100644 --- a/readme.md +++ b/readme.md @@ -84,24 +84,40 @@ Actually, it appears to me that the meaning of this attribute has to be interpre The required schema in the database is - CREATE TABLE users ( - id INTEGER AUTO_INCREMENT, - username VARCHAR(25) NOT NULL, - pw VARCHAR(512) NOT NULL, - super INT(1) NOT NULL DEFAULT 0, - PRIMARY KEY (id) - ); - CREATE UNIQUE INDEX users_username ON users (username); - CREATE TABLE acls ( - id INTEGER AUTO_INCREMENT, - username VARCHAR(25) NOT NULL, - topic VARCHAR(256) NOT NULL, - rw INTEGER(1) NOT NULL DEFAULT 1, -- 1 is read, 2 is write, 3 is readwrite, 4 is subscribe - PRIMARY KEY (id) - ); - CREATE UNIQUE INDEX acls_user_topic ON acls (username, topic(228)); + CREATE TABLE users_t ( + id INTEGER AUTO_INCREMENT, + username VARCHAR(25) NOT NULL, + pw VARCHAR(512) NOT NULL, + super INT(1) NOT NULL DEFAULT 0, + PRIMARY KEY (id) + ); + CREATE UNIQUE INDEX users_username ON users_t (username); + CREATE OR REPLACE VIEW users AS + SELECT username, pw, super + FROM users_t; + + CREATE TABLE acls_t ( + id INTEGER AUTO_INCREMENT, + user INTEGER NOT NULL, + topic VARCHAR(256) NOT NULL, + rw INTEGER(1) NOT NULL DEFAULT 1, -- 1 is read, 2 is write, 3 is readwrite, 4 is subscribe + PRIMARY KEY (id), + CONSTRAINT `fk_book_author` + FOREIGN KEY (user) REFERENCES users_t (id) + ON DELETE CASCADE + ON UPDATE CASCADE + ); + CREATE UNIQUE INDEX acls_user_topic ON acls_t (user, topic); + + CREATE OR REPLACE VIEW acls AS + SELECT a.topic, a.rw, + u.username + FROM users_t u, acls_t a + WHERE a.user = u.id; + + The password is generated using the `pw` tool provided by mosquitto-go-auth, which is included in the image at `/opt/bin`. It can be used either within the container using `docker exec -it /opt/bin/pw`. You may also try to copy it from the container onto your Linux host. It should run, since it is only linked against typical Linux libraries, however, I wouldn't do that. For further information consult the readme and the examples in the mosquitto-go-auth project (https://github.com/iegomez/mosquitto-go-auth or https://github.com/wollud1969/mosquitto-go-auth).