@@ -2,6 +2,7 @@ import { Catch } from '../../decorators/Catch';
22import { ConnectionPool } from '../ConnectionPool' ;
33import * as path from 'path' ;
44import * as fs from 'fs/promises' ;
5+ import Config from '../../config/index' ;
56export 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