mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-20 10:11:48 +03:00
00a3c8ca2b
* Change to using arrow functions Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Add lint rule --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
42 lines
918 B
TypeScript
42 lines
918 B
TypeScript
// check-db.ts
|
|
|
|
import { PrismaClient } from '@prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
const schemaDatabaseExists = async (databaseName: string) => {
|
|
try {
|
|
const result = await prisma.$queryRawUnsafe<[any]>(
|
|
`SELECT 1 FROM pg_database WHERE datname = '${databaseName}';`,
|
|
);
|
|
|
|
return result.length > 0;
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
const main = async () => {
|
|
const databaseName = 'tests';
|
|
// Check if schema exists
|
|
const databaseExistsResult = await schemaDatabaseExists(databaseName);
|
|
|
|
if (!databaseExistsResult) {
|
|
throw new Error(`Schema ${databaseName} does not exist`);
|
|
}
|
|
|
|
// Check if database is initialized
|
|
await prisma.$queryRaw`SELECT 1 FROM pg_tables WHERE tablename='_prisma_migrations';`;
|
|
};
|
|
|
|
main()
|
|
.then(() => {
|
|
process.exit(0);
|
|
})
|
|
.catch(() => {
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|