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 d1e7998b
authored
Jan 31, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge master into 2.0
1 parent
4b1b89f3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
11 deletions
changelog.md
lib/dao-validator.js
lib/dialects/postgres/query-generator.js
lib/query-interface.js
test/migrator.test.js
test/query-interface.test.js
test/support.js
changelog.md
View file @
d1e7998
...
...
@@ -3,9 +3,10 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
# v1.7.0-rc4
-
fixes issue with postgres sync and enums
[
#1020
](
https://github.com/sequelize/sequelize/issues/1020
)
-
fixes various issues with limit and includes
[
#1322
](
https://github.com/sequelize/sequelize/pull/1322
)
-
fixes issues with migrations/queryInterface createTable and enums
#### Backwards compatability changes
-
find/findAll will no
t
always return primary keys regardless of
`attributes`
settings. (Motivation was to fix various issues with eager loading)
-
find/findAll will no
w
always return primary keys regardless of
`attributes`
settings. (Motivation was to fix various issues with eager loading)
# v1.7.0-rc3
-
dropAllTables now takes an option parameter with
`skip`
as an option
[
#1280
](
https://github.com/sequelize/sequelize/pull/1280
)
...
...
lib/dao-validator.js
View file @
d1e7998
...
...
@@ -91,7 +91,7 @@ var validateAttributes = function() {
,
errors
=
{}
Utils
.
_
.
each
(
this
.
model
.
rawAttributes
,
function
(
rawAttribute
,
field
)
{
var
value
=
self
.
model
.
dataValues
[
field
]
||
undefined
var
value
=
self
.
model
.
dataValues
[
field
]
,
hasAllowedNull
=
((
rawAttribute
===
undefined
||
rawAttribute
.
allowNull
===
true
)
&&
((
value
===
null
)
||
(
value
===
undefined
)))
,
isSkipped
=
self
.
options
.
skip
.
length
>
0
&&
self
.
options
.
skip
.
indexOf
(
field
)
!==
-
1
...
...
lib/dialects/postgres/query-generator.js
View file @
d1e7998
...
...
@@ -710,7 +710,15 @@ module.exports = (function() {
pgEnum
:
function
(
tableName
,
attr
,
dataType
,
options
)
{
var
enumName
=
this
.
pgEscapeAndQuote
(
"enum_"
+
tableName
+
"_"
+
attr
)
var
sql
=
"CREATE TYPE "
+
enumName
+
" AS "
+
dataType
.
match
(
/^ENUM
\(
.+
\)
/
)[
0
]
+
"; "
,
values
if
(
dataType
.
values
)
{
values
=
"ENUM('"
+
dataType
.
values
.
join
(
"', '"
)
+
"')"
;
}
else
{
values
=
dataType
.
toString
().
match
(
/^ENUM
\(
.+
\)
/
)[
0
]
}
var
sql
=
"CREATE TYPE "
+
enumName
+
" AS "
+
values
+
"; "
if
(
!!
options
&&
options
.
force
===
true
)
{
sql
=
this
.
pgEnumDrop
(
tableName
,
attr
)
+
sql
}
...
...
@@ -731,8 +739,8 @@ module.exports = (function() {
return
sql
},
pgEnumDrop
:
function
(
tableName
,
attr
)
{
var
enumName
=
this
.
pgEscapeAndQuote
(
"enum_"
+
tableName
+
"_"
+
attr
)
pgEnumDrop
:
function
(
tableName
,
attr
,
enumName
)
{
enumName
=
enumName
||
this
.
pgEscapeAndQuote
(
"enum_"
+
tableName
+
"_"
+
attr
)
return
'DROP TYPE IF EXISTS '
+
enumName
+
'; '
},
...
...
lib/query-interface.js
View file @
d1e7998
...
...
@@ -101,7 +101,7 @@ module.exports = (function() {
,
getTableName
=
(
!
options
||
!
options
.
schema
||
options
.
schema
===
"public"
?
''
:
options
.
schema
+
'_'
)
+
tableName
for
(
i
=
0
;
i
<
keyLen
;
i
++
)
{
if
(
attributes
[
keys
[
i
]].
toString
().
match
(
/^ENUM
\(
/
))
{
if
(
attributes
[
keys
[
i
]].
toString
().
match
(
/^ENUM
\(
/
)
||
attributes
[
keys
[
i
]].
toString
()
===
"ENUM"
||
(
attributes
[
keys
[
i
]].
type
&&
attributes
[
keys
[
i
]].
type
.
toString
()
===
"ENUM"
)
)
{
sql
=
self
.
QueryGenerator
.
pgListEnums
(
getTableName
,
keys
[
i
],
options
)
chainer
.
add
(
self
.
sequelize
.
query
(
sql
,
null
,
{
plain
:
true
,
raw
:
true
,
type
:
QueryTypes
.
SELECT
,
logging
:
options
.
logging
}))
}
...
...
@@ -116,7 +116,7 @@ module.exports = (function() {
daoTable
=
daoTable
.
length
>
0
?
daoTable
[
0
]
:
null
for
(
i
=
0
;
i
<
keyLen
;
i
++
)
{
if
(
attributes
[
keys
[
i
]].
toString
().
match
(
/^ENUM
\(
/
))
{
if
(
attributes
[
keys
[
i
]].
toString
().
match
(
/^ENUM
\(
/
)
||
attributes
[
keys
[
i
]].
toString
()
===
"ENUM"
||
(
attributes
[
keys
[
i
]].
type
&&
attributes
[
keys
[
i
]].
type
.
toString
()
===
"ENUM"
)
)
{
// If the enum type doesn't exist then create it
if
(
!
results
[
enumIdx
])
{
sql
=
self
.
QueryGenerator
.
pgEnum
(
getTableName
,
keys
[
i
],
attributes
[
keys
[
i
]],
options
)
...
...
@@ -288,6 +288,36 @@ module.exports = (function() {
}
}
QueryInterface
.
prototype
.
dropAllEnums
=
function
(
options
)
{
if
(
this
.
sequelize
.
getDialect
()
!==
'postgres'
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
emitter
.
emit
(
'success'
)
}).
run
()
}
options
=
options
||
{}
var
self
=
this
,
emitter
=
new
Utils
.
CustomEventEmitter
()
,
chainer
=
new
Utils
.
QueryChainer
()
,
sql
=
this
.
QueryGenerator
.
pgListEnums
()
this
.
sequelize
.
query
(
sql
,
null
,
{
plain
:
false
,
raw
:
true
,
type
:
QueryTypes
.
SELECT
,
logging
:
options
.
logging
})
.
proxy
(
emitter
,
{
events
:
[
'sql'
,
'error'
]})
.
success
(
function
(
results
)
{
results
.
forEach
(
function
(
result
)
{
chainer
.
add
(
self
.
sequelize
.
query
(
self
.
QueryGenerator
.
pgEnumDrop
(
null
,
null
,
result
.
enum_name
),
null
,
{
logging
:
options
.
logging
,
raw
:
true
}
))
})
chainer
.
run
().
proxy
(
emitter
)
})
return
emitter
}
QueryInterface
.
prototype
.
renameTable
=
function
(
before
,
after
)
{
var
sql
=
this
.
QueryGenerator
.
renameTableQuery
(
before
,
after
)
return
queryAndEmit
.
call
(
this
,
sql
,
'renameTable'
)
...
...
test/migrator.test.js
View file @
d1e7998
...
...
@@ -2,6 +2,7 @@ var chai = require('chai')
,
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/support'
)
,
Migrator
=
require
(
"../lib/migrator"
)
,
DataTypes
=
require
(
"../lib/data-types"
)
,
dialect
=
Support
.
getTestDialect
()
chai
.
Assertion
.
includeStack
=
true
...
...
@@ -287,7 +288,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
})
})
})
})
describe
(
'renameColumn'
,
function
()
{
it
(
"renames the signature column from user to sig"
,
function
(
done
)
{
...
...
@@ -308,7 +309,7 @@ describe(Support.getTestDialectTeaser("Migrator"), function() {
})
})
})
if
(
dialect
.
match
(
/^postgres/
))
{
describe
(
'function migrations'
,
function
()
{
...
...
test/query-interface.test.js
View file @
d1e7998
...
...
@@ -142,4 +142,27 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
})
})
})
describe
(
'createTable'
,
function
()
{
it
(
'should work with enums (1)'
,
function
(
done
)
{
this
.
queryInterface
.
createTable
(
'SomeTable'
,
{
someEnum
:
DataTypes
.
ENUM
(
'value1'
,
'value2'
,
'value3'
)
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
done
()
})
})
it
(
'should work with enums (2)'
,
function
(
done
)
{
this
.
queryInterface
.
createTable
(
'SomeTable'
,
{
someEnum
:
{
type
:
DataTypes
.
ENUM
,
values
:
[
'value1'
,
'value2'
,
'value3'
]
}
}).
done
(
function
(
err
)
{
expect
(
err
).
not
.
to
.
be
.
ok
done
()
})
})
})
})
test/support.js
View file @
d1e7998
...
...
@@ -83,9 +83,18 @@ var Support = {
.
dropAllTables
()
.
success
(
function
()
{
sequelize
.
daoFactoryManager
.
daos
=
[]
callback
&&
callback
()
sequelize
.
getQueryInterface
()
.
dropAllEnums
()
.
success
(
callback
)
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
})
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
.
error
(
function
(
err
)
{
console
.
log
(
err
)
})
},
getSupportedDialects
:
function
()
{
...
...
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