mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-19 17:42:27 +03:00
2d758c990b
* Fix merge issue flexible backend * Fix tests * Try fix tests * Try fix tests
57 lines
1.1 KiB
TypeScript
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();
|
|
});
|