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 ebec0cf9
authored
Sep 08, 2018
by
Sushant
Committed by
GitHub
Sep 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(changeColumn): use engine defaults for foreign/unique key naming (#9890)
1 parent
27e44941
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
10 additions
and
12 deletions
lib/dialects/mssql/query-generator.js
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
test/integration/query-interface/changeColumn.test.js
test/unit/sql/change-column.test.js
lib/dialects/mssql/query-generator.js
View file @
ebec0cf
...
@@ -260,8 +260,7 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
...
@@ -260,8 +260,7 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
for
(
const
attributeName
in
attributes
)
{
for
(
const
attributeName
in
attributes
)
{
const
definition
=
attributes
[
attributeName
];
const
definition
=
attributes
[
attributeName
];
if
(
definition
.
match
(
/REFERENCES/
))
{
if
(
definition
.
match
(
/REFERENCES/
))
{
constraintString
.
push
(
_
.
template
(
'<%= fkName %> FOREIGN KEY (<%= attrName %>) <%= definition %>'
,
this
.
_templateSettings
)({
constraintString
.
push
(
_
.
template
(
'FOREIGN KEY (<%= attrName %>) <%= definition %>'
,
this
.
_templateSettings
)({
fkName
:
this
.
quoteIdentifier
(
attributeName
+
'_foreign_idx'
),
attrName
:
this
.
quoteIdentifier
(
attributeName
),
attrName
:
this
.
quoteIdentifier
(
attributeName
),
definition
:
definition
.
replace
(
/.+
?(?=
REFERENCES
)
/
,
''
)
definition
:
definition
.
replace
(
/.+
?(?=
REFERENCES
)
/
,
''
)
}));
}));
...
@@ -279,7 +278,7 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
...
@@ -279,7 +278,7 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
finalQuery
+=
constraintString
.
length
?
' '
:
''
;
finalQuery
+=
constraintString
.
length
?
' '
:
''
;
}
}
if
(
constraintString
.
length
)
{
if
(
constraintString
.
length
)
{
finalQuery
+=
'ADD
CONSTRAINT
'
+
constraintString
.
join
(
', '
);
finalQuery
+=
'ADD '
+
constraintString
.
join
(
', '
);
}
}
return
_
.
template
(
query
,
this
.
_templateSettings
)({
return
_
.
template
(
query
,
this
.
_templateSettings
)({
...
...
lib/dialects/mysql/query-generator.js
View file @
ebec0cf
...
@@ -141,10 +141,9 @@ class MySQLQueryGenerator extends AbstractQueryGenerator {
...
@@ -141,10 +141,9 @@ class MySQLQueryGenerator extends AbstractQueryGenerator {
for
(
const
attributeName
in
attributes
)
{
for
(
const
attributeName
in
attributes
)
{
let
definition
=
attributes
[
attributeName
];
let
definition
=
attributes
[
attributeName
];
if
(
definition
.
match
(
/REFERENCES/
))
{
if
(
definition
.
match
(
/REFERENCES/
))
{
const
fkName
=
this
.
quoteIdentifier
(
tableName
+
'_'
+
attributeName
+
'_foreign_idx'
);
const
attrName
=
this
.
quoteIdentifier
(
attributeName
);
const
attrName
=
this
.
quoteIdentifier
(
attributeName
);
definition
=
definition
.
replace
(
/.+
?(?=
REFERENCES
)
/
,
''
);
definition
=
definition
.
replace
(
/.+
?(?=
REFERENCES
)
/
,
''
);
constraintString
.
push
(
`
${
fkName
}
FOREIGN KEY (
${
attrName
}
)
${
definition
}
`
);
constraintString
.
push
(
`FOREIGN KEY (
${
attrName
}
)
${
definition
}
`
);
}
else
{
}
else
{
attrString
.
push
(
'`'
+
attributeName
+
'` `'
+
attributeName
+
'` '
+
definition
);
attrString
.
push
(
'`'
+
attributeName
+
'` `'
+
attributeName
+
'` '
+
definition
);
}
}
...
@@ -156,7 +155,7 @@ class MySQLQueryGenerator extends AbstractQueryGenerator {
...
@@ -156,7 +155,7 @@ class MySQLQueryGenerator extends AbstractQueryGenerator {
finalQuery
+=
constraintString
.
length
?
' '
:
''
;
finalQuery
+=
constraintString
.
length
?
' '
:
''
;
}
}
if
(
constraintString
.
length
)
{
if
(
constraintString
.
length
)
{
finalQuery
+=
'ADD
CONSTRAINT
'
+
constraintString
.
join
(
', '
);
finalQuery
+=
'ADD '
+
constraintString
.
join
(
', '
);
}
}
return
`ALTER TABLE
${
this
.
quoteTable
(
tableName
)}
${
finalQuery
}
;`
;
return
`ALTER TABLE
${
this
.
quoteTable
(
tableName
)}
${
finalQuery
}
;`
;
...
...
lib/dialects/postgres/query-generator.js
View file @
ebec0cf
...
@@ -294,7 +294,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
...
@@ -294,7 +294,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
attrSql
+=
_
.
template
(
query
.
replace
(
'ALTER COLUMN'
,
''
),
this
.
_templateSettings
)({
attrSql
+=
_
.
template
(
query
.
replace
(
'ALTER COLUMN'
,
''
),
this
.
_templateSettings
)({
tableName
:
this
.
quoteTable
(
tableName
),
tableName
:
this
.
quoteTable
(
tableName
),
query
:
'ADD
CONSTRAINT '
+
this
.
quoteIdentifier
(
attributeName
+
'_unique_idx'
)
+
'
UNIQUE ('
+
this
.
quoteIdentifier
(
attributeName
)
+
')'
query
:
'ADD UNIQUE ('
+
this
.
quoteIdentifier
(
attributeName
)
+
')'
});
});
}
}
...
@@ -302,7 +302,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
...
@@ -302,7 +302,7 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
definition
=
definition
.
replace
(
/.+
?(?=
REFERENCES
)
/
,
''
);
definition
=
definition
.
replace
(
/.+
?(?=
REFERENCES
)
/
,
''
);
attrSql
+=
_
.
template
(
query
.
replace
(
'ALTER COLUMN'
,
''
),
this
.
_templateSettings
)({
attrSql
+=
_
.
template
(
query
.
replace
(
'ALTER COLUMN'
,
''
),
this
.
_templateSettings
)({
tableName
:
this
.
quoteTable
(
tableName
),
tableName
:
this
.
quoteTable
(
tableName
),
query
:
'ADD
CONSTRAINT '
+
this
.
quoteIdentifier
(
attributeName
+
'_foreign_idx'
)
+
'
FOREIGN KEY ('
+
this
.
quoteIdentifier
(
attributeName
)
+
') '
+
definition
query
:
'ADD FOREIGN KEY ('
+
this
.
quoteIdentifier
(
attributeName
)
+
') '
+
definition
});
});
}
else
{
}
else
{
attrSql
+=
_
.
template
(
query
,
this
.
_templateSettings
)({
attrSql
+=
_
.
template
(
query
,
this
.
_templateSettings
)({
...
...
test/integration/query-interface/changeColumn.test.js
View file @
ebec0cf
...
@@ -113,7 +113,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
...
@@ -113,7 +113,7 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
});
});
}
}
//SQlite na
vitely doesn
t support ALTER Foreign key
//SQlite na
tively doesn'
t support ALTER Foreign key
if
(
dialect
!==
'sqlite'
)
{
if
(
dialect
!==
'sqlite'
)
{
describe
(
'should support foreign keys'
,
()
=>
{
describe
(
'should support foreign keys'
,
()
=>
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
...
...
test/unit/sql/change-column.test.js
View file @
ebec0cf
...
@@ -62,9 +62,9 @@ if (current.dialect.name !== 'sqlite') {
...
@@ -62,9 +62,9 @@ if (current.dialect.name !== 'sqlite') {
onDelete
:
'cascade'
onDelete
:
'cascade'
}).
then
(
sql
=>
{
}).
then
(
sql
=>
{
expectsql
(
sql
,
{
expectsql
(
sql
,
{
mssql
:
'ALTER TABLE [users] ADD
CONSTRAINT [level_id_foreign_idx]
FOREIGN KEY ([level_id]) REFERENCES [level] ([id]) ON DELETE CASCADE;'
,
mssql
:
'ALTER TABLE [users] ADD FOREIGN KEY ([level_id]) REFERENCES [level] ([id]) ON DELETE CASCADE;'
,
mysql
:
'ALTER TABLE `users` ADD
CONSTRAINT `users_level_id_foreign_idx`
FOREIGN KEY (`level_id`) REFERENCES `level` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;'
,
mysql
:
'ALTER TABLE `users` ADD FOREIGN KEY (`level_id`) REFERENCES `level` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;'
,
postgres
:
'ALTER TABLE "users" ADD
CONSTRAINT "level_id_foreign_idx"
FOREIGN KEY ("level_id") REFERENCES "level" ("id") ON DELETE CASCADE ON UPDATE CASCADE;'
postgres
:
'ALTER TABLE "users" ADD FOREIGN KEY ("level_id") REFERENCES "level" ("id") ON DELETE CASCADE ON UPDATE 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