@@ -302,6 +302,10 @@ private function createTablesForCreateMigrationForDropTable132()
302
302
Yii::$ app ->db ->createCommand ()->createTable ('{{%ubigpks}} ' , [
303
303
'id ' => 'ubigpk ' ,
304
304
'name ' => 'string(150) ' ,
305
+ 'size ' => "ENUM('x-small', 'small', 'medium', 'large', 'x-large') NOT NULL DEFAULT 'x-small' " ,
306
+ 'd SMALLINT UNSIGNED ZEROFILL ' ,
307
+ 'e ' => 'SMALLINT UNSIGNED ZEROFILL ' ,
308
+ 'f ' => 'decimal(12,4) ' ,
305
309
])->execute ();
306
310
307
311
// ---
@@ -347,6 +351,83 @@ private function deleteTablesForCreateMigrationForDropTable132()
347
351
Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%the_animal_table_name}} ' )->execute ();
348
352
}
349
353
354
+ // Create migration for drop table if a entire schema is deleted from OpenAPI spec #132
355
+ // https://github.com/cebe/yii2-openapi/issues/132
356
+ // For PgSQL
357
+ public function testCreateMigrationForDropTable132ForPgsql ()
358
+ {
359
+ $ this ->changeDbToPgsql ();
360
+ $ testFile = Yii::getAlias ("@specs/issue_fix/132_create_migration_for_drop_table/132_create_migration_for_drop_table.php " );
361
+ $ this ->createTablesForCreateMigrationForDropTable132ForPgsql ();
362
+ $ this ->runGenerator ($ testFile , 'pgsql ' );
363
+ $ this ->runActualMigrations ('pgsql ' , 8 );
364
+ // ... TODO compare files
365
+ $ this ->deleteTablesForCreateMigrationForDropTable132ForPgsql ();
366
+ $ this ->deleteTables ();
367
+ }
368
+
369
+ private function createTablesForCreateMigrationForDropTable132ForPgsql ()
370
+ {
371
+ Yii::$ app ->db ->createCommand ()->createTable ('{{%upks}} ' , [
372
+ 'id ' => 'upk ' ,
373
+ 'name ' => 'string(150) ' ,
374
+ ])->execute ();
375
+ Yii::$ app ->db ->createCommand ()->createTable ('{{%bigpks}} ' , [
376
+ 'id ' => 'bigpk ' ,
377
+ 'name ' => 'string(150) ' ,
378
+ ])->execute ();
379
+ Yii::$ app ->db ->createCommand ()->createTable ('{{%ubigpks}} ' , [
380
+ 'id ' => 'ubigpk ' ,
381
+ 'name ' => 'string(150) ' ,
382
+ // 'size' => "ENUM('x-small', 'small', 'medium', 'large', 'x-large') NOT NULL DEFAULT 'x-small'",
383
+ // 'd SMALLINT UNSIGNED ZEROFILL',
384
+ // 'e' => 'SMALLINT UNSIGNED ZEROFILL',
385
+ // 'f' => 'decimal(12,4)',
386
+ ])->execute ();
387
+
388
+ // ---
389
+ Yii::$ app ->db ->createCommand ()->createTable ('{{%fruits}} ' , [
390
+ 'id ' => 'pk ' ,
391
+ 'name ' => 'string(150) ' ,
392
+ 'food_of ' => 'int '
393
+ ])->execute ();
394
+ Yii::$ app ->db ->createCommand ()->createTable ('{{%pristines}} ' , [
395
+ 'id ' => 'pk ' ,
396
+ 'name ' => 'string(151) ' ,
397
+ 'fruit_id ' => 'int ' , // FK
398
+ ])->execute ();
399
+ Yii::$ app ->db ->createCommand ()->addForeignKey ('name ' , '{{%pristines}} ' , 'fruit_id ' , '{{%fruits}} ' , 'id ' )->execute ();
400
+
401
+ // ---
402
+ Yii::$ app ->db ->createCommand ()->createTable ('{{%the_animal_table_name}} ' , [
403
+ 'id ' => 'pk ' ,
404
+ 'name ' => 'string(150) ' ,
405
+ ])->execute ();
406
+ Yii::$ app ->db ->createCommand ()->addForeignKey ('name2 ' , '{{%fruits}} ' , 'food_of ' , '{{%the_animal_table_name}} ' , 'id ' )->execute ();
407
+ Yii::$ app ->db ->createCommand ()->createTable ('{{%the_mango_table_name}} ' , [
408
+ 'id ' => 'pk ' ,
409
+ 'name ' => 'string(150) ' ,
410
+ 'food_of ' => 'int '
411
+ ])->execute ();
412
+ Yii::$ app ->db ->createCommand ()->addForeignKey ('animal_fruit_fk ' , '{{%the_mango_table_name}} ' , 'food_of ' , '{{%the_animal_table_name}} ' , 'id ' )->execute ();
413
+ }
414
+
415
+ private function deleteTablesForCreateMigrationForDropTable132ForPgsql ()
416
+ {
417
+ Yii::$ app ->db ->createCommand ()->dropForeignKey ('name ' , '{{%pristines}} ' )->execute ();
418
+ Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%pristines}} ' )->execute ();
419
+ Yii::$ app ->db ->createCommand ()->dropForeignKey ('name2 ' , '{{%fruits}} ' )->execute ();
420
+ Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%fruits}} ' )->execute ();
421
+
422
+ Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%upks}} ' )->execute ();
423
+ Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%bigpks}} ' )->execute ();
424
+ Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%ubigpks}} ' )->execute ();
425
+
426
+ Yii::$ app ->db ->createCommand ()->dropForeignKey ('animal_fruit_fk ' , '{{%the_mango_table_name}} ' )->execute ();
427
+ Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%the_mango_table_name}} ' )->execute ();
428
+ Yii::$ app ->db ->createCommand ('DROP TABLE IF EXISTS {{%the_animal_table_name}} ' )->execute ();
429
+ }
430
+
350
431
public function test162BugDollarrefWithXFaker ()
351
432
{
352
433
$ testFile = Yii::getAlias ("@specs/issue_fix/162_bug_dollarref_with_x_faker/162_bug_dollarref_with_x_faker.php " );
0 commit comments