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 091abb48
authored
Feb 11, 2018
by
Sushant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: alter:true create duplicate index
1 parent
0abea9f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
1 deletions
lib/model.js
test/integration/model/sync.test.js
lib/model.js
View file @
091abb4
...
@@ -1179,7 +1179,7 @@ class Model {
...
@@ -1179,7 +1179,7 @@ class Model {
})
})
.
then
(()
=>
this
.
QueryInterface
.
showIndex
(
this
.
getTableName
(
options
),
options
))
.
then
(()
=>
this
.
QueryInterface
.
showIndex
(
this
.
getTableName
(
options
),
options
))
.
then
(
indexes
=>
{
.
then
(
indexes
=>
{
// Assign an auto-generated name to indexes which are not named by the user
// Assign an auto-generated name to indexes which are not named by the user
this
.
options
.
indexes
=
this
.
QueryInterface
.
nameIndexes
(
this
.
options
.
indexes
,
this
.
tableName
);
this
.
options
.
indexes
=
this
.
QueryInterface
.
nameIndexes
(
this
.
options
.
indexes
,
this
.
tableName
);
indexes
=
_
.
filter
(
this
.
options
.
indexes
,
item1
=>
indexes
=
_
.
filter
(
this
.
options
.
indexes
,
item1
=>
...
...
test/integration/model/sync.test.js
View file @
091abb4
...
@@ -130,6 +130,85 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -130,6 +130,85 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
describe
(
'indexes'
,
()
=>
{
describe
(
'indexes'
,
()
=>
{
describe
(
'with alter:true'
,
()
=>
{
it
(
'should not duplicate named indexes after multiple sync calls'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'testSync'
,
{
email
:
{
type
:
Sequelize
.
STRING
},
phone
:
{
type
:
Sequelize
.
STRING
},
mobile
:
{
type
:
Sequelize
.
STRING
}
},
{
indexes
:
[
{
name
:
'another_index_email_mobile'
,
fields
:
[
'email'
,
'mobile'
]
},
{
name
:
'another_index_phone_mobile'
,
fields
:
[
'phone'
,
'mobile'
],
unique
:
true
},
{
name
:
'another_index_email'
,
fields
:
[
'email'
]
},
{
name
:
'another_index_mobile'
,
fields
:
[
'mobile'
]
},
]
});
return
User
.
sync
({
sync
:
true
})
.
then
(()
=>
User
.
sync
({
alter
:
true
}))
.
then
(()
=>
User
.
sync
({
alter
:
true
}))
.
then
(()
=>
User
.
sync
({
alter
:
true
}))
.
then
(()
=>
this
.
sequelize
.
getQueryInterface
().
showIndex
(
User
.
getTableName
()))
.
then
(
results
=>
{
if
(
dialect
===
'sqlite'
)
{
// SQLite doesn't treat primary key as index
expect
(
results
).
to
.
have
.
length
(
4
);
}
else
{
expect
(
results
).
to
.
have
.
length
(
4
+
1
);
expect
(
results
.
filter
(
r
=>
r
.
primary
)).
to
.
have
.
length
(
1
);
}
expect
(
results
.
filter
(
r
=>
r
.
name
===
'another_index_email_mobile'
)).
to
.
have
.
length
(
1
);
expect
(
results
.
filter
(
r
=>
r
.
name
===
'another_index_phone_mobile'
)).
to
.
have
.
length
(
1
);
expect
(
results
.
filter
(
r
=>
r
.
name
===
'another_index_email'
)).
to
.
have
.
length
(
1
);
expect
(
results
.
filter
(
r
=>
r
.
name
===
'another_index_mobile'
)).
to
.
have
.
length
(
1
);
});
});
it
(
'should not duplicate unnamed indexes after multiple sync calls'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'testSync'
,
{
email
:
{
type
:
Sequelize
.
STRING
},
phone
:
{
type
:
Sequelize
.
STRING
},
mobile
:
{
type
:
Sequelize
.
STRING
}
},
{
indexes
:
[
{
fields
:
[
'email'
,
'mobile'
]
},
{
fields
:
[
'phone'
,
'mobile'
],
unique
:
true
},
{
fields
:
[
'email'
]
},
{
fields
:
[
'mobile'
]
},
]
});
return
User
.
sync
({
sync
:
true
})
.
then
(()
=>
User
.
sync
({
alter
:
true
}))
.
then
(()
=>
User
.
sync
({
alter
:
true
}))
.
then
(()
=>
User
.
sync
({
alter
:
true
}))
.
then
(()
=>
this
.
sequelize
.
getQueryInterface
().
showIndex
(
User
.
getTableName
()))
.
then
(
results
=>
{
if
(
dialect
===
'sqlite'
)
{
// SQLite doesn't treat primary key as index
expect
(
results
).
to
.
have
.
length
(
4
);
}
else
{
expect
(
results
).
to
.
have
.
length
(
4
+
1
);
expect
(
results
.
filter
(
r
=>
r
.
primary
)).
to
.
have
.
length
(
1
);
}
});
});
});
it
(
'should create only one unique index for unique:true column'
,
function
()
{
it
(
'should create only one unique index for unique:true column'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'testSync'
,
{
const
User
=
this
.
sequelize
.
define
(
'testSync'
,
{
email
:
{
email
:
{
...
...
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