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 @@ -5,6 +5,7 @@ import bots from 'lib/facts/bots.js'; import genesis from 'lib/facts/genesis.js'; import { policyTypes } from 'lib/facts/policies.js'; +import { specialRoles } from 'lib/permissions/special-roles.js'; import { messageTypes } from 'lib/types/message-types-enum.js'; import { threadPermissions } from 'lib/types/thread-permission-types.js'; import { threadTypes } from 'lib/types/thread-types-enum.js'; @@ -664,6 +665,23 @@ }, ], [52, updateRolesAndPermissionsForAllThreads], + [ + 53, + async () => { + await dbQuery( + SQL` + ALTER TABLE roles + ADD COLUMN IF NOT EXISTS special_role + tinyint(2) UNSIGNED DEFAULT NULL; + + UPDATE roles r + JOIN threads t ON r.id = t.default_role + SET r.special_role = ${specialRoles.DEFAULT_ROLE}; + `, + { 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 @@ -135,7 +135,8 @@ thread bigint(20) NOT NULL, name varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, permissions json NOT NULL, - creation_time bigint(20) NOT NULL + creation_time bigint(20) NOT NULL, + special_role tinyint(2) UNSIGNED DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE sessions ( diff --git a/lib/permissions/special-roles.js b/lib/permissions/special-roles.js new file mode 100644 --- /dev/null +++ b/lib/permissions/special-roles.js @@ -0,0 +1,5 @@ +// @flow + +export const specialRoles = Object.freeze({ + DEFAULT_ROLE: 1, +});