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 7bf1b71b
authored
Jul 25, 2019
by
Ariel Barabas
Committed by
Sushant
Jul 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(sqlite): don't break when adding second constraint to a table (#11067)
1 parent
ab72dfd5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
2 deletions
lib/dialects/sqlite/query-generator.js
lib/dialects/sqlite/query-interface.js
test/integration/query-interface.test.js
lib/dialects/sqlite/query-generator.js
View file @
7bf1b71
...
@@ -425,7 +425,9 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
...
@@ -425,7 +425,9 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
const
quotedBackupTableName
=
this
.
quoteTable
(
backupTableName
);
const
quotedBackupTableName
=
this
.
quoteTable
(
backupTableName
);
const
attributeNames
=
Object
.
keys
(
attributes
).
map
(
attr
=>
this
.
quoteIdentifier
(
attr
)).
join
(
', '
);
const
attributeNames
=
Object
.
keys
(
attributes
).
map
(
attr
=>
this
.
quoteIdentifier
(
attr
)).
join
(
', '
);
return
`
${
createTableSql
.
replace
(
`CREATE TABLE
${
quotedTableName
}
`
,
`CREATE TABLE
${
quotedBackupTableName
}
`
)
return
`
${
createTableSql
.
replace
(
`CREATE TABLE
${
quotedTableName
}
`
,
`CREATE TABLE
${
quotedBackupTableName
}
`
)
.
replace
(
`CREATE TABLE
${
quotedTableName
.
replace
(
/`/g
,
'"'
)}
`
,
`CREATE TABLE
${
quotedBackupTableName
}
`
)
}
INSERT
INTO
$
{
quotedBackupTableName
}
SELECT
${
attributeNames
}
FROM
${
quotedTableName
}
;`
}
INSERT
INTO
$
{
quotedBackupTableName
}
SELECT
${
attributeNames
}
FROM
${
quotedTableName
}
;`
+
`DROP TABLE
${
quotedTableName
}
;`
+
`DROP TABLE
${
quotedTableName
}
;`
+
`ALTER TABLE
${
quotedBackupTableName
}
RENAME TO
${
quotedTableName
}
;`
;
+
`ALTER TABLE
${
quotedBackupTableName
}
RENAME TO
${
quotedTableName
}
;`
;
...
...
lib/dialects/sqlite/query-interface.js
View file @
7bf1b71
...
@@ -113,7 +113,8 @@ function removeConstraint(qi, tableName, constraintName, options) {
...
@@ -113,7 +113,8 @@ function removeConstraint(qi, tableName, constraintName, options) {
return
qi
.
showConstraint
(
tableName
,
constraintName
)
return
qi
.
showConstraint
(
tableName
,
constraintName
)
.
then
(
constraints
=>
{
.
then
(
constraints
=>
{
const
constraint
=
constraints
[
0
];
// sqlite can't show only one constraint, so we find here the one to remove
const
constraint
=
constraints
.
find
(
constaint
=>
constaint
.
constraintName
===
constraintName
);
if
(
constraint
)
{
if
(
constraint
)
{
createTableSql
=
constraint
.
sql
;
createTableSql
=
constraint
.
sql
;
...
...
test/integration/query-interface.test.js
View file @
7bf1b71
...
@@ -490,6 +490,34 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
...
@@ -490,6 +490,34 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
expect
(
constraints
).
to
.
not
.
include
(
'users_email_uk'
);
expect
(
constraints
).
to
.
not
.
include
(
'users_email_uk'
);
});
});
});
});
it
(
'should add a constraint after another'
,
function
()
{
return
this
.
queryInterface
.
addConstraint
(
'users'
,
[
'username'
],
{
type
:
'unique'
}).
then
(()
=>
this
.
queryInterface
.
addConstraint
(
'users'
,
[
'email'
],
{
type
:
'unique'
}))
.
then
(()
=>
this
.
queryInterface
.
showConstraint
(
'users'
))
.
then
(
constraints
=>
{
constraints
=
constraints
.
map
(
constraint
=>
constraint
.
constraintName
);
expect
(
constraints
).
to
.
include
(
'users_email_uk'
);
expect
(
constraints
).
to
.
include
(
'users_username_uk'
);
return
this
.
queryInterface
.
removeConstraint
(
'users'
,
'users_email_uk'
);
})
.
then
(()
=>
this
.
queryInterface
.
showConstraint
(
'users'
))
.
then
(
constraints
=>
{
constraints
=
constraints
.
map
(
constraint
=>
constraint
.
constraintName
);
expect
(
constraints
).
to
.
not
.
include
(
'users_email_uk'
);
expect
(
constraints
).
to
.
include
(
'users_username_uk'
);
return
this
.
queryInterface
.
removeConstraint
(
'users'
,
'users_username_uk'
);
})
.
then
(()
=>
this
.
queryInterface
.
showConstraint
(
'users'
))
.
then
(
constraints
=>
{
constraints
=
constraints
.
map
(
constraint
=>
constraint
.
constraintName
);
expect
(
constraints
).
to
.
not
.
include
(
'users_email_uk'
);
expect
(
constraints
).
to
.
not
.
include
(
'users_username_uk'
);
});
});
});
});
if
(
current
.
dialect
.
supports
.
constraints
.
check
)
{
if
(
current
.
dialect
.
supports
.
constraints
.
check
)
{
...
...
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