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 3fd1d95b
authored
Jan 03, 2012
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed obsolete migration + createTable can handle complex attribute definition
1 parent
4312d328
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
6 deletions
lib/query-interface.js
spec/assets/migrations/20111117063700-createPerson.js
spec/migrator.spec.js
lib/query-interface.js
View file @
3fd1d95
...
...
@@ -9,6 +9,17 @@ module.exports = (function() {
Utils
.
addEventEmitter
(
QueryInterface
)
QueryInterface
.
prototype
.
createTable
=
function
(
tableName
,
attributes
,
options
)
{
var
attributeHashes
=
{}
Utils
.
_
.
each
(
attributes
,
function
(
dataTypeOrOptions
,
attributeName
)
{
if
(
Utils
.
_
.
values
(
DataTypes
).
indexOf
(
dataTypeOrOptions
)
>
-
1
)
attributeHashes
[
attributeName
]
=
{
type
:
dataTypeOrOptions
}
else
attributeHashes
[
attributeName
]
=
dataTypeOrOptions
})
attributes
=
this
.
QueryGenerator
.
attributesToSQL
(
attributeHashes
)
var
sql
=
this
.
QueryGenerator
.
createTableQuery
(
tableName
,
attributes
,
options
)
return
queryAndEmit
.
call
(
this
,
sql
,
'createTable'
)
}
...
...
spec/assets/migrations/20111117063700-createPerson.js
View file @
3fd1d95
module
.
exports
=
{
up
:
function
(
migration
,
DataTypes
)
{
migration
.
createTable
(
'Person'
,
{
name
:
DataTypes
.
STRING
name
:
DataTypes
.
STRING
,
isBetaMember
:
{
type
:
DataTypes
.
BOOLEAN
,
defaultValue
:
false
,
allowNull
:
false
}
})
},
down
:
function
(
migration
)
{
...
...
spec/migrator.spec.js
View file @
3fd1d95
...
...
@@ -62,21 +62,21 @@ describe('Migrator', function() {
})
it
(
"returns also the file which is exactly options.from or options.to"
,
function
()
{
setup
({
from
:
20111117063700
,
to
:
201111
230607
00
})
setup
({
from
:
20111117063700
,
to
:
201111
301611
00
})
Helpers
.
async
(
function
(
done
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
toBeNull
()
expect
(
migrations
.
length
).
toEqual
(
2
)
expect
(
migrations
[
0
].
filename
).
toEqual
(
'20111117063700-createPerson.js'
)
expect
(
migrations
[
1
].
filename
).
toEqual
(
'201111
23060700-addBirthdateToPers
on.js'
)
expect
(
migrations
[
1
].
filename
).
toEqual
(
'201111
30161100-emptyMigrati
on.js'
)
done
()
})
})
})
it
(
"returns all files to options.to if no options.from is defined"
,
function
()
{
setup
({
to
:
201111
230607
00
})
setup
({
to
:
201111
301611
00
})
Helpers
.
async
(
function
(
done
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
...
...
@@ -94,8 +94,8 @@ describe('Migrator', function() {
SequelizeMeta
.
create
({
from
:
null
,
to
:
'20111117063700'
}).
success
(
function
()
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
toBeNull
()
expect
(
migrations
.
length
).
toEqual
(
7
)
expect
(
migrations
[
0
].
filename
).
toEqual
(
'201111
23060700-addBirthdateToPers
on.js'
)
expect
(
migrations
.
length
).
toEqual
(
6
)
expect
(
migrations
[
0
].
filename
).
toEqual
(
'201111
30161100-emptyMigrati
on.js'
)
done
()
})
})
...
...
@@ -124,6 +124,16 @@ describe('Migrator', function() {
})
})
it
(
"executes migration #20111117063700 and correctly adds isBetaMember"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
sequelize
.
getQueryInterface
().
describeTable
(
'Person'
).
success
(
function
(
data
)
{
var
beta
=
data
.
filter
(
function
(
d
)
{
return
d
.
Field
==
'isBetaMember'
})
expect
(
beta
).
toBeDefined
()
done
()
})
})
})
it
(
"executes migration #20111117063700 correctly up (createTable) and downwards (dropTable)"
,
function
()
{
Helpers
.
async
(
function
(
done
)
{
sequelize
.
getQueryInterface
().
showAllTables
().
success
(
function
(
tableNames
)
{
...
...
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