1
1
'use strict' ;
2
2
const fs = require ( 'fs' ) ;
3
3
const path = require ( 'path' ) ;
4
- const KnexMigrator = require ( 'knex-migrator' ) ;
5
4
6
5
const Config = require ( '../utils/config' ) ;
7
6
const Command = require ( '../command' ) ;
8
- const errors = require ( '../errors' ) ;
9
7
const startupChecks = require ( './doctor/checks/startup' ) ;
8
+ const runMigrations = require ( '../tasks/migrate' ) ;
10
9
11
10
class StartCommand extends Command {
12
11
run ( argv ) {
@@ -21,50 +20,19 @@ class StartCommand extends Command {
21
20
process . env . NODE_ENV = this . environment = 'development' ;
22
21
}
23
22
24
- return this . ui . listr ( startupChecks , { environment : this . environment } ) . then ( ( ) => {
25
- config = Config . load ( this . environment ) ;
26
- cliConfig = Config . load ( '.ghost-cli' ) ;
23
+ config = Config . load ( this . environment ) ;
24
+ cliConfig = Config . load ( '.ghost-cli' ) ;
27
25
28
- if ( cliConfig . has ( 'running' ) ) {
29
- return Promise . reject ( new Error ( 'Ghost is already running.' ) ) ;
30
- }
26
+ if ( cliConfig . has ( 'running' ) ) {
27
+ return Promise . reject ( new Error ( 'Ghost is already running.' ) ) ;
28
+ }
31
29
30
+ return this . ui . listr ( startupChecks . concat ( {
31
+ title : 'Running database migrations' ,
32
+ task : runMigrations
33
+ } ) , { environment : this . environment , config : config } ) . then ( ( ) => {
32
34
this . service . setConfig ( config ) ;
33
35
34
- process . env . paths__contentPath = path . join ( process . cwd ( ) , 'content' ) ;
35
-
36
- let knexMigrator = new KnexMigrator ( {
37
- knexMigratorFilePath : path . join ( process . cwd ( ) , 'current' )
38
- } ) ;
39
-
40
- return knexMigrator . isDatabaseOK ( ) . catch ( ( error ) => {
41
- if ( error . code === 'DB_NOT_INITIALISED' ||
42
- error . code === 'MIGRATION_TABLE_IS_MISSING' ) {
43
- return knexMigrator . init ( ) ;
44
- } else if ( error . code === 'DB_NEEDS_MIGRATION' ) {
45
- return knexMigrator . migrate ( ) ;
46
- }
47
-
48
- if ( error . code === 'ENOTFOUND' ) {
49
- // Database not found
50
- error = new errors . ConfigError ( {
51
- configKey : 'database.connection.host' ,
52
- configValue : config . get ( 'database.connection.host' ) ,
53
- message : 'Invalid database host' ,
54
- environment : this . environment
55
- } ) ;
56
- } else if ( error . code === 'ER_ACCESS_DENIED_ERROR' ) {
57
- error = new errors . ConfigError ( {
58
- configKey : 'database.connection.user' ,
59
- configValue : config . get ( 'database.connection.user' ) ,
60
- message : 'Invalid database username or password' ,
61
- environment : this . environment
62
- } ) ;
63
- }
64
-
65
- return Promise . reject ( error ) ;
66
- } ) ;
67
- } ) . then ( ( ) => {
68
36
let start = ( ) => Promise . resolve ( this . service . process . start ( process . cwd ( ) , this . environment ) ) . then ( ( ) => {
69
37
let systemConfig = Config . load ( 'system' ) ;
70
38
let instance = systemConfig . get ( `instances.${ config . get ( 'pname' ) } ` , { } ) ;
0 commit comments