From 9e9b9f638521e431d13580b5981251a222075245 Mon Sep 17 00:00:00 2001 From: Micah Morrison Date: Fri, 10 May 2024 15:01:36 -0400 Subject: [PATCH] Create Thunder database if not exists --- example.env | 2 +- src/database/database.ts | 2 +- src/index.ts | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/example.env b/example.env index 700365d..552dd72 100644 --- a/example.env +++ b/example.env @@ -2,7 +2,7 @@ POSTGRES_USER=user POSTGRES_PASSWORD=password POSTGRES_HOSTNAME=postgres POSTGRES_PORT=5432 -POSTGRES_DATABASE=thunder-database +POSTGRES_DATABASE=thunder_database APNS_KEY_ID=key_id APNS_TEAM_ID=team_id diff --git a/src/database/database.ts b/src/database/database.ts index cf41e53..88d91a6 100644 --- a/src/database/database.ts +++ b/src/database/database.ts @@ -6,7 +6,7 @@ dotenv.config(); // Configure database const sequelize = new Sequelize( - `postgres://${process.env.POSTGRES_USER ?? "user"}:${process.env.POSTGRES_PASSWORD ?? "password"}@${process.env.POSTGRES_HOSTNAME ?? "postgres"}:${process.env.POSTGRES_PORT ?? "5432"}/${process.env.POSTGRES_DATABASE ?? "thunder-database"}` + `postgres://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASSWORD}@postgres:5432/database` ); export default sequelize; diff --git a/src/index.ts b/src/index.ts index 48be233..64466b1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import { } from "./types/notification_request"; // Database +import { ensureThunderDatabaseExists } from "./database/database"; import sequelize from "./database/database"; // Helper functions @@ -70,6 +71,7 @@ app.delete("/notifications", (req, res) => { app.listen(port, async () => { console.log(`Server is running on http://localhost:${port}`); + await ensureThunderDatabaseExists(); await sequelize.sync({ force: DEBUG_MODE }); console.log("All models were synchronized successfully."); });