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 0ba5d25a
authored
Jul 30, 2013
by
Daniel Durante
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding unique to a column for Postgres in the migrator should be fixed. Closes #623
1 parent
9a41b4ae
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
3 deletions
lib/dialects/postgres/query-generator.js
test/assets/migrations/20111205167000-addUniqueNameColumnToUser.js
test/migrator.test.js
lib/dialects/postgres/query-generator.js
View file @
0ba5d25
...
@@ -189,6 +189,15 @@ module.exports = (function() {
...
@@ -189,6 +189,15 @@ module.exports = (function() {
definition
=
definition
.
replace
(
/^ENUM
\(
.+
\)
/
,
this
.
quoteIdentifier
(
"enum_"
+
tableName
+
"_"
+
attributeName
))
definition
=
definition
.
replace
(
/^ENUM
\(
.+
\)
/
,
this
.
quoteIdentifier
(
"enum_"
+
tableName
+
"_"
+
attributeName
))
}
}
if
(
definition
.
match
(
/UNIQUE;*$/
))
{
definition
=
definition
.
replace
(
/UNIQUE;*$/
,
''
)
attrSql
+=
Utils
.
_
.
template
(
query
.
replace
(
'ALTER COLUMN'
,
''
))({
tableName
:
this
.
quoteIdentifiers
(
tableName
),
query
:
'ADD CONSTRAINT '
+
this
.
quoteIdentifier
(
attributeName
+
'_unique_idx'
)
+
' UNIQUE ('
+
this
.
quoteIdentifier
(
attributeName
)
+
')'
})
}
attrSql
+=
Utils
.
_
.
template
(
query
)({
attrSql
+=
Utils
.
_
.
template
(
query
)({
tableName
:
this
.
quoteIdentifiers
(
tableName
),
tableName
:
this
.
quoteIdentifiers
(
tableName
),
query
:
this
.
quoteIdentifier
(
attributeName
)
+
' TYPE '
+
definition
query
:
this
.
quoteIdentifier
(
attributeName
)
+
' TYPE '
+
definition
...
...
test/assets/migrations/20111205167000-addUniqueNameColumnToUser.js
0 → 100644
View file @
0ba5d25
module
.
exports
=
{
up
:
function
(
migration
,
DataTypes
,
done
)
{
migration
.
addColumn
(
'User'
,
'uniqueName'
,
{
type
:
DataTypes
.
STRING
}).
complete
(
function
()
{
migration
.
changeColumn
(
'User'
,
'uniqueName'
,
{
type
:
DataTypes
.
STRING
,
allowNull
:
false
,
unique
:
true
}).
complete
(
done
)
})
},
down
:
function
(
migration
,
DataTypes
,
done
)
{
migration
.
removeColumn
(
'User'
,
'uniqueName'
).
complete
(
done
)
}
}
test/migrator.test.js
View file @
0ba5d25
var
chai
=
require
(
'chai'
)
var
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/support'
)
,
Support
=
require
(
__dirname
+
'/support'
)
,
DataTypes
=
require
(
__dirname
+
"/../lib/data-types"
)
,
QueryChainer
=
require
(
"../lib/query-chainer"
)
,
Migrator
=
require
(
"../lib/migrator"
)
,
Migrator
=
require
(
"../lib/migrator"
)
,
dialect
=
Support
.
getTestDialect
()
,
dialect
=
Support
.
getTestDialect
()
...
@@ -16,6 +14,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
...
@@ -16,6 +14,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
logging
:
function
(){}
logging
:
function
(){}
},
options
||
{})
},
options
||
{})
// this.sequelize.options.logging = console.log
var
migrator
=
new
Migrator
(
this
.
sequelize
,
options
)
var
migrator
=
new
Migrator
(
this
.
sequelize
,
options
)
migrator
migrator
...
@@ -87,7 +86,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
...
@@ -87,7 +86,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
SequelizeMeta
.
create
({
from
:
null
,
to
:
20111117063700
}).
success
(
function
()
{
SequelizeMeta
.
create
({
from
:
null
,
to
:
20111117063700
}).
success
(
function
()
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
migrator
.
getUndoneMigrations
(
function
(
err
,
migrations
)
{
expect
(
err
).
to
.
be
.
null
expect
(
err
).
to
.
be
.
null
expect
(
migrations
).
to
.
have
.
length
(
6
)
expect
(
migrations
).
to
.
have
.
length
(
7
)
expect
(
migrations
[
0
].
filename
).
to
.
equal
(
'20111130161100-emptyMigration.js'
)
expect
(
migrations
[
0
].
filename
).
to
.
equal
(
'20111130161100-emptyMigration.js'
)
done
()
done
()
})
})
...
@@ -186,6 +185,31 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
...
@@ -186,6 +185,31 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
})
})
describe
(
'addColumn'
,
function
()
{
describe
(
'addColumn'
,
function
()
{
it
(
'adds a unique column to the user table'
,
function
(
done
)
{
var
self
=
this
this
.
init
({
from
:
20111117063700
,
to
:
20111205167000
},
function
(
migrator
)
{
migrator
.
migrate
().
complete
(
function
(
err
)
{
self
.
sequelize
.
getQueryInterface
().
describeTable
(
'User'
).
complete
(
function
(
err
,
data
)
{
var
signature
=
data
.
signature
,
isAdmin
=
data
.
isAdmin
,
shopId
=
data
.
shopId
expect
(
signature
.
allowNull
).
to
.
be
.
true
expect
(
isAdmin
.
allowNull
).
to
.
be
.
false
if
(
dialect
===
"postgres"
||
dialect
===
"postgres-native"
||
dialect
===
"sqlite"
)
{
expect
(
isAdmin
.
defaultValue
).
to
.
be
.
false
}
else
{
expect
(
isAdmin
.
defaultValue
).
to
.
equal
(
"0"
)
}
expect
(
shopId
.
allowNull
).
to
.
be
.
true
done
()
})
})
})
})
it
(
'adds a column to the user table'
,
function
(
done
)
{
it
(
'adds a column to the user table'
,
function
(
done
)
{
var
self
=
this
var
self
=
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