Skip to content

Commit

Permalink
delay psql connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Looskie authored Feb 12, 2024
1 parent e2671d3 commit ae6c27a
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions apps/api/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@ import { Logger } from "../utils/logger";
export let db: ReturnType<typeof drizzle>;

export const setupDB = async () => {
const pool = await new Pool({
connectionString: env.DATABASE_URL,
})
.connect()
.then((client) => {
Logger.info("INIT", "Connected to database");

return client;
setTimeout(() => {
const pool = await new Pool({
connectionString: env.DATABASE_URL,
})
.catch((err) => {
Logger.error("INIT", `Failed to connect to database ${String(err)}}`);
process.exit(1);
});

db = drizzle(pool);

await migrate(db, {
migrationsFolder: "../../packages/internal/db/migrations",
})
.then(() => {
Logger.info("INIT", "Migrated database");
.connect()
.then((client) => {
Logger.info("INIT", "Connected to database");

return client;
})
.catch((err) => {
Logger.error("INIT", `Failed to connect to database ${String(err)}}`);
process.exit(1);
});

db = drizzle(pool);

await migrate(db, {
migrationsFolder: "../../packages/internal/db/migrations",
})
.catch((err) => {
Logger.error("INIT", `Failed to migrate database ${String(err)}`);
process.exit(1);
});
.then(() => {
Logger.info("INIT", "Migrated database");
})
.catch((err) => {
Logger.error("INIT", `Failed to migrate database ${String(err)}`);
process.exit(1);
});
}, 1000)
};

0 comments on commit ae6c27a

Please sign in to comment.