* Fix bug where "metadata" scheme was not created automatically (#1971) * logging on * testing on render * render upadte * added setup-db.ts and updated package.json
This commit is contained in:
31
server/scripts/setup-db.ts
Normal file
31
server/scripts/setup-db.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
import { config } from 'dotenv';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
config();
|
||||
|
||||
const configService = new ConfigService();
|
||||
|
||||
export const connectionSource = new DataSource({
|
||||
type: 'postgres',
|
||||
logging: false,
|
||||
url: configService.get<string>('PG_DATABASE_URL'),
|
||||
});
|
||||
|
||||
connectionSource
|
||||
.initialize()
|
||||
.then(async () => {
|
||||
await connectionSource.query(`CREATE SCHEMA IF NOT EXISTS "metadata"`);
|
||||
const result = await connectionSource.query(`
|
||||
SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'metadata'
|
||||
`);
|
||||
if (result.length > 0) {
|
||||
console.log('Schema "metadata" created successfully');
|
||||
} else {
|
||||
console.log('Failed to create schema "metadata"');
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Error during Data Source initialization:', err);
|
||||
});
|
||||
Reference in New Issue
Block a user