File tree 2 files changed +27
-30
lines changed
2 files changed +27
-30
lines changed Original file line number Diff line number Diff line change @@ -96,32 +96,10 @@ var PgDriver = Base.extend({
96
96
options = { } ;
97
97
}
98
98
99
- if ( options . ifNotExists ) {
100
- this . runSql (
101
- `
102
- DO
103
- $do$
104
- DECLARE
105
- _db TEXT := '${ dbName } ';
106
- BEGIN
107
- CREATE EXTENSION IF NOT EXISTS dblink;
108
- IF EXISTS (SELECT 1 FROM pg_database WHERE datname = _db) THEN
109
- RAISE NOTICE 'Database "%" already exists, skipping creation.', _db;
110
- ELSE
111
- PERFORM dblink_connect('dbname=' || current_database());
112
- PERFORM dblink_exec('CREATE DATABASE ' || _db || ' ${ spec } ');
113
- END IF;
114
- END
115
- $do$
116
- ` ,
117
- callback
118
- ) ;
119
- } else {
120
- this . runSql (
121
- util . format ( 'CREATE DATABASE %s %s' , this . escapeDDL ( dbName ) , spec ) ,
122
- callback
123
- ) ;
124
- }
99
+ this . runSql (
100
+ util . format ( 'CREATE DATABASE %s %s' , this . escapeDDL ( dbName ) , spec ) ,
101
+ callback
102
+ ) ;
125
103
} ,
126
104
127
105
dropDatabase : function ( dbName , options , callback ) {
@@ -253,8 +231,9 @@ var PgDriver = Base.extend({
253
231
var searchPathes = result [ 0 ] . search_path . split ( ',' ) ;
254
232
255
233
for ( var i = 0 ; i < searchPathes . length ; ++ i ) {
234
+ searchPathes [ i ] = searchPathes [ i ] . trim ( ) ;
256
235
if ( searchPathes [ i ] . indexOf ( '"' ) !== 0 ) {
257
- searchPathes [ i ] = '"' + searchPathes [ i ] . trim ( ) + '"' ;
236
+ searchPathes [ i ] = '"' + searchPathes [ i ] + '"' ;
258
237
}
259
238
}
260
239
Original file line number Diff line number Diff line change @@ -940,14 +940,32 @@ lab.experiment('pg', () => {
940
940
let rows ;
941
941
942
942
lab . before ( async ( ) => {
943
- await db . createDatabase ( 'test' ) ;
943
+ await db . createDatabase ( 'test2' ) ;
944
+ } ) ;
945
+
946
+ // this seems to not work currently, the code was temporarily removed
947
+ lab . test . skip ( 'create already existing db with ifNotExist flag' , async ( ) => {
948
+ await db . createDatabase ( 'test2' , { ifNotExists : true } ) ;
949
+ } ) ;
950
+
951
+ lab . after ( ( ) => db . dropDatabase ( 'test2' ) ) ;
952
+ } ) ;
953
+
954
+ lab . experiment ( 'searchPath' , ( ) => {
955
+ let rows ;
956
+
957
+ lab . before ( async ( ) => {
958
+ await db . runSql ( 'SET search_path TO "$user",public,"something-with-quotes";' ) ;
944
959
} ) ;
945
960
946
961
lab . test ( 'create already existing db with ifNotExist flag' , async ( ) => {
947
- await db . createDatabase ( 'test' , { ifNotExists : true } ) ;
962
+ await db . createMigrationsTable ( ) ;
948
963
} ) ;
949
964
950
- lab . after ( ( ) => db . dropDatabase ( 'test' ) ) ;
965
+ lab . after ( async ( ) => {
966
+ await db . dropTable ( 'migrations' ) ;
967
+ await db . switchDatabase ( { schema : config . schema } ) ;
968
+ } ) ;
951
969
} ) ;
952
970
953
971
lab . after ( ( ) => db . close ( ) ) ;
You can’t perform that action at this time.
0 commit comments