diff options
Diffstat (limited to 'server/initializers/migrations/0575-duplicate-thumbnail.ts')
-rw-r--r-- | server/initializers/migrations/0575-duplicate-thumbnail.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/server/initializers/migrations/0575-duplicate-thumbnail.ts b/server/initializers/migrations/0575-duplicate-thumbnail.ts new file mode 100644 index 000000000..4dbbe71d4 --- /dev/null +++ b/server/initializers/migrations/0575-duplicate-thumbnail.ts | |||
@@ -0,0 +1,24 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction | ||
5 | queryInterface: Sequelize.QueryInterface | ||
6 | sequelize: Sequelize.Sequelize | ||
7 | db: any | ||
8 | }): Promise<void> { | ||
9 | { | ||
10 | const query = 'DELETE FROM "thumbnail" s1 ' + | ||
11 | 'USING (SELECT MIN(id) as id, "filename", "type" FROM "thumbnail" GROUP BY "filename", "type" HAVING COUNT(*) > 1) s2 ' + | ||
12 | 'WHERE s1."filename" = s2."filename" AND s1."type" = s2."type" AND s1.id <> s2.id' | ||
13 | await utils.sequelize.query(query) | ||
14 | } | ||
15 | } | ||
16 | |||
17 | function down (options) { | ||
18 | throw new Error('Not implemented.') | ||
19 | } | ||
20 | |||
21 | export { | ||
22 | up, | ||
23 | down | ||
24 | } | ||