diff options
Diffstat (limited to 'server/initializers/migrator.ts')
-rw-r--r-- | server/initializers/migrator.ts | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts index f3a05cc8c..bb2539fc8 100644 --- a/server/initializers/migrator.ts +++ b/server/initializers/migrator.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import * as path from 'path' | 1 | import * as path from 'path' |
2 | import { logger, readdirPromise } from '../helpers' | 2 | import { logger, readdirPromise } from '../helpers' |
3 | import { ApplicationModel } from '../models/application/application' | ||
4 | import { LAST_MIGRATION_VERSION } from './constants' | 3 | import { LAST_MIGRATION_VERSION } from './constants' |
5 | import { sequelizeTypescript } from './database' | 4 | import { sequelizeTypescript } from './database' |
6 | 5 | ||
@@ -11,9 +10,23 @@ async function migrate () { | |||
11 | // The installer will do that | 10 | // The installer will do that |
12 | if (tables.length === 0) return | 11 | if (tables.length === 0) return |
13 | 12 | ||
14 | let actualVersion = await ApplicationModel.loadMigrationVersion() | 13 | let actualVersion: number = null |
14 | |||
15 | // Search in "Applications" or "application" tables | ||
16 | try { | ||
17 | const [ rows ] = await sequelizeTypescript.query('SELECT "migrationVersion" FROM "Applications"') | ||
18 | if (rows && rows[ 0 ] && rows[ 0 ].migrationVersion) { | ||
19 | actualVersion = rows[ 0 ].migrationVersion | ||
20 | } | ||
21 | } catch { | ||
22 | const [ rows ] = await sequelizeTypescript.query('SELECT "migrationVersion" FROM "application"') | ||
23 | if (rows && rows[0] && rows[0].migrationVersion) { | ||
24 | actualVersion = rows[0].migrationVersion | ||
25 | } | ||
26 | } | ||
27 | |||
15 | if (actualVersion === null) { | 28 | if (actualVersion === null) { |
16 | await ApplicationModel.create({ migrationVersion: 0 }) | 29 | await sequelizeTypescript.query('INSERT INTO "application" ("migrationVersion") VALUES (0)') |
17 | actualVersion = 0 | 30 | actualVersion = 0 |
18 | } | 31 | } |
19 | 32 | ||
@@ -88,6 +101,6 @@ async function executeMigration (actualVersion: number, entity: { version: strin | |||
88 | await migrationScript.up(options) | 101 | await migrationScript.up(options) |
89 | 102 | ||
90 | // Update the new migration version | 103 | // Update the new migration version |
91 | await ApplicationModel.updateMigrationVersion(versionScript, t) | 104 | await sequelizeTypescript.query('UPDATE "application" SET "migrationVersion" = ' + versionScript, { transaction: t }) |
92 | }) | 105 | }) |
93 | } | 106 | } |