Skip to content

Commit c7d0c4b

Browse files
authored
fix: ORM-1247 fix consistency issues across envs in created migration output (#5545)
Had to change the name of the model in this case to ensure that consistent sql is produced between different environments. In particular under mysqls `lower_case_table_names = 1` setting (which is the default under windows but not linux) the casing of the table name in the `ALTER TABLE` statements would otherwise change between linux and windows based tests.
1 parent f44e5b3 commit c7d0c4b

1 file changed

Lines changed: 35 additions & 35 deletions

File tree

schema-engine/sql-migration-tests/tests/migrations/schema_filter.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn schema_filter_migration_adding_external_tables_incl_relations(api: TestApi) {
237237
fn schema_filter_migration_removing_external_tables_incl_relations(mut api: TestApi) {
238238
let schema_1 = api.datamodel_with_provider(
239239
r#"
240-
model Cat {
240+
model cat {
241241
id Int @id
242242
name String
243243
@@ -250,13 +250,13 @@ fn schema_filter_migration_removing_external_tables_incl_relations(mut api: Test
250250
model ExternalTableA {
251251
id Int @id
252252
name String
253-
cats Cat[]
253+
cats cat[]
254254
}
255255
256256
model ExternalTableB {
257257
id Int @id
258258
name String
259-
cat Cat? @relation(fields: [catId], references: [id])
259+
cat cat? @relation(fields: [catId], references: [id])
260260
catId Int?
261261
}
262262
"#,
@@ -274,7 +274,7 @@ fn schema_filter_migration_removing_external_tables_incl_relations(mut api: Test
274274

275275
let schema_2 = api.datamodel_with_provider(
276276
r#"
277-
model Cat {
277+
model cat {
278278
id Int @id
279279
name String
280280
}
@@ -294,50 +294,50 @@ fn schema_filter_migration_removing_external_tables_incl_relations(mut api: Test
294294
/*
295295
Warnings:
296296
297-
- You are about to drop the column `externalTableId` on the `Cat` table. All the data in the column will be lost.
297+
- You are about to drop the column `externalTableId` on the `cat` table. All the data in the column will be lost.
298298
299299
*/
300300
-- DropForeignKey
301-
ALTER TABLE "Cat" DROP CONSTRAINT "Cat_externalTableId_fkey";
301+
ALTER TABLE "cat" DROP CONSTRAINT "cat_externalTableId_fkey";
302302
303303
-- AlterTable
304-
ALTER TABLE "Cat" DROP COLUMN "externalTableId";
304+
ALTER TABLE "cat" DROP COLUMN "externalTableId";
305305
"#]]
306306
} else if is_mysql {
307307
expect![[r#"
308308
/*
309309
Warnings:
310310
311-
- You are about to drop the column `externalTableId` on the `Cat` table. All the data in the column will be lost.
311+
- You are about to drop the column `externalTableId` on the `cat` table. All the data in the column will be lost.
312312
313313
*/
314314
-- DropForeignKey
315-
ALTER TABLE `Cat` DROP FOREIGN KEY `Cat_externalTableId_fkey`;
315+
ALTER TABLE `cat` DROP FOREIGN KEY `cat_externalTableId_fkey`;
316316
317317
-- DropIndex
318-
DROP INDEX `Cat_externalTableId_fkey` ON `Cat`;
318+
DROP INDEX `cat_externalTableId_fkey` ON `cat`;
319319
320320
-- AlterTable
321-
ALTER TABLE `Cat` DROP COLUMN `externalTableId`;
321+
ALTER TABLE `cat` DROP COLUMN `externalTableId`;
322322
"#]]
323323
} else if is_sqlite {
324324
expect![[r#"
325325
/*
326326
Warnings:
327327
328-
- You are about to drop the column `externalTableId` on the `Cat` table. All the data in the column will be lost.
328+
- You are about to drop the column `externalTableId` on the `cat` table. All the data in the column will be lost.
329329
330330
*/
331331
-- RedefineTables
332332
PRAGMA defer_foreign_keys=ON;
333333
PRAGMA foreign_keys=OFF;
334-
CREATE TABLE "new_Cat" (
334+
CREATE TABLE "new_cat" (
335335
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
336336
"name" TEXT NOT NULL
337337
);
338-
INSERT INTO "new_Cat" ("id", "name") SELECT "id", "name" FROM "Cat";
339-
DROP TABLE "Cat";
340-
ALTER TABLE "new_Cat" RENAME TO "Cat";
338+
INSERT INTO "new_cat" ("id", "name") SELECT "id", "name" FROM "cat";
339+
DROP TABLE "cat";
340+
ALTER TABLE "new_cat" RENAME TO "cat";
341341
PRAGMA foreign_keys=ON;
342342
PRAGMA defer_foreign_keys=OFF;
343343
"#]]
@@ -346,18 +346,18 @@ fn schema_filter_migration_removing_external_tables_incl_relations(mut api: Test
346346
/*
347347
Warnings:
348348
349-
- You are about to drop the column `externalTableId` on the `Cat` table. All the data in the column will be lost.
349+
- You are about to drop the column `externalTableId` on the `cat` table. All the data in the column will be lost.
350350
351351
*/
352352
BEGIN TRY
353353
354354
BEGIN TRAN;
355355
356356
-- DropForeignKey
357-
ALTER TABLE [dbo].[Cat] DROP CONSTRAINT [Cat_externalTableId_fkey];
357+
ALTER TABLE [dbo].[cat] DROP CONSTRAINT [cat_externalTableId_fkey];
358358
359359
-- AlterTable
360-
ALTER TABLE [dbo].[Cat] DROP COLUMN [externalTableId];
360+
ALTER TABLE [dbo].[cat] DROP COLUMN [externalTableId];
361361
362362
COMMIT TRAN;
363363
@@ -379,11 +379,11 @@ fn schema_filter_migration_removing_external_tables_incl_relations(mut api: Test
379379
});
380380
}
381381

382-
#[test_connector(exclude(CockroachDb))]
382+
#[test_connector(exclude(CockroachDb, Vitess))]
383383
fn schema_filter_migration_modifying_external_tables_incl_relations(mut api: TestApi) {
384384
let schema_1 = api.datamodel_with_provider(
385385
r#"
386-
model Cat {
386+
model cat {
387387
id Int @id
388388
name String
389389
}
@@ -410,7 +410,7 @@ fn schema_filter_migration_modifying_external_tables_incl_relations(mut api: Tes
410410

411411
let schema_2 = api.datamodel_with_provider(
412412
r#"
413-
model Cat {
413+
model cat {
414414
id Int @id
415415
name String
416416
externalTablesB ExternalTableB[]
@@ -422,13 +422,13 @@ fn schema_filter_migration_modifying_external_tables_incl_relations(mut api: Tes
422422
model ExternalTableA {
423423
id Int @id
424424
name String
425-
cats Cat[]
425+
cats cat[]
426426
}
427427
428428
model ExternalTableB {
429429
id Int @id
430430
name String
431-
cat Cat? @relation(fields: [catId], references: [id])
431+
cat cat? @relation(fields: [catId], references: [id])
432432
catId Int?
433433
}
434434
"#,
@@ -445,33 +445,33 @@ fn schema_filter_migration_modifying_external_tables_incl_relations(mut api: Tes
445445
let expected_script = if is_postgres {
446446
expect![[r#"
447447
-- AlterTable
448-
ALTER TABLE "Cat" ADD COLUMN "externalTableId" INTEGER;
448+
ALTER TABLE "cat" ADD COLUMN "externalTableId" INTEGER;
449449
450450
-- AddForeignKey
451-
ALTER TABLE "Cat" ADD CONSTRAINT "Cat_externalTableId_fkey" FOREIGN KEY ("externalTableId") REFERENCES "ExternalTableA"("id") ON DELETE SET NULL ON UPDATE CASCADE;
451+
ALTER TABLE "cat" ADD CONSTRAINT "cat_externalTableId_fkey" FOREIGN KEY ("externalTableId") REFERENCES "ExternalTableA"("id") ON DELETE SET NULL ON UPDATE CASCADE;
452452
"#]]
453453
} else if is_mysql {
454454
expect![[r#"
455455
-- AlterTable
456-
ALTER TABLE `Cat` ADD COLUMN `externalTableId` INTEGER NULL;
456+
ALTER TABLE `cat` ADD COLUMN `externalTableId` INTEGER NULL;
457457
458458
-- AddForeignKey
459-
ALTER TABLE `Cat` ADD CONSTRAINT `Cat_externalTableId_fkey` FOREIGN KEY (`externalTableId`) REFERENCES `ExternalTableA`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
459+
ALTER TABLE `cat` ADD CONSTRAINT `cat_externalTableId_fkey` FOREIGN KEY (`externalTableId`) REFERENCES `ExternalTableA`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
460460
"#]]
461461
} else if is_sqlite {
462462
expect![[r#"
463463
-- RedefineTables
464464
PRAGMA defer_foreign_keys=ON;
465465
PRAGMA foreign_keys=OFF;
466-
CREATE TABLE "new_Cat" (
466+
CREATE TABLE "new_cat" (
467467
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
468468
"name" TEXT NOT NULL,
469469
"externalTableId" INTEGER,
470-
CONSTRAINT "Cat_externalTableId_fkey" FOREIGN KEY ("externalTableId") REFERENCES "ExternalTableA" ("id") ON DELETE SET NULL ON UPDATE CASCADE
470+
CONSTRAINT "cat_externalTableId_fkey" FOREIGN KEY ("externalTableId") REFERENCES "ExternalTableA" ("id") ON DELETE SET NULL ON UPDATE CASCADE
471471
);
472-
INSERT INTO "new_Cat" ("id", "name") SELECT "id", "name" FROM "Cat";
473-
DROP TABLE "Cat";
474-
ALTER TABLE "new_Cat" RENAME TO "Cat";
472+
INSERT INTO "new_cat" ("id", "name") SELECT "id", "name" FROM "cat";
473+
DROP TABLE "cat";
474+
ALTER TABLE "new_cat" RENAME TO "cat";
475475
PRAGMA foreign_keys=ON;
476476
PRAGMA defer_foreign_keys=OFF;
477477
"#]]
@@ -482,10 +482,10 @@ fn schema_filter_migration_modifying_external_tables_incl_relations(mut api: Tes
482482
BEGIN TRAN;
483483
484484
-- AlterTable
485-
ALTER TABLE [dbo].[Cat] ADD [externalTableId] INT;
485+
ALTER TABLE [dbo].[cat] ADD [externalTableId] INT;
486486
487487
-- AddForeignKey
488-
ALTER TABLE [dbo].[Cat] ADD CONSTRAINT [Cat_externalTableId_fkey] FOREIGN KEY ([externalTableId]) REFERENCES [dbo].[ExternalTableA]([id]) ON DELETE SET NULL ON UPDATE CASCADE;
488+
ALTER TABLE [dbo].[cat] ADD CONSTRAINT [cat_externalTableId_fkey] FOREIGN KEY ([externalTableId]) REFERENCES [dbo].[ExternalTableA]([id]) ON DELETE SET NULL ON UPDATE CASCADE;
489489
490490
COMMIT TRAN;
491491

0 commit comments

Comments
 (0)