aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0770-actor-preferred-username.ts44
2 files changed, 45 insertions, 1 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index adf24b73f..1dfc9fb27 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -27,7 +27,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
27 27
28// --------------------------------------------------------------------------- 28// ---------------------------------------------------------------------------
29 29
30const LAST_MIGRATION_VERSION = 765 30const LAST_MIGRATION_VERSION = 770
31 31
32// --------------------------------------------------------------------------- 32// ---------------------------------------------------------------------------
33 33
diff --git a/server/initializers/migrations/0770-actor-preferred-username.ts b/server/initializers/migrations/0770-actor-preferred-username.ts
new file mode 100644
index 000000000..217813f7f
--- /dev/null
+++ b/server/initializers/migrations/0770-actor-preferred-username.ts
@@ -0,0 +1,44 @@
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
4 transaction: Sequelize.Transaction
5 queryInterface: Sequelize.QueryInterface
6 sequelize: Sequelize.Sequelize
7 db: any
8}): Promise<void> {
9 const { transaction } = utils
10
11 await utils.sequelize.query('drop index if exists "actor_preferred_username"', { transaction })
12 await utils.sequelize.query('drop index if exists "actor_preferred_username_server_id"', { transaction })
13
14 await utils.sequelize.query(
15 'DELETE FROM "actor" v1 USING (' +
16 'SELECT MIN(id) as id, lower("preferredUsername") AS "lowerPreferredUsername", "serverId" ' +
17 'FROM "actor" ' +
18 'GROUP BY "lowerPreferredUsername", "serverId" HAVING COUNT(*) > 1 AND "serverId" IS NOT NULL' +
19 ') v2 ' +
20 'WHERE lower(v1."preferredUsername") = v2."lowerPreferredUsername" AND v1."serverId" = v2."serverId" AND v1.id <> v2.id',
21 { transaction }
22 )
23
24 await utils.sequelize.query(
25 'DELETE FROM "actor" v1 USING (' +
26 'SELECT MIN(id) as id, lower("preferredUsername") AS "lowerPreferredUsername", "serverId" ' +
27 'FROM "actor" ' +
28 'GROUP BY "lowerPreferredUsername", "serverId" HAVING COUNT(*) > 1 AND "serverId" IS NULL' +
29 ') v2 ' +
30 'WHERE lower(v1."preferredUsername") = v2."lowerPreferredUsername" AND v1."serverId" IS NULL AND v1.id <> v2.id',
31 { transaction }
32 )
33}
34
35async function down (utils: {
36 queryInterface: Sequelize.QueryInterface
37 transaction: Sequelize.Transaction
38}) {
39}
40
41export {
42 up,
43 down
44}