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)
);
