added packages into dockploy 4
This commit is contained in:
+40
-9
@@ -140075,14 +140075,26 @@ var require_apply_migrations = __commonJS({
|
||||
var node_fs_1 = require("node:fs");
|
||||
var node_path_1 = __importDefault2(require("node:path"));
|
||||
var client_1 = require_default2();
|
||||
var IGNORABLE = /* @__PURE__ */ new Set(["42701", "42710", "42P07"]);
|
||||
function migrationsDir() {
|
||||
return node_path_1.default.join(process.cwd(), "runtime", "migrations");
|
||||
}
|
||||
__name(migrationsDir, "migrationsDir");
|
||||
function splitStatements(sql) {
|
||||
return sql.split(/;\s*(?:\r?\n|$)/).map((part) => part.trim()).filter((part) => part.length > 0 && !part.startsWith("--"));
|
||||
return sql.split(/;\s*(?:\r?\n|$)/).map((part) => part.split(/\r?\n/).filter((line) => {
|
||||
const trimmed = line.trim();
|
||||
return trimmed.length > 0 && !trimmed.startsWith("--");
|
||||
}).join("\n").trim()).filter((part) => part.length > 0);
|
||||
}
|
||||
__name(splitStatements, "splitStatements");
|
||||
function pgCode(err) {
|
||||
if (typeof err === "object" && err && "meta" in err) {
|
||||
const meta = err.meta;
|
||||
return meta?.code;
|
||||
}
|
||||
return void 0;
|
||||
}
|
||||
__name(pgCode, "pgCode");
|
||||
async function waitForDb(prisma) {
|
||||
let lastError;
|
||||
for (let i = 1; i <= 30; i++) {
|
||||
@@ -140099,6 +140111,17 @@ var require_apply_migrations = __commonJS({
|
||||
throw lastError;
|
||||
}
|
||||
__name(waitForDb, "waitForDb");
|
||||
async function customerTableExists(prisma) {
|
||||
const rows = await prisma.$queryRaw`
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public' AND table_name = 'Customer'
|
||||
) AS "exists"
|
||||
`;
|
||||
return Boolean(rows[0]?.exists);
|
||||
}
|
||||
__name(customerTableExists, "customerTableExists");
|
||||
async function applyPendingMigrations() {
|
||||
const dir = migrationsDir();
|
||||
if (!(0, node_fs_1.existsSync)(dir)) {
|
||||
@@ -140120,6 +140143,11 @@ var require_apply_migrations = __commonJS({
|
||||
"applied_steps_count" INTEGER NOT NULL DEFAULT 0
|
||||
)
|
||||
`);
|
||||
await prisma.$executeRawUnsafe(`DELETE FROM "_prisma_migrations" WHERE "finished_at" IS NULL`);
|
||||
if (!await customerTableExists(prisma)) {
|
||||
console.log("Empty database; replaying all migrations");
|
||||
await prisma.$executeRawUnsafe(`DELETE FROM "_prisma_migrations"`);
|
||||
}
|
||||
const applied = await prisma.$queryRaw`
|
||||
SELECT "migration_name" FROM "_prisma_migrations" WHERE "finished_at" IS NOT NULL
|
||||
`;
|
||||
@@ -140135,17 +140163,20 @@ var require_apply_migrations = __commonJS({
|
||||
const checksum = (0, node_crypto_1.createHash)("sha256").update(sql).digest("hex");
|
||||
const id = (0, node_crypto_1.randomUUID)();
|
||||
console.log(`Applying migration ${name}`);
|
||||
await prisma.$executeRaw`
|
||||
INSERT INTO "_prisma_migrations" ("id", "checksum", "migration_name", "started_at", "applied_steps_count")
|
||||
VALUES (${id}, ${checksum}, ${name}, now(), 0)
|
||||
`;
|
||||
for (const statement of splitStatements(sql)) {
|
||||
await prisma.$executeRawUnsafe(statement);
|
||||
try {
|
||||
await prisma.$executeRawUnsafe(statement);
|
||||
} catch (err) {
|
||||
if (IGNORABLE.has(pgCode(err) ?? "")) {
|
||||
console.log(` skip already-exists: ${statement.slice(0, 60)}`);
|
||||
continue;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
await prisma.$executeRaw`
|
||||
UPDATE "_prisma_migrations"
|
||||
SET "finished_at" = now(), "applied_steps_count" = 1
|
||||
WHERE "id" = ${id}
|
||||
INSERT INTO "_prisma_migrations" ("id", "checksum", "migration_name", "started_at", "finished_at", "applied_steps_count")
|
||||
VALUES (${id}, ${checksum}, ${name}, now(), now(), 1)
|
||||
`;
|
||||
}
|
||||
console.log("Migrations up to date");
|
||||
|
||||
+52
-11
@@ -3,6 +3,8 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const IGNORABLE = new Set(['42701', '42710', '42P07'])
|
||||
|
||||
function migrationsDir(): string {
|
||||
return path.join(process.cwd(), 'runtime', 'migrations')
|
||||
}
|
||||
@@ -10,8 +12,25 @@ function migrationsDir(): string {
|
||||
function splitStatements(sql: string): string[] {
|
||||
return sql
|
||||
.split(/;\s*(?:\r?\n|$)/)
|
||||
.map((part) => part.trim())
|
||||
.filter((part) => part.length > 0 && !part.startsWith('--'))
|
||||
.map((part) =>
|
||||
part
|
||||
.split(/\r?\n/)
|
||||
.filter((line) => {
|
||||
const trimmed = line.trim()
|
||||
return trimmed.length > 0 && !trimmed.startsWith('--')
|
||||
})
|
||||
.join('\n')
|
||||
.trim(),
|
||||
)
|
||||
.filter((part) => part.length > 0)
|
||||
}
|
||||
|
||||
function pgCode(err: unknown): string | undefined {
|
||||
if (typeof err === 'object' && err && 'meta' in err) {
|
||||
const meta = (err as { meta?: { code?: string } }).meta
|
||||
return meta?.code
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
async function waitForDb(prisma: PrismaClient): Promise<void> {
|
||||
@@ -30,6 +49,17 @@ async function waitForDb(prisma: PrismaClient): Promise<void> {
|
||||
throw lastError
|
||||
}
|
||||
|
||||
async function customerTableExists(prisma: PrismaClient): Promise<boolean> {
|
||||
const rows = await prisma.$queryRaw<Array<{ exists: boolean }>>`
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public' AND table_name = 'Customer'
|
||||
) AS "exists"
|
||||
`
|
||||
return Boolean(rows[0]?.exists)
|
||||
}
|
||||
|
||||
export async function applyPendingMigrations(): Promise<void> {
|
||||
const dir = migrationsDir()
|
||||
if (!existsSync(dir)) {
|
||||
@@ -53,6 +83,15 @@ export async function applyPendingMigrations(): Promise<void> {
|
||||
)
|
||||
`)
|
||||
|
||||
await prisma.$executeRawUnsafe(
|
||||
`DELETE FROM "_prisma_migrations" WHERE "finished_at" IS NULL`,
|
||||
)
|
||||
|
||||
if (!(await customerTableExists(prisma))) {
|
||||
console.log('Empty database; replaying all migrations')
|
||||
await prisma.$executeRawUnsafe(`DELETE FROM "_prisma_migrations"`)
|
||||
}
|
||||
|
||||
const applied = await prisma.$queryRaw<Array<{ migration_name: string }>>`
|
||||
SELECT "migration_name" FROM "_prisma_migrations" WHERE "finished_at" IS NOT NULL
|
||||
`
|
||||
@@ -73,19 +112,21 @@ export async function applyPendingMigrations(): Promise<void> {
|
||||
const id = randomUUID()
|
||||
console.log(`Applying migration ${name}`)
|
||||
|
||||
await prisma.$executeRaw`
|
||||
INSERT INTO "_prisma_migrations" ("id", "checksum", "migration_name", "started_at", "applied_steps_count")
|
||||
VALUES (${id}, ${checksum}, ${name}, now(), 0)
|
||||
`
|
||||
|
||||
for (const statement of splitStatements(sql)) {
|
||||
await prisma.$executeRawUnsafe(statement)
|
||||
try {
|
||||
await prisma.$executeRawUnsafe(statement)
|
||||
} catch (err) {
|
||||
if (IGNORABLE.has(pgCode(err) ?? '')) {
|
||||
console.log(` skip already-exists: ${statement.slice(0, 60)}`)
|
||||
continue
|
||||
}
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.$executeRaw`
|
||||
UPDATE "_prisma_migrations"
|
||||
SET "finished_at" = now(), "applied_steps_count" = 1
|
||||
WHERE "id" = ${id}
|
||||
INSERT INTO "_prisma_migrations" ("id", "checksum", "migration_name", "started_at", "finished_at", "applied_steps_count")
|
||||
VALUES (${id}, ${checksum}, ${name}, now(), now(), 1)
|
||||
`
|
||||
}
|
||||
console.log('Migrations up to date')
|
||||
|
||||
Reference in New Issue
Block a user