twenty/server/test/utils/check-db.ts
Jérémy M 157e5b9a2e
feat: implement e2e test for CompanyResolver (#944)
* feat: wip e2e server test

* feat: use github action postgres & use infra for local

* feat: company e2e test

* feat: add company e2e test for permissions

* Simplify server e2e test run

* Fix lint

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2023-07-27 09:48:40 -07:00

42 lines
914 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;
}
};
async function main() {
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();
});