Cannot use final insert for migrations that create a new table
mbyczkowski opened this issue · comments
Mat Byczkowski commented
It seems that Shift tries to validate the migration and fails, because a table doesn't exist, but it would have existed after the DDL statement execution.
It would be nice if Shift could recognize this and appropriately validate the input.
Error I saw:
Error message: migration: invalid final insert statement: Error 1146: Table 'some_app_staging.ar_internal_metadata' doesn't exist.
My DDL statement:
CREATE TABLE
`ar_internal_metadata` (
`key` VARCHAR (255) CHARACTER
SET
utf8 COLLATE utf8_unicode_ci NOT NULL
,`value` VARCHAR (255) COLLATE utf8mb4_unicode_ci DEFAULT NULL
,`created_at` datetime NOT NULL
,`updated_at` datetime NOT NULL
,PRIMARY KEY (`key`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
My final insert:
INSERT INTO `ar_internal_metadata` (`key`, `value`, `created_at`, `updated_at`)
VALUES ('environment', 'staging', NOW(), NOW())
Michael Finch commented
That makes sense. The final insert was intended to be used to insert records into something like a schema_migrations table after a migration is run, but I agree that there's no reason shift shouldn't allow performing a final insert on a table that is created in the same migration.