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 be4ffc9b
authored
May 04, 2013
by
Martin Aspeli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for dropping tables with constraints
1 parent
f293a111
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
6 deletions
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
lib/dialects/query-generator.js
lib/dialects/sqlite/query-generator.js
lib/query-interface.js
spec-jasmine/postgres/query-generator.spec.js
lib/dialects/mysql/query-generator.js
View file @
be4ffc9
...
@@ -496,6 +496,16 @@ module.exports = (function() {
...
@@ -496,6 +496,16 @@ module.exports = (function() {
return
fields
return
fields
},
},
enableForeignKeyConstraintsQuery
:
function
()
{
var
sql
=
"SET FOREIGN_KEY_CHECKS = 1;"
return
Utils
.
_
.
template
(
sql
,
{})
},
disableForeignKeyConstraintsQuery
:
function
()
{
var
sql
=
"SET FOREIGN_KEY_CHECKS = 0;"
return
Utils
.
_
.
template
(
sql
,
{})
},
addQuotes
:
function
(
s
,
quoteChar
)
{
addQuotes
:
function
(
s
,
quoteChar
)
{
return
Utils
.
addTicks
(
s
,
quoteChar
)
return
Utils
.
addTicks
(
s
,
quoteChar
)
},
},
...
...
lib/dialects/postgres/query-generator.js
View file @
be4ffc9
...
@@ -78,7 +78,7 @@ module.exports = (function() {
...
@@ -78,7 +78,7 @@ module.exports = (function() {
dropTableQuery
:
function
(
tableName
,
options
)
{
dropTableQuery
:
function
(
tableName
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
var
query
=
"DROP TABLE IF EXISTS <%= table %>;"
var
query
=
"DROP TABLE IF EXISTS <%= table %>
CASCADE
;"
return
Utils
.
_
.
template
(
query
)({
return
Utils
.
_
.
template
(
query
)({
table
:
QueryGenerator
.
addQuotes
(
tableName
)
table
:
QueryGenerator
.
addQuotes
(
tableName
)
})
})
...
@@ -602,8 +602,16 @@ module.exports = (function() {
...
@@ -602,8 +602,16 @@ module.exports = (function() {
return
fields
return
fields
},
},
enableForeignKeyConstraintsQuery
:
function
()
{
return
false
// not supported by dialect
},
disableForeignKeyConstraintsQuery
:
function
()
{
return
false
// not supported by dialect
},
databaseConnectionUri
:
function
(
config
)
{
databaseConnectionUri
:
function
(
config
)
{
var
template
=
'<%= protocol %>://<%= user %>:<%= password %>@<%= host %><% if(port) { %>:<%= port %><% } %>/<%= database %>'
;
var
template
=
'<%= protocol %>://<%= user %>:<%= password %>@<%= host %><% if(port) { %>:<%= port %><% } %>/<%= database %>'
return
Utils
.
_
.
template
(
template
)({
return
Utils
.
_
.
template
(
template
)({
user
:
encodeURIComponent
(
config
.
username
),
user
:
encodeURIComponent
(
config
.
username
),
...
...
lib/dialects/query-generator.js
View file @
be4ffc9
...
@@ -229,7 +229,22 @@ module.exports = (function() {
...
@@ -229,7 +229,22 @@ module.exports = (function() {
*/
*/
findAutoIncrementField
:
function
(
factory
)
{
findAutoIncrementField
:
function
(
factory
)
{
throwMethodUndefined
(
'findAutoIncrementField'
)
throwMethodUndefined
(
'findAutoIncrementField'
)
},
/*
Globally enable foreign key constraints
*/
enableForeignKeyConstraintsQuery
:
function
()
{
throwMethodUndefined
(
'enableForeignKeyConstraintsQuery'
)
},
/*
Globally disable foreign key constraints
*/
disableForeignKeyConstraintsQuery
:
function
()
{
throwMethodUndefined
(
'disableForeignKeyConstraintsQuery'
)
}
}
}
}
var
throwMethodUndefined
=
function
(
methodName
)
{
var
throwMethodUndefined
=
function
(
methodName
)
{
...
...
lib/dialects/sqlite/query-generator.js
View file @
be4ffc9
...
@@ -265,6 +265,16 @@ module.exports = (function() {
...
@@ -265,6 +265,16 @@ module.exports = (function() {
return
fields
return
fields
},
},
enableForeignKeyConstraintsQuery
:
function
()
{
var
sql
=
"PRAGMA foreign_keys = ON;"
return
Utils
.
_
.
template
(
sql
,
{})
},
disableForeignKeyConstraintsQuery
:
function
()
{
var
sql
=
"PRAGMA foreign_keys = OFF;"
return
Utils
.
_
.
template
(
sql
,
{})
},
hashToWhereConditions
:
function
(
hash
)
{
hashToWhereConditions
:
function
(
hash
)
{
for
(
var
key
in
hash
)
{
for
(
var
key
in
hash
)
{
if
(
hash
.
hasOwnProperty
(
key
))
{
if
(
hash
.
hasOwnProperty
(
key
))
{
...
...
lib/query-interface.js
View file @
be4ffc9
...
@@ -91,11 +91,17 @@ module.exports = (function() {
...
@@ -91,11 +91,17 @@ module.exports = (function() {
var
chainer
=
new
Utils
.
QueryChainer
()
var
chainer
=
new
Utils
.
QueryChainer
()
self
.
showAllTables
().
success
(
function
(
tableNames
)
{
self
.
showAllTables
().
success
(
function
(
tableNames
)
{
chainer
.
add
(
self
,
'disableForeignKeyConstraints'
,
[])
tableNames
.
forEach
(
function
(
tableName
)
{
tableNames
.
forEach
(
function
(
tableName
)
{
chainer
.
add
(
self
.
dropTable
(
tableName
)
)
chainer
.
add
(
self
,
'dropTable'
,
[
tableName
]
)
})
})
chainer
.
add
(
self
,
'enableForeignKeyConstraints'
,
[])
chainer
chainer
.
run
()
.
run
Serially
()
.
success
(
function
()
{
.
success
(
function
()
{
self
.
emit
(
'dropAllTables'
,
null
)
self
.
emit
(
'dropAllTables'
,
null
)
emitter
.
emit
(
'success'
,
null
)
emitter
.
emit
(
'success'
,
null
)
...
@@ -313,6 +319,30 @@ module.exports = (function() {
...
@@ -313,6 +319,30 @@ module.exports = (function() {
}).
run
()
}).
run
()
}
}
QueryInterface
.
prototype
.
enableForeignKeyConstraints
=
function
()
{
var
sql
=
this
.
QueryGenerator
.
enableForeignKeyConstraintsQuery
()
if
(
sql
)
{
return
queryAndEmit
.
call
(
this
,
sql
,
'enableForeignKeyConstraints'
)
}
else
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
this
.
emit
(
'enableForeignKeyConstraints'
,
null
)
emitter
.
emit
(
'success'
)
}).
run
()
}
}
QueryInterface
.
prototype
.
disableForeignKeyConstraints
=
function
()
{
var
sql
=
this
.
QueryGenerator
.
disableForeignKeyConstraintsQuery
()
if
(
sql
){
return
queryAndEmit
.
call
(
this
,
sql
,
'disableForeignKeyConstraints'
)
}
else
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
this
.
emit
(
'disableForeignKeyConstraints'
,
null
)
emitter
.
emit
(
'success'
)
}).
run
()
}
}
// private
// private
var
queryAndEmit
=
function
(
sqlOrQueryParams
,
methodName
,
options
,
emitter
)
{
var
queryAndEmit
=
function
(
sqlOrQueryParams
,
methodName
,
options
,
emitter
)
{
...
...
spec-jasmine/postgres/query-generator.spec.js
View file @
be4ffc9
...
@@ -96,11 +96,11 @@ describe('QueryGenerator', function() {
...
@@ -96,11 +96,11 @@ describe('QueryGenerator', function() {
dropTableQuery
:
[
dropTableQuery
:
[
{
{
arguments
:
[
'myTable'
],
arguments
:
[
'myTable'
],
expectation
:
"DROP TABLE IF EXISTS \"myTable\";"
expectation
:
"DROP TABLE IF EXISTS \"myTable\"
CASCADE
;"
},
},
{
{
arguments
:
[
'mySchema.myTable'
],
arguments
:
[
'mySchema.myTable'
],
expectation
:
"DROP TABLE IF EXISTS \"mySchema\".\"myTable\";"
expectation
:
"DROP TABLE IF EXISTS \"mySchema\".\"myTable\"
CASCADE
;"
}
}
],
],
...
...
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