mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 04:20:55 +00:00
Trains management CRUD issues solved
This commit is contained in:
25
apps/edr-freight-api/src/scripts/create-freight-schema.js
Normal file
25
apps/edr-freight-api/src/scripts/create-freight-schema.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const { Client } = require('pg');
|
||||
|
||||
(async function createSchema(){
|
||||
const client = new Client({
|
||||
host: 'localhost',
|
||||
port: 5432,
|
||||
user: 'postgres',
|
||||
password: '',
|
||||
database: 'edr_freight',
|
||||
});
|
||||
|
||||
try {
|
||||
console.log('Connecting to Postgres...');
|
||||
await client.connect();
|
||||
console.log('Creating schema freight if not exists...');
|
||||
await client.query('CREATE SCHEMA IF NOT EXISTS freight');
|
||||
console.log('Schema ensured.');
|
||||
await client.end();
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('Failed to create schema:', err);
|
||||
try { await client.end(); } catch {}
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
27
apps/edr-freight-api/src/scripts/create-freight-schema.ts
Normal file
27
apps/edr-freight-api/src/scripts/create-freight-schema.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Client } from 'pg';
|
||||
|
||||
async function createSchema() {
|
||||
const client = new Client({
|
||||
host: 'localhost',
|
||||
port: 5432,
|
||||
user: 'postgres',
|
||||
password: '',
|
||||
database: 'edr_freight',
|
||||
});
|
||||
|
||||
try {
|
||||
console.log('Connecting to Postgres...');
|
||||
await client.connect();
|
||||
console.log('Creating schema freight if not exists...');
|
||||
await client.query('CREATE SCHEMA IF NOT EXISTS freight');
|
||||
console.log('Schema ensured.');
|
||||
await client.end();
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('Failed to create schema:', err);
|
||||
try { await client.end(); } catch {}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
createSchema();
|
||||
21
apps/edr-freight-api/src/scripts/run-migrations.ts
Normal file
21
apps/edr-freight-api/src/scripts/run-migrations.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { AppDataSource } from '../data-source';
|
||||
|
||||
async function runMigrations() {
|
||||
try {
|
||||
console.log('Initializing datasource...');
|
||||
await AppDataSource.initialize();
|
||||
console.log('Datasource initialized. Running migrations...');
|
||||
const migrations = await AppDataSource.runMigrations();
|
||||
console.log(`Applied ${migrations.length} migrations.`);
|
||||
await AppDataSource.destroy();
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('Migration run failed:', err);
|
||||
try {
|
||||
await AppDataSource.destroy();
|
||||
} catch {}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
runMigrations();
|
||||
Reference in New Issue
Block a user