增加群组创建、邀请与成员权限管理
This commit is contained in:
1 parent
b1f55df263
commit
99a741e6da
13 files changed
+620
-5
No files matched your search
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE chat_groups (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name text NOT NULL CHECK (char_length(name) BETWEEN 1 AND 64),
|
||||
owner_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
membership_version bigint NOT NULL DEFAULT 1,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE group_members (
|
||||
group_id uuid NOT NULL REFERENCES chat_groups(id) ON DELETE CASCADE,
|
||||
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
state text NOT NULL CHECK (state IN ('invited', 'active')),
|
||||
role text NOT NULL DEFAULT 'member' CHECK (role IN ('member', 'admin')),
|
||||
PRIMARY KEY (group_id, user_id),
|
||||
CHECK (state = 'active' OR role = 'member')
|
||||
);
|
||||
|
||||
CREATE INDEX group_members_user ON group_members(user_id, group_id);
|
||||
@@ -25,6 +25,9 @@ var mlsCredentialsMigration string
|
||||
//go:embed 006_attachments.sql
|
||||
var attachmentsMigration string
|
||||
|
||||
//go:embed 007_groups.sql
|
||||
var groupsMigration string
|
||||
|
||||
func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
|
||||
tx, err := pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -37,7 +40,7 @@ func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
|
||||
if _, err = tx.Exec(ctx, "CREATE TABLE IF NOT EXISTS schema_migrations (version integer PRIMARY KEY)"); err != nil {
|
||||
return err
|
||||
}
|
||||
for index, migration := range []string{identityMigration, contactsMigration, deliveryMigration, keyPackagesMigration, mlsCredentialsMigration, attachmentsMigration} {
|
||||
for index, migration := range []string{identityMigration, contactsMigration, deliveryMigration, keyPackagesMigration, mlsCredentialsMigration, attachmentsMigration, groupsMigration} {
|
||||
version := index + 1
|
||||
var applied bool
|
||||
if err = tx.QueryRow(ctx, "SELECT EXISTS (SELECT 1 FROM schema_migrations WHERE version=$1)", version).Scan(&applied); err != nil {
|
||||
|
||||
Reference in new issue
Block a user