File tree 3 files changed +33
-0
lines changed
3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ export function ensureCurrentMetaSchema(migrator) {
77
77
if ( columns . length === 1 && columns [ 0 ] === columnName ) {
78
78
return ;
79
79
} else if ( columns . length === 3 && columns . indexOf ( 'createdAt' ) >= 0 ) {
80
+ // If found createdAt - indicate we have timestamps enabled
81
+ helpers . umzug . enableTimestamps ( ) ;
80
82
return ;
81
83
}
82
84
} )
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ const storageJsonName = {
15
15
seeder : 'sequelize-data.json' ,
16
16
} ;
17
17
18
+ let timestampsDefault = false ;
19
+
18
20
module . exports = {
19
21
getStorageOption ( property , fallback ) {
20
22
return helpers . config . readConfig ( ) [ property ] || fallback ;
@@ -41,6 +43,14 @@ module.exports = {
41
43
return this . getStorageOption ( type + 'StorageTableSchema' , undefined ) ;
42
44
} ,
43
45
46
+ enableTimestamps ( ) {
47
+ timestampsDefault = true ;
48
+ } ,
49
+
50
+ getTimestamps ( type ) {
51
+ return this . getStorageOption ( type + 'Timestamps' , timestampsDefault ) ;
52
+ } ,
53
+
44
54
getStorageOptions ( type , extraOptions ) {
45
55
const options = { } ;
46
56
@@ -49,6 +59,7 @@ module.exports = {
49
59
} else if ( this . getStorage ( type ) === 'sequelize' ) {
50
60
options . tableName = this . getTableName ( type ) ;
51
61
options . schema = this . getSchema ( type ) ;
62
+ options . timestamps = this . getTimestamps ( type ) ;
52
63
}
53
64
54
65
_ . assign ( options , extraOptions ) ;
Original file line number Diff line number Diff line change @@ -118,5 +118,25 @@ const gulp = require('gulp');
118
118
} )
119
119
) ;
120
120
} ) ;
121
+
122
+ it ( 'run migration again with timestamp fields present' , function ( done ) {
123
+ gulp
124
+ . src ( Support . resolveSupportPath ( 'tmp' ) )
125
+ . pipe ( helpers . runCli ( 'db:migrate' ) )
126
+ . pipe (
127
+ helpers . teardown ( ( ) => {
128
+ helpers
129
+ . execQuery (
130
+ this . sequelize ,
131
+ this . queryGenerator . selectQuery ( 'SequelizeMeta' ) ,
132
+ { raw : true , type : 'SELECT' }
133
+ )
134
+ . then ( ( items ) => {
135
+ expect ( items . length ) . to . equal ( 2 ) ;
136
+ done ( ) ;
137
+ } ) ;
138
+ } )
139
+ ) ;
140
+ } ) ;
121
141
} ) ;
122
142
} ) ;
You can’t perform that action at this time.
0 commit comments