aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations/0640-unique-keys.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers/migrations/0640-unique-keys.ts')
-rw-r--r--server/initializers/migrations/0640-unique-keys.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/server/initializers/migrations/0640-unique-keys.ts b/server/initializers/migrations/0640-unique-keys.ts
new file mode 100644
index 000000000..b082accc2
--- /dev/null
+++ b/server/initializers/migrations/0640-unique-keys.ts
@@ -0,0 +1,39 @@
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 {
10 await utils.sequelize.query(
11 'DELETE FROM "actor" v1 USING (SELECT MIN(id) as id, "preferredUsername", "serverId" FROM "actor" ' +
12 'GROUP BY "preferredUsername", "serverId" HAVING COUNT(*) > 1 AND "serverId" IS NOT NULL) v2 ' +
13 'WHERE v1."preferredUsername" = v2."preferredUsername" AND v1."serverId" = v2."serverId" AND v1.id <> v2.id'
14 )
15 }
16
17 {
18 await utils.sequelize.query(
19 'DELETE FROM "actor" v1 USING (SELECT MIN(id) as id, "url" FROM "actor" GROUP BY "url" HAVING COUNT(*) > 1) v2 ' +
20 'WHERE v1."url" = v2."url" AND v1.id <> v2.id'
21 )
22 }
23
24 {
25 await utils.sequelize.query(
26 'DELETE FROM "tag" v1 USING (SELECT MIN(id) as id, "name" FROM "tag" GROUP BY "name" HAVING COUNT(*) > 1) v2 ' +
27 'WHERE v1."name" = v2."name" AND v1.id <> v2.id'
28 )
29 }
30}
31
32function down (options) {
33 throw new Error('Not implemented.')
34}
35
36export {
37 up,
38 down
39}