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 65518552
authored
Jan 10, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1229 from sequelize/hotfix/undo_migrations
Tests/Fixes for undoing migrations.
2 parents
f5d6065f
aff5f1c6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
13 deletions
bin/sequelize
lib/migrator.js
test/sequelize.executable.test.js
bin/sequelize
View file @
6551855
...
@@ -185,11 +185,12 @@ if (program.migrate) {
...
@@ -185,11 +185,12 @@ if (program.migrate) {
if
(
key
===
"use_env_variable"
)
{
if
(
key
===
"use_env_variable"
)
{
if
(
process
.
env
[
value
])
{
if
(
process
.
env
[
value
])
{
var
db_info
=
process
.
env
[
value
].
match
(
var
db_info
=
process
.
env
[
value
].
match
(
/
([^
:
]
+
)
:
\/\/([^
:
]
+
)
:
([^
@
]
+
)
@
([^
:
]
+
)
:
(\d
+
)\/(
.+
)
/
);
/
([^
:
]
+
)
:
\/\/([^
:
]
+
)
:
([^
@
]
+
)
@
([^
:
]
+
)
:
(\d
+
)\/(
.+
)
/
);
config
.
database
=
db_info
[
6
];
config
.
database
=
db_info
[
6
];
config
.
username
=
db_info
[
2
];
config
.
username
=
db_info
[
2
];
config
.
password
=
db_info
[
3
];
config
.
password
=
db_info
[
3
];
options
=
_
.
extend
(
options
,
{
options
=
_
.
extend
(
options
,
{
host
:
db_info
[
4
],
host
:
db_info
[
4
],
port
:
db_info
[
5
],
port
:
db_info
[
5
],
...
@@ -207,15 +208,17 @@ if (program.migrate) {
...
@@ -207,15 +208,17 @@ if (program.migrate) {
,
migrator
=
sequelize
.
getMigrator
(
migratorOptions
)
,
migrator
=
sequelize
.
getMigrator
(
migratorOptions
)
if
(
program
.
undo
)
{
if
(
program
.
undo
)
{
sequelize
.
migrator
.
findOrCreateSequelizeMetaDAO
().
success
(
function
(
Meta
)
{
migrator
.
findOrCreateSequelizeMetaDAO
().
success
(
function
(
Meta
)
{
Meta
.
find
({
order
:
'id DESC'
}).
success
(
function
(
meta
)
{
Meta
.
find
({
order
:
'id DESC'
}).
success
(
function
(
meta
)
{
if
(
meta
)
{
if
(
meta
)
{
migrator
=
sequelize
.
getMigrator
(
_
.
extend
(
migratorOptions
,
meta
),
true
)
migrator
=
sequelize
.
getMigrator
(
_
.
extend
(
migratorOptions
,
meta
.
values
),
true
)
}
migrator
.
migrate
({
method
:
'down'
}).
success
(
function
()
{
process
.
exit
(
0
)
migrator
.
migrate
({
method
:
'down'
}).
success
(
function
()
{
})
}
else
{
console
.
log
(
"There are no pending migrations."
)
process
.
exit
(
0
)
process
.
exit
(
0
)
}
)
}
})
})
})
})
}
else
{
}
else
{
...
...
lib/migrator.js
View file @
6551855
...
@@ -9,10 +9,10 @@ module.exports = (function() {
...
@@ -9,10 +9,10 @@ module.exports = (function() {
var
Migrator
=
function
(
sequelize
,
options
)
{
var
Migrator
=
function
(
sequelize
,
options
)
{
this
.
sequelize
=
sequelize
this
.
sequelize
=
sequelize
this
.
options
=
Utils
.
_
.
extend
({
this
.
options
=
Utils
.
_
.
extend
({
path
:
__dirname
+
'/../migrations'
,
path
:
__dirname
+
'/../migrations'
,
from
:
null
,
from
:
null
,
to
:
null
,
to
:
null
,
logging
:
console
.
log
,
logging
:
console
.
log
,
filesFilter
:
/
\.
js$/
filesFilter
:
/
\.
js$/
},
options
||
{})
},
options
||
{})
...
@@ -49,7 +49,6 @@ module.exports = (function() {
...
@@ -49,7 +49,6 @@ module.exports = (function() {
,
from
=
migrations
[
0
]
,
from
=
migrations
[
0
]
if
(
options
.
method
===
'down'
)
{
if
(
options
.
method
===
'down'
)
{
from
=
migrations
[
0
]
migrations
.
reverse
()
migrations
.
reverse
()
}
}
...
...
test/sequelize.executable.test.js
View file @
6551855
...
@@ -209,6 +209,106 @@ describe(Support.getTestDialectTeaser("Executable"), function() {
...
@@ -209,6 +209,106 @@ describe(Support.getTestDialectTeaser("Executable"), function() {
;(
function
(
flags
)
{
;(
function
(
flags
)
{
flags
.
forEach
(
function
(
flag
)
{
flags
.
forEach
(
function
(
flag
)
{
var
execBinary
=
function
(
callback
,
_flag
)
{
_flag
=
_flag
||
flag
var
dialect
=
Support
.
getTestDialect
()
,
config
=
require
(
__dirname
+
'/config/config.js'
)
config
.
sqlite
.
storage
=
__dirname
+
"/tmp/test.sqlite"
config
=
_
.
extend
(
config
,
config
[
dialect
],
{
dialect
:
dialect
})
exec
(
"echo '"
+
JSON
.
stringify
(
config
)
+
"' > config/config.json"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"../../bin/sequelize "
+
_flag
,
{
cwd
:
__dirname
+
"/tmp"
},
callback
)
})
}
var
prepare
=
function
(
callback
,
options
)
{
options
=
options
||
{}
exec
(
"rm -rf ./*"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"../../bin/sequelize --init"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"cp ../assets/migrations/*-createPerson.js ./migrations/"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"cat ../support.js|sed s,/../,/../../, > ./support.js"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
if
(
!
options
.
skipExecBinary
)
{
execBinary
(
callback
,
options
.
flag
)
}
})
})
})
})
}
describe
(
flag
,
function
()
{
it
(
"creates a SequelizeMeta table"
,
function
(
done
)
{
var
sequelize
=
this
.
sequelize
if
(
this
.
sequelize
.
options
.
dialect
===
'sqlite'
)
{
var
options
=
this
.
sequelize
.
options
options
.
storage
=
__dirname
+
"/tmp/test.sqlite"
sequelize
=
new
Support
.
Sequelize
(
""
,
""
,
""
,
options
)
}
prepare
(
function
()
{
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tables
)
{
tables
=
tables
.
sort
()
expect
(
tables
).
to
.
have
.
length
(
1
)
expect
(
tables
[
0
]).
to
.
equal
(
"SequelizeMeta"
)
done
()
})
}.
bind
(
this
))
})
it
(
"stops execution if no migrations have been done yet"
,
function
(
done
)
{
var
sequelize
=
this
.
sequelize
if
(
this
.
sequelize
.
options
.
dialect
===
'sqlite'
)
{
var
options
=
this
.
sequelize
.
options
options
.
storage
=
__dirname
+
"/tmp/test.sqlite"
sequelize
=
new
Support
.
Sequelize
(
""
,
""
,
""
,
options
)
}
prepare
(
function
(
err
,
output
)
{
expect
(
err
).
to
.
be
.
null
expect
(
output
).
to
.
include
(
"There are no pending migrations."
)
done
()
}.
bind
(
this
))
})
it
(
"is correctly undoing a migration if they have been done yet"
,
function
(
done
)
{
var
sequelize
=
this
.
sequelize
if
(
this
.
sequelize
.
options
.
dialect
===
'sqlite'
)
{
var
options
=
this
.
sequelize
.
options
options
.
storage
=
__dirname
+
"/tmp/test.sqlite"
sequelize
=
new
Support
.
Sequelize
(
""
,
""
,
""
,
options
)
}
prepare
(
function
()
{
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tables
)
{
tables
=
tables
.
sort
()
expect
(
tables
).
to
.
have
.
length
(
2
)
expect
(
tables
[
0
]).
to
.
equal
(
"Person"
)
execBinary
(
function
(
err
,
output
)
{
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tables
)
{
expect
(
tables
).
to
.
have
.
length
(
1
)
expect
(
tables
[
0
]).
to
.
equal
(
"SequelizeMeta"
)
done
()
})
})
})
}.
bind
(
this
),
{
flag
:
'-m'
})
})
})
})
})([
'--migrate --undo'
,
'-mu'
])
;(
function
(
flags
)
{
flags
.
forEach
(
function
(
flag
)
{
var
prepare
=
function
(
callback
)
{
var
prepare
=
function
(
callback
)
{
exec
(
"rm -rf ./*"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"rm -rf ./*"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"../../bin/sequelize --init"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
exec
(
"../../bin/sequelize --init"
,
{
cwd
:
__dirname
+
'/tmp'
},
function
(
error
,
stdout
)
{
...
...
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