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 c933bed7
authored
Oct 14, 2017
by
Sushant
Committed by
GitHub
Oct 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(postgres/createSchema): support for create schema if not exists w… (#8484)
1 parent
88622127
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
12 deletions
lib/dialects/postgres/query-generator.js
test/integration/dialects/postgres/query-interface.test.js
test/integration/model/searchPath.test.js
test/unit/sql/create-schema.test.js
lib/dialects/postgres/query-generator.js
View file @
c933bed
...
...
@@ -17,6 +17,12 @@ const QueryGenerator = {
},
createSchema
(
schema
)
{
const
databaseVersion
=
_
.
get
(
this
,
'sequelize.options.databaseVersion'
,
0
);
if
(
databaseVersion
&&
semver
.
gte
(
databaseVersion
,
'9.2.0'
))
{
return
`CREATE SCHEMA IF NOT EXISTS
${
schema
}
;`
;
}
return
`CREATE SCHEMA
${
schema
}
;`
;
},
...
...
test/integration/dialects/postgres/query-interface.test.js
View file @
c933bed
...
...
@@ -34,10 +34,17 @@ if (dialect.match(/^postgres/)) {
});
});
it
(
'
errors if the
schema exists'
,
function
()
{
it
(
'
works even when
schema exists'
,
function
()
{
return
this
.
queryInterface
.
createSchema
(
'testschema'
)
.
catch
(
err
=>
{
expect
(
err
.
message
).
to
.
be
.
equal
(
'schema "testschema" already exists'
);
.
then
(()
=>
this
.
queryInterface
.
createSchema
(
'testschema'
))
.
then
(()
=>
this
.
sequelize
.
query
(
`
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name = 'testschema';
`
,
{
type
:
this
.
sequelize
.
QueryTypes
.
SELECT
}))
.
then
(
res
=>
{
expect
(
res
,
'query results'
).
to
.
not
.
be
.
empty
;
expect
(
res
[
0
].
schema_name
).
to
.
be
.
equal
(
'testschema'
);
});
});
});
...
...
test/integration/model/searchPath.test.js
View file @
c933bed
'use strict'
;
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
Support
=
require
(
__dirname
+
'/../support'
),
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
);
const
chai
=
require
(
'chai'
);
const
expect
=
chai
.
expect
;
const
Support
=
require
(
__dirname
+
'/../support'
);
const
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
);
const
SEARCH_PATH_ONE
=
'schema_one,public'
;
const
SEARCH_PATH_TWO
=
'schema_two,public'
;
...
...
test/unit/sql/create-schema.test.js
View file @
c933bed
'use strict'
;
const
Support
=
require
(
__dirname
+
'/../support'
),
expectsql
=
Support
.
expectsql
,
current
=
Support
.
sequelize
,
sql
=
current
.
dialect
.
QueryGenerator
;
const
Support
=
require
(
__dirname
+
'/../support'
);
const
expectsql
=
Support
.
expectsql
;
const
current
=
Support
.
sequelize
;
const
sql
=
current
.
dialect
.
QueryGenerator
;
describe
(
Support
.
getTestDialectTeaser
(
'SQL'
),
()
=>
{
if
(
current
.
dialect
.
name
===
'postgres'
)
{
describe
(
'dropSchema'
,
()
=>
{
tes
t
(
'IF EXISTS'
,
()
=>
{
i
t
(
'IF EXISTS'
,
()
=>
{
expectsql
(
sql
.
dropSchema
(
'foo'
),
{
postgres
:
'DROP SCHEMA IF EXISTS foo CASCADE;'
});
});
});
describe
(
'createSchema'
,
()
=>
{
before
(
function
()
{
this
.
version
=
current
.
options
.
databaseVersion
;
});
after
(
function
()
{
current
.
options
.
databaseVersion
=
this
.
version
;
});
it
(
'9.2.0 or above'
,
()
=>
{
current
.
options
.
databaseVersion
=
'9.2.0'
;
expectsql
(
sql
.
createSchema
(
'foo'
),
{
postgres
:
'CREATE SCHEMA IF NOT EXISTS foo;'
});
});
it
(
'below 9.2.0'
,
()
=>
{
current
.
options
.
databaseVersion
=
'9.0.0'
;
expectsql
(
sql
.
createSchema
(
'foo'
),
{
postgres
:
'CREATE SCHEMA foo;'
});
});
});
}
});
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