add configs from file, continue develpoment on hubs
This commit is contained in:
@@ -76,6 +76,9 @@ func Init(ctx context.Context) {
|
||||
CREATE TABLE IF NOT EXISTS hubs ()
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
creator_id UUID NOT NULL REFERENCES users(id),
|
||||
name TEXT NOT NULL,
|
||||
allow_user_color BOOLEAN DEFAULT TRUE,
|
||||
rgba BIGINT NOT NULL DEFAULT 0 CHECK (rgba BETWEEN 0 AND 4294967295),
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
`)
|
||||
if err != nil {
|
||||
@@ -118,7 +121,7 @@ func Init(ctx context.Context) {
|
||||
_, err = dbConn.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS hub_user_roles ()
|
||||
user_id UUID PRIMARY KEY NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
role_id SMALLINT NOT NULL REFERENCES hub_roles(role_id)
|
||||
role_id SMALLINT NOT NULL REFERENCES hub_roles(role_id) ON DELETE CASCADE
|
||||
`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -129,6 +132,7 @@ func Init(ctx context.Context) {
|
||||
hub_id UUID PRIMARY KEY NOT NULL REFERENCES hubs(id) ON DELETE CASCADE,
|
||||
role_id SMALLINT NOT NULL DEFAULT 0,
|
||||
name TEXT NOT NULL,
|
||||
permissions INTEGER NOT NULL DEFAULT 0,
|
||||
rgba BIGINT NOT NULL DEFAULT 0 CHECK (rgba BETWEEN 0 AND 4294967295),
|
||||
`)
|
||||
if err != nil {
|
||||
@@ -316,3 +320,10 @@ func ConnectionGetMessagesBefore(ctx context.Context, before time.Time, connecti
|
||||
}
|
||||
return messages, rows.Err()
|
||||
}
|
||||
|
||||
func HubCreate(ctx context.Context, hub *types.Hub, creator *types.User) error {
|
||||
_, err := dbConn.Exec(ctx, `
|
||||
INSERT INTO hubs (id, creator_id, name, allow_user_color, rgba, created_at) VALUES ($1, $2, $3, $4, $5)
|
||||
`, hub.Id, creator.Id, hub.Name, hub.AllowUserColor, convertions.RgbaToUint32(hub.Color), hub.CreatedAt)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user