aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-11 16:16:27 +0200
committerChocobozzz <me@florianbigard.com>2023-05-11 16:16:27 +0200
commit85c20aaeb90ef0e0f44c377e62c323fde275cdde (patch)
tree79d09e1b6f1746398c2ea4f0279ac54fa2be96dd /server/initializers/migrations
parent823c34c07fc0df81110098ee1032e9d3ed70b662 (diff)
downloadPeerTube-85c20aaeb90ef0e0f44c377e62c323fde275cdde.tar.gz
PeerTube-85c20aaeb90ef0e0f44c377e62c323fde275cdde.tar.zst
PeerTube-85c20aaeb90ef0e0f44c377e62c323fde275cdde.zip
Set actor preferred name case insensitive
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r--server/initializers/migrations/0770-actor-preferred-username.ts44
1 files changed, 44 insertions, 0 deletions
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}