Moray
Moray
Explore posts from servers
PPrisma
Created by Moray on 8/23/2024 in #help-and-questions
Introspecting an existing database doesn't handle join tables correctly
For info, this is what the existing _RoleToTenantUser table looks like:
CREATE TABLE `_RoleToTenantUser` (
`A` char(25) CHARACTER SET utf8 NOT NULL,
`B` char(25) CHARACTER SET utf8 NOT NULL,
UNIQUE KEY `RoleToTenantUser_AB_unique` (`A`,`B`),
KEY `B` (`B`),
CONSTRAINT `_RoleToTenantUser_ibfk_1` FOREIGN KEY (`A`) REFERENCES `Role` (`id`) ON DELETE CASCADE,
CONSTRAINT `_RoleToTenantUser_ibfk_2` FOREIGN KEY (`B`) REFERENCES `TenantUser` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
CREATE TABLE `_RoleToTenantUser` (
`A` char(25) CHARACTER SET utf8 NOT NULL,
`B` char(25) CHARACTER SET utf8 NOT NULL,
UNIQUE KEY `RoleToTenantUser_AB_unique` (`A`,`B`),
KEY `B` (`B`),
CONSTRAINT `_RoleToTenantUser_ibfk_1` FOREIGN KEY (`A`) REFERENCES `Role` (`id`) ON DELETE CASCADE,
CONSTRAINT `_RoleToTenantUser_ibfk_2` FOREIGN KEY (`B`) REFERENCES `TenantUser` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
And this is what Prisma generated for this table in prisma/migrations/0_init/migration.sql:
CREATE TABLE `_RoleToTenantUser` (
`A` CHAR(25) NOT NULL,
`B` CHAR(25) NOT NULL,

UNIQUE INDEX `_RoleToTenantUser_AB_unique`(`A`, `B`),
INDEX `_RoleToTenantUser_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `_RoleToTenantUser` ADD CONSTRAINT `_RoleToTenantUser_A_fkey` FOREIGN KEY (`A`) REFERENCES `Role`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `_RoleToTenantUser` ADD CONSTRAINT `_RoleToTenantUser_B_fkey` FOREIGN KEY (`B`) REFERENCES `TenantUser`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
CREATE TABLE `_RoleToTenantUser` (
`A` CHAR(25) NOT NULL,
`B` CHAR(25) NOT NULL,

UNIQUE INDEX `_RoleToTenantUser_AB_unique`(`A`, `B`),
INDEX `_RoleToTenantUser_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `_RoleToTenantUser` ADD CONSTRAINT `_RoleToTenantUser_A_fkey` FOREIGN KEY (`A`) REFERENCES `Role`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `_RoleToTenantUser` ADD CONSTRAINT `_RoleToTenantUser_B_fkey` FOREIGN KEY (`B`) REFERENCES `TenantUser`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
3 replies
PPrisma
Created by Moray on 8/16/2024 in #help-and-questions
Upgrading from Prisma 1
Going to have to apply a few preliminary database changes so that it understands which relationships are 1-many and which are many-many
7 replies
PPrisma
Created by Moray on 8/16/2024 in #help-and-questions
Upgrading from Prisma 1
Yeah that's basically what I'm doing. The new DB introspection only looks at the database state rather than the GraphQL files that prisma1 uses so I'm going to have to spend a fair bit of time fixing that before I get on to updating literally thousands of queries in our application
7 replies
PPrisma
Created by Moray on 8/16/2024 in #help-and-questions
Upgrading from Prisma 1
I think this is going to be less of an upgrade process and more of a "start from scratch"
7 replies
PPrisma
Created by Moray on 8/16/2024 in #help-and-questions
Upgrading from Prisma 1
After a bit of fiddling, it seems that we have to jump straight from v1 to 4.10 at a minimum. Going to try going to 4.16.2 and see what happens...
7 replies