Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 6084b1d9
authored
Nov 22, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
find the correct files
1 parent
1c6841b7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
75 deletions
lib/migrator.js
lib/migrator.js
View file @
6084b1d
var
fs
=
require
(
"fs"
)
const
fs
=
require
(
"fs"
)
,
path
=
require
(
"path"
)
,
moment
=
require
(
"moment"
)
,
Utils
=
require
(
"./utils"
)
var
Utils
=
require
(
"./utils"
)
,
DataTypes
=
require
(
"./data-types"
)
,
QueryInterface
=
require
(
"./query-interface"
)
module
.
exports
=
(
function
()
{
var
Migrator
=
function
(
sequelize
,
options
)
{
this
.
sequelize
=
sequelize
this
.
queryInterface
=
new
QueryInterface
(
this
.
sequelize
)
this
.
options
=
Utils
.
_
.
extend
({
path
:
__dirname
+
'/../migrations'
,
from
:
null
,
...
...
@@ -18,69 +21,17 @@ module.exports = (function() {
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
execMigrations
=
function
(
from
)
{
var
nonMigratedFiles
=
getMigrationsFilesSince
.
call
(
self
,
from
)
nonMigratedFiles
.
forEach
(
function
(
file
)
{
executeMigration
.
call
(
self
,
self
.
options
.
path
+
'/'
+
file
)
getUndoneMigrations
.
call
(
self
,
function
(
migrations
)
{
console
.
log
(
migrations
)
})
emitter
.
emit
(
'success'
)
}
if
(
self
.
options
.
from
)
{
execMigrations
(
self
.
options
.
from
)
}
else
{
getLastMigrationId
.
call
(
self
).
success
(
function
(
migrationId
)
{
migrationId
=
migrationId
||
'19700101000000'
execMigrations
.
call
(
self
,
migrationId
)
})
}
}).
run
()
}
Migrator
.
prototype
.
createTable
=
function
()
{
}
Migrator
.
prototype
.
dropTable
=
function
()
{
}
Migrator
.
prototype
.
renameTable
=
function
()
{
}
Migrator
.
prototype
.
addColumn
=
function
()
{
}
Migrator
.
prototype
.
removeColumn
=
function
()
{
}
Migrator
.
prototype
.
changeColumn
=
function
()
{
}
Migrator
.
prototype
.
renameColumn
=
function
()
{
}
Migrator
.
prototype
.
addIndex
=
function
()
{
}
Migrator
.
prototype
.
removeIndex
=
function
()
{
}
// private
var
executeMigration
=
function
(
path
,
method
)
{
var
migration
=
require
(
path
)
migration
[
method
||
'up'
](
this
)
migration
[
method
||
'up'
](
this
.
queryInterface
,
DataTypes
)
}
var
getLastMigrationId
=
function
()
{
...
...
@@ -92,7 +43,7 @@ module.exports = (function() {
var
findLastMigrationId
=
function
()
{
SequelizeMeta
.
find
({
order
:
'id DESC'
}).
success
(
function
(
sequelizeMeta
)
{
emitter
.
emit
(
'success'
,
sequelizeMeta
?
sequelizeMeta
.
lastMigrationId
:
null
)
})
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}
if
(
SequelizeMeta
)
{
...
...
@@ -102,11 +53,10 @@ module.exports = (function() {
lastMigrationId
:
DataTypes
.
STRING
})
SequelizeMeta
.
sync
().
success
(
function
()
{
findLastMigrationId
()
}).
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
SequelizeMeta
.
sync
()
.
success
(
function
()
{
findLastMigrationId
()
})
.
error
(
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}
}).
run
()
}
...
...
@@ -124,24 +74,31 @@ module.exports = (function() {
}
var
stringToDate
=
function
(
s
)
{
var
formattedString
=
getFormattedDateString
(
s
)
,
date
=
moment
(
formattedString
,
"YYYYMMDDHHmmss"
)
return
date
return
moment
(
getFormattedDateString
(
s
),
"YYYYMMDDHHmmss"
)
}
var
get
MigrationsFilesSince
=
function
(
sinceString
)
{
var
result
=
[]
,
since
=
stringToDate
(
sinceString
)
var
get
UndoneMigrations
=
function
(
callback
)
{
var
migrationFiles
=
fs
.
readdirSync
(
this
.
options
.
path
)
,
undoneMigrations
=
migrationFiles
var
undoneMigrationFiles
=
fs
.
readdirSync
(
this
.
options
.
path
).
filter
(
function
(
file
)
{
var
fileDateString
=
file
.
split
(
"-"
)[
0
]
,
fileDate
=
stringToDate
(
fileDateString
)
if
(
this
.
options
.
from
)
{
var
sinceDate
=
stringToDate
(
this
.
options
.
from
.
toString
())
return
fileDate
.
diff
(
since
)
>
0
undoneMigrations
=
migrationFiles
.
filter
(
function
(
file
)
{
var
fileDate
=
stringToDate
(
file
.
split
(
"-"
)[
0
])
return
fileDate
.
diff
(
sinceDate
)
>=
0
})
}
if
(
this
.
options
.
to
)
{
var
toDate
=
stringToDate
(
this
.
options
.
to
.
toString
())
undoneMigrations
=
undoneMigrations
.
filter
(
function
(
file
)
{
var
fileDate
=
stringToDate
(
file
.
split
(
"-"
)[
0
])
return
toDate
.
diff
(
fileDate
)
>=
0
})
}
return
undoneMigrationFiles
callback
&&
callback
(
undoneMigrations
)
}
return
Migrator
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment