diff --git a/packages/postgresql/postgresql.go b/packages/postgresql/postgresql.go index d11e156..9b18469 100644 --- a/packages/postgresql/postgresql.go +++ b/packages/postgresql/postgresql.go @@ -81,9 +81,40 @@ func Init(ctx context.Context) { creator UUID NOT NULL REFERENCES users(id), join_role, // TODO set role uuid rgba BIGINT NOT NULL DEFAULT 0 CHECK (rgba BETWEEN 0 AND 4294967295), - user_color_allowed BOOLEAN DEAFAULT FALSE + user_color_allowed BOOLEAN DEAFAULT FALSE, + created_at TIMESTAMP NOT NULL DEFAULT NOW(), ) `) + if err != nil { + panic(err) + } + + _, err = dbConn.Exec(ctx, ` + CREATE TABLE IF NOT EXISTS hub_roles ( + id TINYINT PRIMARY KEY, + parent_id UUID NOT NULL REFERACES hubs(id) ON DELETE CASCADE + name TEXT NOT NULL, + permissions INT NOT NULL DEFAULT 0, + rgba BIGINT NOT NULL DEFAULT 0 CHECK (rgba BETWEEN 0 AND 4294967295), + created_at TIMESTAMP NOT NULL DEFAULT NOW(), + ) + `) + if err != nil { + panic(err) + } + + _, err = dbConn.Exec(ctx, ` + CREATE TABLE IF NOT EXISTS hub_channel ( + id TINYINT PRIMARY KEY, + name TEXT NOT NULL, + permissions INT NOT NULL DEFAULT 0, + rgba BIGINT NOT NULL DEFAULT 0 CHECK (rgba BETWEEN 0 AND 4294967295), + created_at TIMESTAMP NOT NULL DEFAULT NOW(), + ) + `) + if err != nil { + panic(err) + } } func UserSave(ctx context.Context, user *types.User) error {