aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrator.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-12 17:53:50 +0100
committerChocobozzz <me@florianbigard.com>2017-12-13 16:50:33 +0100
commit3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch)
treee5ca358287fca6ecacce83defcf23af1e8e9f419 /server/initializers/migrator.ts
parentc893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff)
downloadPeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst
PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip
Move models to typescript-sequelize
Diffstat (limited to 'server/initializers/migrator.ts')
-rw-r--r--server/initializers/migrator.ts21
1 files changed, 10 insertions, 11 deletions
diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts
index 187c9be6e..f3a05cc8c 100644
--- a/server/initializers/migrator.ts
+++ b/server/initializers/migrator.ts
@@ -1,19 +1,19 @@
1import * as path from 'path' 1import * as path from 'path'
2
3import { database as db } from './database'
4import { LAST_MIGRATION_VERSION } from './constants'
5import { logger, readdirPromise } from '../helpers' 2import { logger, readdirPromise } from '../helpers'
3import { ApplicationModel } from '../models/application/application'
4import { LAST_MIGRATION_VERSION } from './constants'
5import { sequelizeTypescript } from './database'
6 6
7async function migrate () { 7async function migrate () {
8 const tables = await db.sequelize.getQueryInterface().showAllTables() 8 const tables = await sequelizeTypescript.getQueryInterface().showAllTables()
9 9
10 // No tables, we don't need to migrate anything 10 // No tables, we don't need to migrate anything
11 // The installer will do that 11 // The installer will do that
12 if (tables.length === 0) return 12 if (tables.length === 0) return
13 13
14 let actualVersion = await db.Application.loadMigrationVersion() 14 let actualVersion = await ApplicationModel.loadMigrationVersion()
15 if (actualVersion === null) { 15 if (actualVersion === null) {
16 await db.Application.create({ migrationVersion: 0 }) 16 await ApplicationModel.create({ migrationVersion: 0 })
17 actualVersion = 0 17 actualVersion = 0
18 } 18 }
19 19
@@ -78,17 +78,16 @@ async function executeMigration (actualVersion: number, entity: { version: strin
78 78
79 const migrationScript = require(path.join(__dirname, 'migrations', migrationScriptName)) 79 const migrationScript = require(path.join(__dirname, 'migrations', migrationScriptName))
80 80
81 await db.sequelize.transaction(async t => { 81 await sequelizeTypescript.transaction(async t => {
82 const options = { 82 const options = {
83 transaction: t, 83 transaction: t,
84 queryInterface: db.sequelize.getQueryInterface(), 84 queryInterface: sequelizeTypescript.getQueryInterface(),
85 sequelize: db.sequelize, 85 sequelize: sequelizeTypescript
86 db
87 } 86 }
88 87
89 await migrationScript.up(options) 88 await migrationScript.up(options)
90 89
91 // Update the new migration version 90 // Update the new migration version
92 await db.Application.updateMigrationVersion(versionScript, t) 91 await ApplicationModel.updateMigrationVersion(versionScript, t)
93 }) 92 })
94} 93}