Skip to content

Commit 04f85a0

Browse files
committed
fix: Updated Tables.ts to use different SQL file paths based on environment
1 parent aa7badd commit 04f85a0

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/database/service/Tables.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Catch } from '../../decorators/Catch';
22
import { ConnectionPool } from '../ConnectionPool';
33
import * as path from 'path';
44
import * as fs from 'fs/promises';
5+
import Config from '../../config/index';
56
export class TablesService {
67
constructor(private _connectionPool: ConnectionPool) {}
78
@Catch({
@@ -11,7 +12,8 @@ export class TablesService {
1112
})
1213
async initialTables() {
1314
const client = await this._connectionPool.getClient();
14-
const sqlFilePath = path.join(__dirname, '..', './sql/Tables.sql');
15+
const productionPath = path.join(process.cwd(), 'src', 'database', 'sql', 'Tables.sql');
16+
const sqlFilePath = Config.environment === 'production' ? productionPath : path.join(__dirname, '..', './sql/Tables.sql');
1517
const sql = await fs.readFile(sqlFilePath, 'utf-8');
1618
await client.query(sql);
1719
console.log('Initial tables have been set up successfully.');
@@ -29,7 +31,8 @@ export class TablesService {
2931
console.log('The tables have already been seeded. Skipping seeding process.');
3032
return; // Skip seeding if there's already data in the User table
3133
}
32-
const sqlFilePath = path.join(__dirname, '..', './sql/seed/SeedDataTables.sql');
34+
const productionPath = path.join(process.cwd(), 'src', 'database', 'sql', 'seed', 'SeedDataTables.sql');
35+
const sqlFilePath = Config.environment === 'production' ? productionPath : path.join(__dirname, '..', './sql/seed/SeedDataTables.sql');
3336
const sql = await fs.readFile(sqlFilePath, 'utf-8');
3437
await client.query(sql);
3538
console.log('All tables have been seeded successfully.');

0 commit comments

Comments
 (0)