fix: run migrations in code
Some checks failed
Deploy to GitHub Pages / build_site (push) Failing after 36s
Some checks failed
Deploy to GitHub Pages / build_site (push) Failing after 36s
This commit is contained in:
@ -2,6 +2,8 @@ import { drizzle } from "drizzle-orm/node-postgres";
|
||||
import pg from "pg";
|
||||
import * as schema from "./schema.ts";
|
||||
|
||||
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
||||
|
||||
// Use pg driver.
|
||||
const { Pool } = pg;
|
||||
|
||||
@ -13,3 +15,7 @@ export const db = drizzle({
|
||||
}),
|
||||
schema,
|
||||
});
|
||||
|
||||
export function migrateDb() {
|
||||
return migrate(db, { migrationsFolder: "drizzle" });
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import { cors } from "hono/cors";
|
||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { nodeRouter } from "./routes/node/node.controller.ts";
|
||||
import { userRouter } from "./routes/user/user.controller.ts";
|
||||
import { migrateDb } from "./db/db.ts";
|
||||
|
||||
const router = new OpenAPIHono();
|
||||
|
||||
@ -26,10 +27,11 @@ router.get("/ui", swaggerUI({ url: "/openapi.json" }));
|
||||
Deno.serve(router.fetch);
|
||||
|
||||
async function init() {
|
||||
await migrateDb();
|
||||
await createUser("max");
|
||||
|
||||
const openapi = await router.request("/openapi.json");
|
||||
const json = await openapi.text();
|
||||
Deno.writeTextFile("openapi.json", json);
|
||||
|
||||
await createUser("max");
|
||||
}
|
||||
await init();
|
||||
|
Reference in New Issue
Block a user