shr0x / ragemp-rp-gamemode

A startup rp script to make your way into making a rp server easier!
Other
21 stars 9 forks source link

TypeORM is not creating the tables Automatically #23

Open DevendarTamma opened 1 month ago

DevendarTamma commented 1 month ago

Question Title

TypeORM is not creating the tables Automatically

Question

TypeORM is not creating the tables Automatically, I am running the npm run watch: server , but the tables are not creating automatically to the database, I have even tried hardcoding the db connection details in Database.module.ts but still it is not creating, Can you please look into this and let me know where I am missing the db connection settings, I have even tried adding console logging but still it is not printing anything to the console when I run the server , I am placing hardcoded db file in context as it is not allowing me to attach .ts files and the screenshots of my structure as attachments as well game-mode server-files

Context

import "reflect-metadata"; import { DataSource } from "typeorm"; import { AccountEntity } from "./entity/Account.entity"; import { CharacterEntity } from "./entity/Character.entity"; import { DatabaseLogger } from "./Logger.module"; import { BanEntity } from "./entity/Ban.entity"; import { InventoryItemsEntity } from "./entity/Inventory.entity"; import { VehicleEntity } from "./entity/Vehicle.entity"; import { BankAccountEntity } from "@entities/Bank.entity";

// Hard-coded configuration const config = { connectionLimit: 100, connectTimeout: 60 60 1000, acquireTimeout: 60 60 1000, timeout: 60 60 1000, host: "localhost", // Replace with your DB host user: "postgres", // Replace with your DB user password: "postgres", // Replace with your DB password database: "mydb", // Replace with your DB name port: 5432 };

const loggerConfig = { queryLogFilePath: "./dblogs/query-log.log", errorLogFilePath: "./dblogs/error.log", defaultLogFilePath: "./dblogs/default-log.log" };

// Logging the configuration details console.log("Database connection configuration:", config);

export const MainDataSource = new DataSource({ type: "postgres", host: config.host, port: config.port, username: config.user, password: config.password, database: config.database, synchronize: true, connectTimeoutMS: config.connectTimeout, logging: ["error"], entities: [AccountEntity, CharacterEntity, BankAccountEntity, BanEntity, InventoryItemsEntity, VehicleEntity], migrations: [], subscribers: [], logger: DatabaseLogger.getInstance(loggerConfig) });

// Function to test database connection async function testDatabaseConnection() { try { console.log("Attempting to connect to the database..."); await MainDataSource.initialize(); console.log("Database connection established successfully."); } catch (error) { console.error("Database connection failed:", error); } }

// Test the database connection testDatabaseConnection();

Troubleshooting Steps

No response

Additional Information

No response

shr0x commented 1 month ago

Is the database connecting?

DevendarTamma commented 1 month ago

I believe no, how to know whethere it is connecting or not , I tried adding a function for testing in Database.module.ts but it is not printing anything in console when I ran the server

shr0x commented 1 month ago

The server should turn off on its own when the database fails to connect, but since you have done changes to it, its not. Do not edit the code as the problem is not there. It's the database, see if you have installed it properly and you have access connecting to it. You might as well try giving RAGEMP server access to your firewall.