fix: make radio migrations safe for existing schemas

This commit is contained in:
Simo committed 2026-07-11 22:18:45 +02:00
1 parent 6c63ed52cd
commit d99b71a2d3
5 files changed
+52 -20

No files matched your search

+4 -2
View File
@@ -3,6 +3,7 @@ import { readFileSync, readdirSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { splitSqlStatements } from "./sql-statements";
import { mysqlConnectionUrl } from "./db-url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const MIGRATIONS_DIR = resolve(__dirname, "../prisma/migrations");
@@ -17,8 +18,9 @@ interface MigrationFile {
function getDbConfig(): { url: string; database: string } {
const url = process.env.DATABASE_URL;
if (!url) throw new Error("DATABASE_URL is required");
const dbName = url.split("/").pop()?.split("?")[0] ?? "atomcms";
return { url, database: dbName };
const parsed = new URL(url);
const dbName = decodeURIComponent(parsed.pathname.replace(/^\//, "")) || "atomcms";
return { url: mysqlConnectionUrl(url), database: dbName };
}
async function ensureConnection(): Promise<void> {