File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -276,7 +276,11 @@ BEGIN
276
276
RETURN;
277
277
END IF;
278
278
279
- IF tg_event = 'sql_drop' and tg_tag != 'ALTER TABLE' THEN
279
+ IF tg_event = 'sql_drop' AND tg_tag = 'DROP SCHEMA' THEN
280
+ -- Take the schema name from the drop schema command
281
+ SELECT object_identity INTO schemaname FROM pg_event_trigger_dropped_objects();
282
+
283
+ ELSIF tg_event = 'sql_drop' and tg_tag != 'ALTER TABLE' THEN
280
284
-- Guess the schema from drop commands
281
285
SELECT schema_name INTO schemaname FROM pg_catalog.pg_event_trigger_dropped_objects() WHERE schema_name IS NOT NULL;
282
286
@@ -286,7 +290,11 @@ BEGIN
286
290
RETURN;
287
291
END IF;
288
292
289
- SELECT schema_name INTO schemaname FROM pg_catalog.pg_event_trigger_ddl_commands() WHERE schema_name IS NOT NULL;
293
+ IF tg_tag = 'CREATE SCHEMA' THEN
294
+ SELECT object_identity INTO schemaname FROM pg_event_trigger_ddl_commands();
295
+ ELSE
296
+ SELECT schema_name INTO schemaname FROM pg_catalog.pg_event_trigger_ddl_commands() WHERE schema_name IS NOT NULL;
297
+ END IF;
290
298
END IF;
291
299
292
300
IF schemaname IS NULL THEN
Original file line number Diff line number Diff line change @@ -197,6 +197,25 @@ func TestInferredMigration(t *testing.T) {
197
197
},
198
198
},
199
199
},
200
+ {
201
+ name : "create/drop schema" ,
202
+ sqlStmts : []string {
203
+ "CREATE SCHEMA foo" ,
204
+ "DROP SCHEMA foo" ,
205
+ },
206
+ wantMigrations : []migrations.Migration {
207
+ {
208
+ Operations : migrations.Operations {
209
+ & migrations.OpRawSQL {Up : "CREATE SCHEMA foo" },
210
+ },
211
+ },
212
+ {
213
+ Operations : migrations.Operations {
214
+ & migrations.OpRawSQL {Up : "DROP SCHEMA foo" },
215
+ },
216
+ },
217
+ },
218
+ },
200
219
}
201
220
202
221
for _ , tt := range tests {
You can’t perform that action at this time.
0 commit comments