feat(database): add TypeORM configuration and initialize data source

- Added TypeORM and PostgreSQL dependencies to package.json.
- Created data-source.ts to configure the database connection.
- Initialized the data source in index.ts and added logging for successful connection.
- Updated devDependencies to include @types/node for better type support.
This commit is contained in:
2025-10-29 10:44:12 +01:00
parent 58ecaf3c4c
commit 43b7bdd8b4
5 changed files with 1556 additions and 8 deletions

19
src/data-source.ts Normal file
View File

@@ -0,0 +1,19 @@
import "reflect-metadata"
import { DataSource } from "typeorm"
import { configDotenv } from "dotenv"
configDotenv()
export const AppDataSource = new DataSource({
type: "postgres",
host: process.env.DB_HOST || "localhost",
port: parseInt(process.env.DB_PORT || "5432"),
username: process.env.DB_USERNAME || "postgres",
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
synchronize: process.env.NODE_ENV !== "production", // false en production
logging: process.env.DB_LOGGING === "true",
entities: ["./entity/**/*.js"],
migrations: ["./migration/**/*.js"],
subscribers: ["./subscriber/**/*.js"],
})

View File

@@ -4,8 +4,17 @@ import path from "path";
import fs from "fs";
import statusService from "./services/status.service";
import "reflect-metadata";
import { AppDataSource } from "./data-source";
configDotenv();
AppDataSource.initialize()
.then(() => {
console.log("Data Source initialized !")
})
.catch((error) => console.log(error));
const client = new Client({
intents: [
GatewayIntentBits.Guilds,