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 18dcc7ee
authored
May 16, 2020
by
Sushant
Committed by
GitHub
May 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(postgres): addColumn support ARRAY(ENUM) (#12259)
1 parent
461c9242
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
lib/dialects/postgres/query-generator.js
test/integration/query-interface.test.js
lib/dialects/postgres/query-generator.js
View file @
18dcc7e
...
@@ -244,17 +244,19 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
...
@@ -244,17 +244,19 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
return
super
.
handleSequelizeMethod
.
call
(
this
,
smth
,
tableName
,
factory
,
options
,
prepend
);
return
super
.
handleSequelizeMethod
.
call
(
this
,
smth
,
tableName
,
factory
,
options
,
prepend
);
}
}
addColumnQuery
(
table
,
key
,
dataTyp
e
)
{
addColumnQuery
(
table
,
key
,
attribut
e
)
{
const
dbDataType
=
this
.
attributeToSQL
(
attribute
,
{
context
:
'addColumn'
,
table
,
key
});
const
d
bDataType
=
this
.
attributeToSQL
(
dataType
,
{
context
:
'addColumn'
,
table
,
key
})
;
const
d
ataType
=
attribute
.
type
||
attribute
;
const
definition
=
this
.
dataTypeMapping
(
table
,
key
,
dbDataType
);
const
definition
=
this
.
dataTypeMapping
(
table
,
key
,
dbDataType
);
const
quotedKey
=
this
.
quoteIdentifier
(
key
);
const
quotedKey
=
this
.
quoteIdentifier
(
key
);
const
quotedTable
=
this
.
quoteTable
(
this
.
extractTableDetails
(
table
));
const
quotedTable
=
this
.
quoteTable
(
this
.
extractTableDetails
(
table
));
let
query
=
`ALTER TABLE
${
quotedTable
}
ADD COLUMN
${
quotedKey
}
${
definition
}
;`
;
let
query
=
`ALTER TABLE
${
quotedTable
}
ADD COLUMN
${
quotedKey
}
${
definition
}
;`
;
if
(
dataType
.
type
&&
dataType
.
type
instanceof
DataTypes
.
ENUM
||
dataType
instanceof
DataTypes
.
ENUM
)
{
if
(
dataType
instanceof
DataTypes
.
ENUM
)
{
query
=
this
.
pgEnum
(
table
,
key
,
dataType
)
+
query
;
query
=
this
.
pgEnum
(
table
,
key
,
dataType
)
+
query
;
}
else
if
(
dataType
.
type
&&
dataType
.
type
instanceof
DataTypes
.
ENUM
)
{
query
=
this
.
pgEnum
(
table
,
key
,
dataType
.
type
)
+
query
;
}
}
return
query
;
return
query
;
...
...
test/integration/query-interface.test.js
View file @
18dcc7e
...
@@ -380,6 +380,23 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
...
@@ -380,6 +380,23 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
values
:
[
'value1'
,
'value2'
,
'value3'
]
values
:
[
'value1'
,
'value2'
,
'value3'
]
});
});
});
});
if
(
dialect
===
'postgres'
)
{
it
(
'should be able to add a column of type of array of enums'
,
async
function
()
{
await
this
.
queryInterface
.
addColumn
(
'users'
,
'tags'
,
{
allowNull
:
false
,
type
:
Sequelize
.
ARRAY
(
Sequelize
.
ENUM
(
'Value1'
,
'Value2'
,
'Value3'
))
});
const
result
=
await
this
.
queryInterface
.
describeTable
(
'users'
);
expect
(
result
).
to
.
have
.
property
(
'tags'
);
expect
(
result
.
tags
.
type
).
to
.
equal
(
'ARRAY'
);
expect
(
result
.
tags
.
allowNull
).
to
.
be
.
false
;
});
}
});
});
describe
(
'describeForeignKeys'
,
()
=>
{
describe
(
'describeForeignKeys'
,
()
=>
{
...
...
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