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 9b87cb86
authored
Oct 10, 2018
by
Justin Kalland
Committed by
Sushant
Oct 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(query): handle undefined field on unique constraint error (#10016) (#10018)
1 parent
5db576a2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
5 deletions
lib/dialects/abstract/index.js
lib/dialects/abstract/query.js
lib/dialects/postgres/index.js
lib/dialects/sqlite/index.js
test/integration/model/create.test.js
lib/dialects/abstract/index.js
View file @
9b87cb8
...
@@ -56,7 +56,8 @@ AbstractDialect.prototype.supports = {
...
@@ -56,7 +56,8 @@ AbstractDialect.prototype.supports = {
parser
:
false
,
parser
:
false
,
concurrently
:
false
,
concurrently
:
false
,
type
:
false
,
type
:
false
,
using
:
true
using
:
true
,
functionBased
:
false
},
},
joinTableDependent
:
true
,
joinTableDependent
:
true
,
groupedLimit
:
true
,
groupedLimit
:
true
,
...
...
lib/dialects/abstract/query.js
View file @
9b87cb8
...
@@ -126,9 +126,9 @@ class AbstractQuery {
...
@@ -126,9 +126,9 @@ class AbstractQuery {
}
}
getUniqueConstraintErrorMessage
(
field
)
{
getUniqueConstraintErrorMessage
(
field
)
{
let
message
=
field
+
' m
ust be unique'
;
let
message
=
field
?
field
+
' must be unique'
:
'M
ust be unique'
;
if
(
this
.
model
)
{
if
(
field
&&
this
.
model
)
{
for
(
const
key
of
Object
.
keys
(
this
.
model
.
uniqueKeys
))
{
for
(
const
key
of
Object
.
keys
(
this
.
model
.
uniqueKeys
))
{
if
(
this
.
model
.
uniqueKeys
[
key
].
fields
.
indexOf
(
field
.
replace
(
/"/g
,
''
))
>=
0
)
{
if
(
this
.
model
.
uniqueKeys
[
key
].
fields
.
indexOf
(
field
.
replace
(
/"/g
,
''
))
>=
0
)
{
if
(
this
.
model
.
uniqueKeys
[
key
].
msg
)
{
if
(
this
.
model
.
uniqueKeys
[
key
].
msg
)
{
...
...
lib/dialects/postgres/index.js
View file @
9b87cb8
...
@@ -38,7 +38,8 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototy
...
@@ -38,7 +38,8 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototy
index
:
{
index
:
{
concurrently
:
true
,
concurrently
:
true
,
using
:
2
,
using
:
2
,
where
:
true
where
:
true
,
functionBased
:
true
},
},
inserts
:
{
inserts
:
{
onConflictDoNothing
:
' ON CONFLICT DO NOTHING'
onConflictDoNothing
:
' ON CONFLICT DO NOTHING'
...
...
lib/dialects/sqlite/index.js
View file @
9b87cb8
...
@@ -28,7 +28,8 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
...
@@ -28,7 +28,8 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
},
},
index
:
{
index
:
{
using
:
false
,
using
:
false
,
where
:
true
where
:
true
,
functionBased
:
true
},
},
transactionOptions
:
{
transactionOptions
:
{
type
:
true
type
:
true
...
...
test/integration/model/create.test.js
View file @
9b87cb8
...
@@ -998,6 +998,26 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -998,6 +998,26 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
if
(
current
.
dialect
.
supports
.
index
.
functionBased
)
{
it
(
"doesn't allow duplicated records with unique function based indexes"
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'UserWithUniqueUsernameFunctionIndex'
,
{
username
:
Sequelize
.
STRING
,
email
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
}
});
return
User
.
sync
({
force
:
true
}).
then
(()
=>
{
const
tableName
=
User
.
getTableName
();
return
this
.
sequelize
.
query
(
'CREATE UNIQUE INDEX lower_case_username ON "'
+
tableName
+
'" ((lower(username)))'
);
}).
then
(()
=>
{
return
User
.
create
({
username
:
'foo'
});
}).
then
(()
=>
{
return
User
.
create
({
username
:
'foo'
});
}).
catch
(
Sequelize
.
UniqueConstraintError
,
err
=>
{
expect
(
err
).
to
.
be
.
ok
;
});
});
}
it
(
'raises an error if created object breaks definition contraints'
,
function
()
{
it
(
'raises an error if created object breaks definition contraints'
,
function
()
{
const
UserNull
=
this
.
sequelize
.
define
(
'UserWithNonNullSmth'
,
{
const
UserNull
=
this
.
sequelize
.
define
(
'UserWithNonNullSmth'
,
{
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
username
:
{
type
:
Sequelize
.
STRING
,
unique
:
true
},
...
...
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