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 db577ddb
authored
Jul 25, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converted migrator tests
1 parent
2daa6050
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
100 deletions
spec/migrator.spec.js → test/migrator.test.js
spec/migrator.spec
.js
→
test/migrator.test
.js
View file @
db577dd
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/support'
)
,
DataTypes
=
require
(
__dirname
+
"/../lib/data-types"
)
,
QueryChainer
=
require
(
"../lib/query-chainer"
)
,
CustomEventEmitter
=
require
(
"../lib/emitters/custom-event-emitter"
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
()
,
Migrator
=
require
(
"../lib/migrator"
)
}
,
dialect
=
Support
.
getTestDialect
()
buster
.
spec
.
expose
()
buster
.
testRunner
.
timeout
=
10000
chai
.
Assertion
.
includeStack
=
true
describe
(
Helpers
.
getTestDialectTeaser
(
"Migrator"
),
function
()
{
before
(
function
(
done
)
{
describe
(
Support
.
getTestDialectTeaser
(
"Migrator"
),
function
()
{
before
Each
(
function
(
)
{
this
.
init
=
function
(
options
,
callback
)
{
options
=
Helpers
.
Sequelize
.
Utils
.
_
.
extend
({
options
=
Support
.
Sequelize
.
Utils
.
_
.
extend
({
path
:
__dirname
+
'/assets/migrations'
,
logging
:
function
(){}
},
options
||
{})
...
...
@@ -27,121 +25,119 @@ describe(Helpers.getTestDialectTeaser("Migrator"), function() {
})
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
}.
bind
(
this
)
Helpers
.
initTests
({
dialect
:
dialect
,
onComplete
:
done
,
context
:
this
})
})
it
(
"as"
,
function
()
{
expect
(
1
).
toEqual
(
1
)
})
describe
(
'getUndoneMigrations'
,
function
()
{
it
(
"returns no files if timestamps are after the files timestamp"
,
function
(
done
)
{
this
.
init
({
from
:
20120101010101
},
function
(
migrator
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
BeNull
()
expect
(
migrations
.
length
).
to
E
qual
(
0
)
expect
(
err
).
to
.
be
.
null
expect
(
migrations
.
length
).
to
.
e
qual
(
0
)
done
()
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
it
(
"returns only files between from and to"
,
function
(
done
)
{
this
.
init
({
from
:
19700101000000
,
to
:
20111117063700
},
function
(
migrator
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
BeNull
()
expect
(
migrations
.
length
).
to
E
qual
(
1
)
expect
(
migrations
[
migrations
.
length
-
1
].
filename
).
to
E
qual
(
'20111117063700-createPerson.js'
)
expect
(
err
).
to
.
be
.
null
expect
(
migrations
.
length
).
to
.
e
qual
(
1
)
expect
(
migrations
[
migrations
.
length
-
1
].
filename
).
to
.
e
qual
(
'20111117063700-createPerson.js'
)
done
()
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
it
(
"returns exactly the migration which is defined in from and to"
,
function
(
done
)
{
this
.
init
({
from
:
20111117063700
,
to
:
20111117063700
},
function
(
migrator
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
BeNull
()
expect
(
migrations
.
length
).
to
E
qual
(
1
)
expect
(
migrations
[
migrations
.
length
-
1
].
filename
).
to
E
qual
(
'20111117063700-createPerson.js'
)
expect
(
err
).
to
.
be
.
null
expect
(
migrations
.
length
).
to
.
e
qual
(
1
)
expect
(
migrations
[
migrations
.
length
-
1
].
filename
).
to
.
e
qual
(
'20111117063700-createPerson.js'
)
done
()
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
it
(
"returns also the file which is exactly options.from or options.to"
,
function
(
done
)
{
this
.
init
({
from
:
20111117063700
,
to
:
20111130161100
},
function
(
migrator
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
BeNull
()
expect
(
migrations
.
length
).
to
E
qual
(
2
)
expect
(
migrations
[
0
].
filename
).
to
E
qual
(
'20111117063700-createPerson.js'
)
expect
(
migrations
[
1
].
filename
).
to
E
qual
(
'20111130161100-emptyMigration.js'
)
expect
(
err
).
to
.
be
.
null
expect
(
migrations
.
length
).
to
.
e
qual
(
2
)
expect
(
migrations
[
0
].
filename
).
to
.
e
qual
(
'20111117063700-createPerson.js'
)
expect
(
migrations
[
1
].
filename
).
to
.
e
qual
(
'20111130161100-emptyMigration.js'
)
done
()
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
it
(
"returns all files to options.to if no options.from is defined"
,
function
(
done
)
{
this
.
init
({
to
:
20111130161100
},
function
(
migrator
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
BeNull
()
expect
(
migrations
.
length
).
to
E
qual
(
2
)
expect
(
err
).
to
.
be
.
null
expect
(
migrations
.
length
).
to
.
e
qual
(
2
)
done
()
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
it
(
"returns all files from last migration id stored in database"
,
function
(
done
)
{
this
.
init
(
undefined
,
function
(
migrator
,
SequelizeMeta
)
{
SequelizeMeta
.
create
({
from
:
null
,
to
:
20111117063700
}).
success
(
function
()
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
BeNull
()
expect
(
migrations
.
length
).
to
E
qual
(
6
)
expect
(
migrations
[
0
].
filename
).
to
E
qual
(
'20111130161100-emptyMigration.js'
)
expect
(
err
).
to
.
be
.
null
expect
(
migrations
.
length
).
to
.
e
qual
(
6
)
expect
(
migrations
[
0
].
filename
).
to
.
e
qual
(
'20111130161100-emptyMigration.js'
)
done
()
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
})
})
describe
(
'migrations'
,
function
()
{
before
(
function
(
done
)
{
beforeEach
(
function
(
done
)
{
var
self
=
this
this
.
init
({
from
:
20111117063700
,
to
:
20111117063700
},
function
(
migrator
)
{
this
.
migrator
=
migrator
this
.
migrator
.
migrate
().
success
(
done
)
}
.
bind
(
this
)
)
self
.
migrator
=
migrator
self
.
migrator
.
migrate
().
success
(
done
)
})
})
describe
(
'executions'
,
function
()
{
it
(
"executes migration #20111117063700 and correctly creates the table"
,
function
(
done
)
{
this
.
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
tableNames
=
tableNames
.
filter
(
function
(
e
){
return
e
!=
'SequelizeMeta'
})
expect
(
tableNames
).
to
Equa
l
([
'Person'
])
expect
(
tableNames
).
to
.
eq
l
([
'Person'
])
done
()
})
})
it
(
"executes migration #20111117063700 and correctly adds isBetaMember"
,
function
(
done
)
{
this
.
sequelize
.
getQueryInterface
().
describeTable
(
'Person'
).
success
(
function
(
data
)
{
var
fields
=
Helpers
.
Sequelize
.
Utils
.
_
.
keys
(
data
).
sort
()
expect
(
fields
).
to
Equa
l
([
'isBetaMember'
,
'name'
])
var
fields
=
Object
.
keys
(
data
).
sort
()
expect
(
fields
).
to
.
eq
l
([
'isBetaMember'
,
'name'
])
done
()
})
})
it
(
"executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)"
,
function
(
done
)
{
var
self
=
this
this
.
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
tableNames
=
tableNames
.
filter
(
function
(
e
){
return
e
!=
'SequelizeMeta'
})
expect
(
tableNames
).
to
Equa
l
([
'Person'
])
expect
(
tableNames
).
to
.
eq
l
([
'Person'
])
this
.
migrator
.
migrate
({
method
:
'down'
}).
success
(
function
()
{
this
.
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
self
.
migrator
.
migrate
({
method
:
'down'
}).
success
(
function
()
{
self
.
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
tableNames
=
tableNames
.
filter
(
function
(
e
){
return
e
!=
'SequelizeMeta'
})
expect
(
tableNames
).
to
Equa
l
([])
expect
(
tableNames
).
to
.
eq
l
([])
done
()
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
})
it
(
"executes the empty migration #20111130161100"
,
function
(
done
)
{
...
...
@@ -149,7 +145,7 @@ describe(Helpers.getTestDialectTeaser("Migrator"), function() {
// this migration isn't actually testing anything but
// should not timeout
expect
(
1
).
toE
qual
(
1
)
// expect(1).to.e
qual(1)
migrator
.
migrate
()
...
...
@@ -160,112 +156,124 @@ describe(Helpers.getTestDialectTeaser("Migrator"), function() {
})
describe
(
'renameTable'
,
function
()
{
before
(
function
(
done
)
{
beforeEach
(
function
(
done
)
{
var
self
=
this
this
.
init
({
from
:
20111117063700
,
to
:
20111117063700
},
function
(
migrator
)
{
this
.
migrator
=
migrator
this
.
migrator
.
migrate
().
success
(
done
)
}
.
bind
(
this
)
)
self
.
migrator
=
migrator
self
.
migrator
.
migrate
().
success
(
done
)
})
})
it
(
"executes migration #20111205064000 and renames a table"
,
function
(
done
)
{
var
self
=
this
this
.
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
tableNames
=
tableNames
.
filter
(
function
(
e
){
return
e
!=
'SequelizeMeta'
})
expect
(
tableNames
).
to
Contain
(
'Person'
)
tableNames
=
tableNames
.
filter
(
function
(
e
)
{
return
e
!=
'SequelizeMeta'
})
expect
(
tableNames
).
to
.
include
(
'Person'
)
this
.
init
({
from
:
20111205064000
,
to
:
20111205064000
},
function
(
migrator
)
{
self
.
init
({
from
:
20111205064000
,
to
:
20111205064000
},
function
(
migrator
)
{
migrator
.
migrate
().
success
(
function
()
{
this
.
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
self
.
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
tableNames
=
tableNames
.
filter
(
function
(
e
){
return
e
!=
'SequelizeMeta'
})
expect
(
tableNames
).
to
Equa
l
([
'User'
])
expect
(
tableNames
).
to
.
eq
l
([
'User'
])
done
()
})
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
})
})
describe
(
'addColumn'
,
function
()
{
it
(
'adds a column to the user table'
,
function
(
done
)
{
var
self
=
this
this
.
init
({
from
:
20111117063700
,
to
:
20111205162700
},
function
(
migrator
)
{
migrator
.
migrate
().
complete
(
function
(
err
)
{
this
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
complete
(
function
(
err
,
data
)
{
self
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
complete
(
function
(
err
,
data
)
{
var
signature
=
data
.
signature
,
isAdmin
=
data
.
isAdmin
,
shopId
=
data
.
shopId
expect
(
signature
.
allowNull
).
to
Equal
(
true
)
expect
(
isAdmin
.
allowNull
).
to
Equal
(
false
)
expect
(
isAdmin
.
defaultValue
).
to
Equal
(
false
)
expect
(
shopId
.
allowNull
).
to
Equal
(
true
)
expect
(
signature
.
allowNull
).
to
.
be
.
true
expect
(
isAdmin
.
allowNull
).
to
.
be
.
false
expect
(
isAdmin
.
defaultValue
).
to
.
equal
(
"0"
)
expect
(
shopId
.
allowNull
).
to
.
be
.
true
done
()
})
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
})
describe
(
'removeColumn'
,
function
()
{
it
(
'removes the shopId column from user'
,
function
(
done
)
{
var
self
=
this
this
.
init
({
to
:
20111206061400
},
function
(
migrator
)
{
migrator
.
migrate
().
success
(
function
(){
this
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
success
(
function
(
data
)
{
self
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
success
(
function
(
data
)
{
var
signature
=
data
.
signature
,
isAdmin
=
data
.
isAdmin
,
shopId
=
data
.
shopId
expect
(
signature
.
allowNull
).
to
Equal
(
true
)
expect
(
isAdmin
.
allowNull
).
to
Equal
(
false
)
expect
(
isAdmin
.
defaultValue
).
to
Equal
(
false
)
expect
(
signature
.
allowNull
).
to
.
be
.
true
expect
(
isAdmin
.
allowNull
).
to
.
be
.
false
expect
(
isAdmin
.
defaultValue
).
to
.
equal
(
'0'
)
expect
(
shopId
).
to
BeFalsy
()
expect
(
shopId
).
to
.
be
.
not
.
ok
done
()
})
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
})
describe
(
'changeColumn'
,
function
()
{
it
(
'changes the signature column from user to default "signature" + notNull'
,
function
(
done
)
{
var
self
=
this
this
.
init
({
to
:
20111206063000
},
function
(
migrator
)
{
migrator
.
migrate
().
success
(
function
()
{
this
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
success
(
function
(
data
)
{
self
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
success
(
function
(
data
)
{
var
signature
=
data
.
signature
if
(
dialect
===
'postgres'
)
{
expect
(
signature
.
type
).
to
E
qual
(
'CHARACTER VARYING'
)
expect
(
signature
.
type
).
to
.
e
qual
(
'CHARACTER VARYING'
)
}
else
{
expect
(
signature
.
type
).
to
E
qual
(
'VARCHAR(255)'
)
expect
(
signature
.
type
).
to
.
e
qual
(
'VARCHAR(255)'
)
}
expect
(
signature
.
allowNull
).
to
E
qual
(
false
)
expect
(
signature
.
defaultValue
).
to
E
qual
(
'Signature'
)
expect
(
signature
.
allowNull
).
to
.
e
qual
(
false
)
expect
(
signature
.
defaultValue
).
to
.
e
qual
(
'Signature'
)
done
()
})
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
})
})
describe
(
'renameColumn'
,
function
()
{
it
(
"renames the signature column from user to sig"
,
function
(
done
)
{
var
self
=
this
this
.
init
({
to
:
20111206163300
},
function
(
migrator
)
{
migrator
.
migrate
().
success
(
function
(){
this
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
success
(
function
(
data
)
{
self
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
success
(
function
(
data
)
{
var
signature
=
data
.
signature
,
sig
=
data
.
sig
expect
(
signature
).
to
BeFalsy
()
expect
(
sig
).
to
BeTruthy
()
expect
(
signature
).
to
.
not
.
be
.
ok
expect
(
sig
).
to
.
be
.
ok
done
()
})
}
.
bind
(
this
)
)
}
.
bind
(
this
)
)
})
})
})
})
})
...
...
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