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 946fb729
authored
Nov 18, 2018
by
Sushant
Committed by
GitHub
Nov 18, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(sync): throw when no models defined (#10175)
1 parent
6b1ff3b1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
15 deletions
lib/sequelize.js
test/integration/sequelize.test.js
lib/sequelize.js
View file @
946fb72
...
@@ -733,6 +733,9 @@ class Sequelize {
...
@@ -733,6 +733,9 @@ class Sequelize {
}
}
});
});
// no models defined, just authenticate
if
(
!
models
.
length
)
return
this
.
authenticate
(
options
);
return
Promise
.
each
(
models
,
model
=>
model
.
sync
(
options
));
return
Promise
.
each
(
models
,
model
=>
model
.
sync
(
options
));
}).
then
(()
=>
{
}).
then
(()
=>
{
if
(
options
.
hooks
)
{
if
(
options
.
hooks
)
{
...
...
test/integration/sequelize.test.js
View file @
946fb72
...
@@ -965,12 +965,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
...
@@ -965,12 +965,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
});
});
if
(
dialect
!==
'sqlite'
)
{
if
(
dialect
!==
'sqlite'
)
{
it
(
'fails for incorrect connection even when no models are defined'
,
function
()
{
const
sequelize
=
new
Sequelize
(
'cyber_bird'
,
'user'
,
'pass'
,
{
dialect
:
this
.
sequelize
.
options
.
dialect
});
return
expect
(
sequelize
.
sync
({
force
:
true
})).
to
.
be
.
rejected
;
});
it
(
'fails with incorrect database credentials (1)'
,
function
()
{
it
(
'fails with incorrect database credentials (1)'
,
function
()
{
this
.
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'omg'
,
'bar'
,
null
,
_
.
omit
(
this
.
sequelize
.
options
,
[
'host'
]));
this
.
sequelizeWithInvalidCredentials
=
new
Sequelize
(
'omg'
,
'bar'
,
null
,
_
.
omit
(
this
.
sequelize
.
options
,
[
'host'
]));
const
User2
=
this
.
sequelizeWithInvalidCredentials
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
,
bio
:
DataTypes
.
TEXT
});
const
User2
=
this
.
sequelizeWithInvalidCredentials
.
define
(
'User'
,
{
name
:
DataTypes
.
STRING
,
bio
:
DataTypes
.
TEXT
});
return
User2
.
sync
().
catch
(
err
=>
{
return
User2
.
sync
()
.
then
(()
=>
{
expect
.
fail
();
})
.
catch
(
err
=>
{
if
(
dialect
===
'postgres'
||
dialect
===
'postgres-native'
)
{
if
(
dialect
===
'postgres'
||
dialect
===
'postgres-native'
)
{
assert
([
assert
([
'fe_sendauth: no password supplied'
,
'fe_sendauth: no password supplied'
,
...
@@ -994,9 +1004,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
...
@@ -994,9 +1004,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
sequelize
.
define
(
'Project'
,
{
title
:
Sequelize
.
STRING
});
sequelize
.
define
(
'Project'
,
{
title
:
Sequelize
.
STRING
});
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
});
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
});
return
sequelize
.
sync
({
force
:
true
}).
catch
(
err
=>
{
return
expect
(
sequelize
.
sync
({
force
:
true
})).
to
.
be
.
rejected
;
expect
(
err
).
to
.
be
.
ok
;
});
});
});
it
(
'fails with incorrect database credentials (3)'
,
function
()
{
it
(
'fails with incorrect database credentials (3)'
,
function
()
{
...
@@ -1008,9 +1016,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
...
@@ -1008,9 +1016,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
sequelize
.
define
(
'Project'
,
{
title
:
Sequelize
.
STRING
});
sequelize
.
define
(
'Project'
,
{
title
:
Sequelize
.
STRING
});
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
});
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
});
return
sequelize
.
sync
({
force
:
true
}).
catch
(
err
=>
{
return
expect
(
sequelize
.
sync
({
force
:
true
})).
to
.
be
.
rejected
;
expect
(
err
).
to
.
be
.
ok
;
});
});
});
it
(
'fails with incorrect database credentials (4)'
,
function
()
{
it
(
'fails with incorrect database credentials (4)'
,
function
()
{
...
@@ -1023,19 +1029,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
...
@@ -1023,19 +1029,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
sequelize
.
define
(
'Project'
,
{
title
:
Sequelize
.
STRING
});
sequelize
.
define
(
'Project'
,
{
title
:
Sequelize
.
STRING
});
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
});
sequelize
.
define
(
'Task'
,
{
title
:
Sequelize
.
STRING
});
return
sequelize
.
sync
({
force
:
true
}).
catch
(
err
=>
{
return
expect
(
sequelize
.
sync
({
force
:
true
})).
to
.
be
.
rejected
;
expect
(
err
).
to
.
be
.
ok
;
});
});
});
it
(
'returns an error correctly if unable to sync a foreign key referenced model'
,
function
()
{
it
(
'returns an error correctly if unable to sync a foreign key referenced model'
,
function
()
{
this
.
sequelize
.
define
(
'Application'
,
{
this
.
sequelize
.
define
(
'Application'
,
{
authorID
:
{
type
:
Sequelize
.
BIGINT
,
allowNull
:
false
,
references
:
{
model
:
'User'
,
key
:
'id'
}
}
authorID
:
{
type
:
Sequelize
.
BIGINT
,
allowNull
:
false
,
references
:
{
model
:
'User'
,
key
:
'id'
}
}
});
});
return
this
.
sequelize
.
sync
().
catch
(
error
=>
{
return
expect
(
this
.
sequelize
.
sync
()).
to
.
be
.
rejected
;
assert
.
ok
(
error
);
});
});
});
it
(
'handles this dependant foreign key constraints'
,
function
()
{
it
(
'handles this dependant foreign key constraints'
,
function
()
{
...
@@ -1065,6 +1074,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
...
@@ -1065,6 +1074,7 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
return
this
.
sequelize
.
sync
();
return
this
.
sequelize
.
sync
();
});
});
}
it
(
'return the sequelize instance after syncing'
,
function
()
{
it
(
'return the sequelize instance after syncing'
,
function
()
{
return
this
.
sequelize
.
sync
().
then
(
sequelize
=>
{
return
this
.
sequelize
.
sync
().
then
(
sequelize
=>
{
...
@@ -1086,7 +1096,6 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
...
@@ -1086,7 +1096,6 @@ describe(Support.getTestDialectTeaser('Sequelize'), () => {
expect
(
result
).
to
.
deep
.
equal
(
block
);
expect
(
result
).
to
.
deep
.
equal
(
block
);
});
});
});
});
}
describe
(
"doesn't emit logging when explicitly saying not to"
,
()
=>
{
describe
(
"doesn't emit logging when explicitly saying not to"
,
()
=>
{
afterEach
(
function
()
{
afterEach
(
function
()
{
...
...
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