mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-23 20:13:21 +03:00
34a3a66451
I don't think that will solve the flaky test but at least it will cleanup the error message to avoid confusion
88 lines
2.1 KiB
TypeScript
88 lines
2.1 KiB
TypeScript
import console from 'console';
|
|
|
|
import { rawDataSource } from 'src/database/typeorm/raw/raw.datasource';
|
|
|
|
import { camelToSnakeCase, performQuery } from './utils';
|
|
|
|
rawDataSource
|
|
.initialize()
|
|
.then(async () => {
|
|
await performQuery(
|
|
'CREATE EXTENSION IF NOT EXISTS "vector"',
|
|
'create extension "vector (pgvector)"',
|
|
);
|
|
|
|
await performQuery(
|
|
'CREATE SCHEMA IF NOT EXISTS "public"',
|
|
'create schema "public"',
|
|
);
|
|
await performQuery(
|
|
'CREATE SCHEMA IF NOT EXISTS "metadata"',
|
|
'create schema "metadata"',
|
|
);
|
|
await performQuery(
|
|
'CREATE SCHEMA IF NOT EXISTS "core"',
|
|
'create schema "core"',
|
|
);
|
|
|
|
await performQuery(
|
|
'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"',
|
|
'create extension "uuid-ossp"',
|
|
);
|
|
|
|
await performQuery(
|
|
'CREATE EXTENSION IF NOT EXISTS "postgres_fdw"',
|
|
'create extension "postgres_fdw"',
|
|
);
|
|
|
|
await performQuery(
|
|
'CREATE EXTENSION IF NOT EXISTS "wrappers"',
|
|
'create extension "wrappers"',
|
|
);
|
|
|
|
await performQuery(
|
|
'CREATE EXTENSION IF NOT EXISTS "mysql_fdw"',
|
|
'create extension "mysql_fdw"',
|
|
);
|
|
|
|
const supabaseWrappers = [
|
|
'airtable',
|
|
'bigQuery',
|
|
'clickHouse',
|
|
'firebase',
|
|
'logflare',
|
|
's3',
|
|
'stripe',
|
|
]; // See https://supabase.github.io/wrappers/
|
|
|
|
for (const wrapper of supabaseWrappers) {
|
|
if (await checkForeignDataWrapperExists(wrapper)) {
|
|
continue;
|
|
}
|
|
await performQuery(
|
|
`
|
|
CREATE FOREIGN DATA WRAPPER "${wrapper.toLowerCase()}_fdw"
|
|
HANDLER "${camelToSnakeCase(wrapper)}_fdw_handler"
|
|
VALIDATOR "${camelToSnakeCase(wrapper)}_fdw_validator";
|
|
`,
|
|
`create ${wrapper} "wrappers"`,
|
|
true,
|
|
true,
|
|
);
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
console.error('Error during Data Source initialization:', err);
|
|
});
|
|
|
|
async function checkForeignDataWrapperExists(
|
|
wrapperName: string,
|
|
): Promise<boolean> {
|
|
const result = await rawDataSource.query(
|
|
`SELECT 1 FROM pg_foreign_data_wrapper WHERE fdwname = $1`,
|
|
[wrapperName],
|
|
);
|
|
|
|
return result.length > 0;
|
|
}
|