twenty/server/scripts/setup-db.ts
Ruslan 77c88bda6e
Fix bug where "metadata" scheme was not created automatically (#1971) and (#1831) (#2018)
* 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
2023-10-14 11:48:55 +02:00

32 lines
863 B
TypeScript

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);
});