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 e41590af
authored
Sep 08, 2017
by
Satana Charuwichitratana
Committed by
Sushant
Sep 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(mysql/addColumn): supports FIRST keyword (#7943)
1 parent
1e0d9a86
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
docs/migrations.md
lib/dialects/mysql/query-generator.js
test/unit/sql/add-column.test.js
docs/migrations.md
View file @
e41590a
...
...
@@ -207,6 +207,30 @@ queryInterface.addColumn(
}
)
// or with first attribute to put the column at the beginning of the table
// currently supports only in MySQL
queryInterface
.
addColumn
(
'nameOfAnExistingTable'
,
'nameOfTheNewAttribute'
,
{
type
:
Sequelize
.
STRING
,
first
:
true
}
)
// or with after attribute to put the column after a specific column
// currently supports only in MySQL
queryInterface
.
addColumn
(
'nameOfAnExistingTable'
,
'nameOfTheNewAttribute'
,
{
type
:
Sequelize
.
STRING
,
after
:
'nameOfAnExistingColumn'
}
)
// or with an explicit schema:
queryInterface
.
addColumn
({
...
...
lib/dialects/mysql/query-generator.js
View file @
e41590a
...
...
@@ -104,6 +104,7 @@ const QueryGenerator = {
tableName
:
table
,
foreignKey
:
key
});
return
`ALTER TABLE
${
this
.
quoteTable
(
table
)}
ADD
${
this
.
quoteIdentifier
(
key
)}
${
definition
}
;`
;
},
...
...
@@ -251,6 +252,9 @@ const QueryGenerator = {
template
+=
' PRIMARY KEY'
;
}
if
(
attribute
.
first
)
{
template
+=
' FIRST'
;
}
if
(
attribute
.
after
)
{
template
+=
' AFTER '
+
this
.
quoteIdentifier
(
attribute
.
after
);
}
...
...
test/unit/sql/add-column.test.js
View file @
e41590a
...
...
@@ -42,6 +42,14 @@ if (current.dialect.name === 'mysql') {
});
});
it
(
'properly generate alter queries with FIRST'
,
()
=>
{
return
expectsql
(
sql
.
addColumnQuery
(
Model
.
getTableName
(),
'test_added_col_first'
,
current
.
normalizeAttribute
({
type
:
DataTypes
.
STRING
,
first
:
true
})),
{
mysql
:
'ALTER TABLE `users` ADD `test_added_col_first` VARCHAR(255) FIRST;'
});
});
});
});
}
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