normalized schema

This commit is contained in:
2019-10-10 09:40:24 +00:00
parent 47a91f2db4
commit ae3bbd1453
2 changed files with 54 additions and 22 deletions

View File

@ -1,17 +1,33 @@
CREATE TABLE users ( CREATE TABLE users_t (
id INTEGER AUTO_INCREMENT, id INTEGER AUTO_INCREMENT,
username VARCHAR(25) NOT NULL, username VARCHAR(25) NOT NULL,
pw VARCHAR(512) NOT NULL, pw VARCHAR(512) NOT NULL,
super INT(1) NOT NULL DEFAULT 0, super INT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (id) 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, id INTEGER AUTO_INCREMENT,
username VARCHAR(25) NOT NULL, user INTEGER NOT NULL,
topic VARCHAR(256) 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 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;

View File

@ -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 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 ( CREATE TABLE users_t (
id INTEGER AUTO_INCREMENT, id INTEGER AUTO_INCREMENT,
username VARCHAR(25) NOT NULL, username VARCHAR(25) NOT NULL,
topic VARCHAR(256) NOT NULL, pw VARCHAR(512) NOT NULL,
rw INTEGER(1) NOT NULL DEFAULT 1, -- 1 is read, 2 is write, 3 is readwrite, 4 is subscribe super INT(1) NOT NULL DEFAULT 0,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
CREATE UNIQUE INDEX acls_user_topic ON acls (username, topic(228)); 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 <mosquitto-container> /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. 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 <mosquitto-container> /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). 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).