Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeORM is not creating the tables Automatically #23

Open
DevendarTamma opened this issue Aug 30, 2024 · 3 comments
Open

TypeORM is not creating the tables Automatically #23

DevendarTamma opened this issue Aug 30, 2024 · 3 comments
Labels
question Further information is requested

Comments

@DevendarTamma
Copy link

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

@DevendarTamma DevendarTamma added the question Further information is requested label Aug 30, 2024
@shr0x
Copy link
Owner

shr0x commented Aug 31, 2024

Is the database connecting?

@DevendarTamma
Copy link
Author

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
Copy link
Owner

shr0x commented Sep 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants