This commit is contained in:
@@ -30,4 +30,4 @@ COPY package.json pnpm-lock.yaml ./
|
|||||||
COPY --from=builder /app/node_modules ./node_modules
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
RUN mkdir -p /app/data
|
RUN mkdir -p /app/data
|
||||||
EXPOSE 4321
|
EXPOSE 4321
|
||||||
CMD ["sh","-c","node scripts/migrate.js && node ./dist/server/entry.mjs"]
|
CMD ["sh","-c","node ./dist/server/entry.mjs"]
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
import Database from "better-sqlite3";
|
|
||||||
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
||||||
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
|
||||||
import path from "path";
|
|
||||||
import fs from "fs";
|
|
||||||
|
|
||||||
const runMigrations = () => {
|
|
||||||
console.log("Starting database migrations...");
|
|
||||||
|
|
||||||
const dbUrl =
|
|
||||||
process.env.DATABASE_URL || path.resolve(process.cwd(), "chronus.db");
|
|
||||||
const dbDir = path.dirname(dbUrl);
|
|
||||||
|
|
||||||
if (!fs.existsSync(dbDir)) {
|
|
||||||
console.log(`Creating directory for database: ${dbDir}`);
|
|
||||||
fs.mkdirSync(dbDir, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Using database at: ${dbUrl}`);
|
|
||||||
|
|
||||||
const sqlite = new Database(dbUrl);
|
|
||||||
const db = drizzle(sqlite);
|
|
||||||
|
|
||||||
const migrationsFolder = path.resolve(process.cwd(), "drizzle");
|
|
||||||
|
|
||||||
if (!fs.existsSync(migrationsFolder)) {
|
|
||||||
console.error(`Migrations folder not found at: ${migrationsFolder}`);
|
|
||||||
console.error(
|
|
||||||
"Did you run `drizzle-kit generate` and copy the folder to the container?",
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
migrate(db, { migrationsFolder });
|
|
||||||
console.log("Migrations completed successfully");
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Migration failed:", error);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlite.close();
|
|
||||||
};
|
|
||||||
|
|
||||||
runMigrations();
|
|
||||||
Reference in New Issue
Block a user