twenty/server/test/utils/setup-db.ts
Charles Bochet 2d758c990b
Fix merge issue flexible backend (#1685)
* Fix merge issue flexible backend

* Fix tests

* Try fix tests

* Try fix tests
2023-09-20 19:11:21 -07:00

57 lines
1.1 KiB
TypeScript

// check-db.ts
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const createMetadataSchema = async () => {
try {
await prisma.$queryRawUnsafe<[any]>(
`CREATE SCHEMA IF NOT EXISTS "metadata";`,
);
await prisma.$queryRawUnsafe<[any]>(
`GRANT ALL ON SCHEMA metadata TO twenty;`,
);
return true;
} catch {
return false;
}
};
const activateUUIDExtension = async () => {
try {
const result = await prisma.$queryRawUnsafe<[any]>(
`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`,
);
return result;
} catch {
return false;
}
};
const main = async () => {
const metadataSchemaCreationSuccess = await createMetadataSchema();
const uuidExtensionActivationSuccess = await activateUUIDExtension();
if (!metadataSchemaCreationSuccess) {
throw new Error(`Failed to create metadata schema`);
}
if (!uuidExtensionActivationSuccess) {
throw new Error(`Failed to activate uuid extension`);
}
};
main()
.then(() => {
process.exit(0);
})
.catch(() => {
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});