Adding support in database for groups and permissions.

This commit is contained in:
sergiotarxz 2021-02-08 15:54:38 +01:00
parent d45ae12c1d
commit b0e9e7c35c
Signed by: sergiotarxz
GPG Key ID: E5903508B6510AC2
3 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,6 @@
DROP TABLE IF EXISTS user_to_group;
DROP INDEX IF EXISTS groups_index;
DROP TABLE IF EXISTS groups;
ALTER TABLE users DROP COLUMN IF EXISTS permissions;
DROP INDEX IF EXISTS users_index;
DROP EXTENSION IF EXISTS hstore;

View File

@ -0,0 +1,22 @@
CREATE EXTENSION IF NOT EXISTS hstore;
CREATE INDEX users_index ON users (
id,
username
);
ALTER TABLE users ADD COLUMN permissions hstore;
CREATE TABLE groups (
id serial PRIMARY KEY,
groupname text UNIQUE NOT NULL,
permissions hstore
);
CREATE INDEX groups_index ON groups (
id,
groupname
);
CREATE TABLE user_to_group (
id_group INTEGER,
id_user INTEGER,
PRIMARY KEY (id_group, id_user),
FOREIGN KEY (id_group) REFERENCES groups (id),
FOREIGN KEY (id_user) REFERENCES users (id)
);

View File

@ -14,6 +14,9 @@ import (
func DB() *sql.DB {
configuration, err := config.New()
if err != nil {
log.Fatal(err)
}
url_postgres, err := configuration.DB.GetURL()
if err != nil {
log.Fatal(err)