This commit is contained in:
@@ -11,6 +11,18 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
|
||||
// Migrations that were first created with dates in the future, renamed to when they were written.
|
||||
// The SQL is unchanged, so databases that already applied them only need the recorded name updated.
|
||||
const RENAMED_MIGRATIONS = {
|
||||
'20261020120000_tab_events': '20261019212336_tab_events',
|
||||
'20261021120000_stock': '20261020124522_stock',
|
||||
'20261022120000_server_tabs_and_stock': '20261020141836_server_tabs_and_stock',
|
||||
'20261023120000_products_on_dashboard': '20261020215540_products_on_dashboard',
|
||||
'20261024120000_product_images_and_events': '20261021104519_product_images_and_events',
|
||||
'20261025120000_sold_unit_view': '20261021225808_sold_unit_view',
|
||||
'20261026120000_drop_tab_snapshots': '20261021233219_drop_tab_snapshots',
|
||||
};
|
||||
|
||||
function run(command) {
|
||||
console.log(`[deploy] ${command}`);
|
||||
execSync(command, { stdio: 'inherit' });
|
||||
@@ -27,6 +39,14 @@ async function main() {
|
||||
EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public') AS tables`;
|
||||
hasMigrationsTable = migrations;
|
||||
hasTables = tables;
|
||||
|
||||
if (hasMigrationsTable) {
|
||||
for (const [oldName, newName] of Object.entries(RENAMED_MIGRATIONS)) {
|
||||
const renamed = await prisma.$executeRaw`
|
||||
UPDATE "_prisma_migrations" SET "migration_name" = ${newName} WHERE "migration_name" = ${oldName}`;
|
||||
if (renamed > 0) console.log(`[deploy] Renamed migration ${oldName} -> ${newName}`);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user