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/database.ts4
-rw-r--r--server/initializers/migrations/0125-table-lowercase.ts36
-rw-r--r--server/initializers/migrator.ts21
4 files changed, 56 insertions, 7 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index f539eb2ee..341086bd6 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -8,7 +8,7 @@ import { isTestInstance, root } from '../helpers/core-utils'
8 8
9// --------------------------------------------------------------------------- 9// ---------------------------------------------------------------------------
10 10
11const LAST_MIGRATION_VERSION = 120 11const LAST_MIGRATION_VERSION = 125
12 12
13// --------------------------------------------------------------------------- 13// ---------------------------------------------------------------------------
14 14
diff --git a/server/initializers/database.ts b/server/initializers/database.ts
index f9e24c6b8..2260938b1 100644
--- a/server/initializers/database.ts
+++ b/server/initializers/database.ts
@@ -50,7 +50,7 @@ const sequelizeTypescript = new SequelizeTypescript({
50 } 50 }
51}) 51})
52 52
53async function initDatabase (silent: boolean) { 53async function initDatabaseModels (silent: boolean) {
54 sequelizeTypescript.addModels([ 54 sequelizeTypescript.addModels([
55 ApplicationModel, 55 ApplicationModel,
56 AvatarModel, 56 AvatarModel,
@@ -81,6 +81,6 @@ async function initDatabase (silent: boolean) {
81// --------------------------------------------------------------------------- 81// ---------------------------------------------------------------------------
82 82
83export { 83export {
84 initDatabase, 84 initDatabaseModels,
85 sequelizeTypescript 85 sequelizeTypescript
86} 86}
diff --git a/server/initializers/migrations/0125-table-lowercase.ts b/server/initializers/migrations/0125-table-lowercase.ts
new file mode 100644
index 000000000..78041ccb0
--- /dev/null
+++ b/server/initializers/migrations/0125-table-lowercase.ts
@@ -0,0 +1,36 @@
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
4 transaction: Sequelize.Transaction,
5 queryInterface: Sequelize.QueryInterface,
6 sequelize: Sequelize.Sequelize
7}): Promise<void> {
8 await utils.queryInterface.renameTable('Applications', 'application')
9 await utils.queryInterface.renameTable('AccountFollows', 'accountFollow')
10 await utils.queryInterface.renameTable('AccountVideoRates', 'accountVideoRate')
11 await utils.queryInterface.renameTable('Accounts', 'account')
12 await utils.queryInterface.renameTable('Avatars', 'avatar')
13 await utils.queryInterface.renameTable('BlacklistedVideos', 'videoBlacklist')
14 await utils.queryInterface.renameTable('Jobs', 'job')
15 await utils.queryInterface.renameTable('OAuthClients', 'oAuthClient')
16 await utils.queryInterface.renameTable('OAuthTokens', 'oAuthToken')
17 await utils.queryInterface.renameTable('Servers', 'server')
18 await utils.queryInterface.renameTable('Tags', 'tag')
19 await utils.queryInterface.renameTable('Users', 'user')
20 await utils.queryInterface.renameTable('VideoAbuses', 'videoAbuse')
21 await utils.queryInterface.renameTable('VideoChannels', 'videoChannel')
22 await utils.queryInterface.renameTable('VideoChannelShares', 'videoChannelShare')
23 await utils.queryInterface.renameTable('VideoFiles', 'videoFile')
24 await utils.queryInterface.renameTable('VideoShares', 'videoShare')
25 await utils.queryInterface.renameTable('VideoTags', 'videoTag')
26 await utils.queryInterface.renameTable('Videos', 'video')
27}
28
29function down (options) {
30 throw new Error('Not implemented.')
31}
32
33export {
34 up,
35 down
36}
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 @@
1import * as path from 'path' 1import * as path from 'path'
2import { logger, readdirPromise } from '../helpers' 2import { logger, readdirPromise } from '../helpers'
3import { ApplicationModel } from '../models/application/application'
4import { LAST_MIGRATION_VERSION } from './constants' 3import { LAST_MIGRATION_VERSION } from './constants'
5import { sequelizeTypescript } from './database' 4import { 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}