use uuid for everything
This commit is contained in:
+18
-18
@@ -26,7 +26,7 @@ func DbInit(ctx context.Context) {
|
||||
|
||||
_, err = dbConn.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name TEXT UNIQUE NOT NULL,
|
||||
pass_hash TEXT NOT NULL,
|
||||
pronouns TEXT DEFAULT NULL,
|
||||
@@ -43,8 +43,8 @@ func DbInit(ctx context.Context) {
|
||||
_, err = dbConn.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS user_connections (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
requestor_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
recipient_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
requestor_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
recipient_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
state SMALLINT NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
)
|
||||
@@ -56,7 +56,7 @@ func DbInit(ctx context.Context) {
|
||||
_, err = dbConn.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS direct_messages (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
sender_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
sender_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
receiver_id UUID NOT NULL REFERENCES user_connections(id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
content TEXT NOT NULL
|
||||
@@ -68,10 +68,10 @@ func DbInit(ctx context.Context) {
|
||||
|
||||
_, err = dbConn.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS chat_groups (
|
||||
id SERIAL PRIMARY KEY,
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL,
|
||||
creator_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
creator_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
owner_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
enable_client_colors BOOLEAN NOT NULL DEFAULT true,
|
||||
color_red SMALLINT DEFAULT NULL,
|
||||
color_green SMALLINT DEFAULT NULL,
|
||||
@@ -85,8 +85,8 @@ func DbInit(ctx context.Context) {
|
||||
|
||||
_, err = dbConn.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS chat_group_members (
|
||||
group_id INTEGER NOT NULL REFERENCES chat_groups(id) ON DELETE CASCADE,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
group_id UUID NOT NULL REFERENCES chat_groups(id) ON DELETE CASCADE,
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
joined_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
PRIMARY KEY (group_id, user_id)
|
||||
)
|
||||
@@ -106,7 +106,7 @@ func DbUserSave(ctx context.Context, user *User) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func DbUserDelete(ctx context.Context, id uint32) error {
|
||||
func DbUserDelete(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := dbConn.Exec(ctx, `
|
||||
DELETE FROM users WHERE id = $1
|
||||
`, id)
|
||||
@@ -136,9 +136,9 @@ func DbUserGetGroups(ctx context.Context, user *User) error {
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
user.Groups = make(map[uint32]struct{})
|
||||
user.Groups = make(map[uuid.UUID]struct{})
|
||||
for rows.Next() {
|
||||
var groupId uint32
|
||||
var groupId uuid.UUID
|
||||
if err := rows.Scan(&groupId); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -312,9 +312,9 @@ func DbGroupGetMembers(ctx context.Context, group *Group) error {
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
group.Users = make(map[uint32]struct{})
|
||||
group.Users = make(map[uuid.UUID]struct{})
|
||||
for rows.Next() {
|
||||
var userId uint32
|
||||
var userId uuid.UUID
|
||||
if err := rows.Scan(&userId); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -323,12 +323,12 @@ func DbGroupGetMembers(ctx context.Context, group *Group) error {
|
||||
return rows.Err()
|
||||
}
|
||||
|
||||
func DbGroupAddUsers(ctx context.Context, groupId uint32, userIds *[MaxUsersInGroup]uint32) error {
|
||||
func DbGroupAddUsers(ctx context.Context, groupId uuid.UUID, userIds *[MaxUsersInGroup]uuid.UUID) error {
|
||||
batch := &pgx.Batch{}
|
||||
now := time.Now()
|
||||
var count int
|
||||
for _, uid := range userIds {
|
||||
if uid == 0 {
|
||||
if uid == (uuid.UUID{}) {
|
||||
continue
|
||||
}
|
||||
batch.Queue(`
|
||||
@@ -348,11 +348,11 @@ func DbGroupAddUsers(ctx context.Context, groupId uint32, userIds *[MaxUsersInGr
|
||||
return nil
|
||||
}
|
||||
|
||||
func DbGroupRemoveUsers(ctx context.Context, groupId uint32, userIds *[MaxUsersInGroup]uint32) (int, error) {
|
||||
func DbGroupRemoveUsers(ctx context.Context, groupId uuid.UUID, userIds *[MaxUsersInGroup]uuid.UUID) (int, error) {
|
||||
batch := &pgx.Batch{}
|
||||
var count int
|
||||
for _, uid := range userIds {
|
||||
if uid == 0 {
|
||||
if uid == (uuid.UUID{}) {
|
||||
continue
|
||||
}
|
||||
batch.Queue(`
|
||||
|
||||
Reference in New Issue
Block a user