@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
node ./scripts/wait-for-database.js
|
||||
node ./scripts/migrate.js
|
||||
exec node server.js
|
||||
@@ -0,0 +1,14 @@
|
||||
const path = require("node:path");
|
||||
const postgres = require("postgres");
|
||||
const { drizzle } = require("drizzle-orm/postgres-js");
|
||||
const { migrate } = require("drizzle-orm/postgres-js/migrator");
|
||||
(async () => {
|
||||
const client = postgres(process.env.DATABASE_URL, { max: 1 });
|
||||
await migrate(drizzle(client), {
|
||||
migrationsFolder: path.join(process.cwd(), "drizzle/migrations"),
|
||||
});
|
||||
await client.end();
|
||||
})().catch((error) => {
|
||||
console.error("Migration failed", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
const postgres = require("postgres");
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
if (!databaseUrl) throw new Error("DATABASE_URL is required.");
|
||||
const client = postgres(databaseUrl, { max: 1 });
|
||||
(async () => {
|
||||
for (let attempt = 1; attempt <= 30; attempt += 1) {
|
||||
try {
|
||||
await client`select 1`;
|
||||
await client.end();
|
||||
return;
|
||||
} catch {
|
||||
if (attempt === 30) {
|
||||
await client.end();
|
||||
throw new Error("Database was not reachable after 30 attempts.");
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error("Database wait failed", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import postgres from "postgres";
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
if (!databaseUrl) throw new Error("DATABASE_URL is required.");
|
||||
const client = postgres(databaseUrl, { max: 1 });
|
||||
for (let attempt = 1; attempt <= 30; attempt += 1) {
|
||||
try {
|
||||
await client`select 1`;
|
||||
await client.end();
|
||||
process.exit(0);
|
||||
} catch {
|
||||
if (attempt === 30) {
|
||||
await client.end();
|
||||
throw new Error("Database was not reachable after 30 attempts.");
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user