diff --git a/keyserver/src/database/migration-config.js b/keyserver/src/database/migration-config.js --- a/keyserver/src/database/migration-config.js +++ b/keyserver/src/database/migration-config.js @@ -800,6 +800,29 @@ ); }, ], + [ + 64, + async () => { + await dbQuery( + SQL` + CREATE TABLE IF NOT EXISTS communities ( + id bigint(20) NOT NULL, + farcaster_channel_id varchar(255) CHARSET latin1 DEFAULT NULL, + blob_holder char(36) CHARSET latin1 DEFAULT NULL + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + + ALTER TABLE communities + ADD PRIMARY KEY (id); + + INSERT INTO communities (id) + SELECT id + FROM threads t + WHERE t.depth = 0; + `, + { multipleStatements: true }, + ); + }, + ], ]); const newDatabaseVersion: number = Math.max(...migrations.keys()); diff --git a/keyserver/src/database/setup-db.js b/keyserver/src/database/setup-db.js --- a/keyserver/src/database/setup-db.js +++ b/keyserver/src/database/setup-db.js @@ -298,6 +298,12 @@ COLLATE latin1_bin NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin; + CREATE TABLE communities ( + id bigint(20) NOT NULL, + farcaster_channel_id varchar(255) CHARSET latin1 DEFAULT NULL, + blob_holder char(36) CHARSET latin1 DEFAULT NULL + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + ALTER TABLE cookies ADD PRIMARY KEY (id), ADD UNIQUE KEY device_token (device_token(512)), @@ -426,6 +432,9 @@ ALTER TABLE olm_accounts ADD PRIMARY KEY (is_content); + + ALTER TABLE communities + ADD PRIMARY KEY (id); `, { multipleStatements: true }, );