We will remove the `twenty-postgres` image that was used for local development and only use `twenty-postgres-pilo` (which we use in prod), bringing the development environment closer to prod and avoiding having to maintain 2 images. Instead of provisioning the super user after the db initialization, we directly rely on the superuser provided by Spilo for simplicity. We also introduce a change that tries to create the right database (`default` or `test`) based on the context. How to test: ``` docker build -t twentycrm/twenty-postgres-spilo:latest -f ./packages/twenty-docker/twenty-postgres-spilo/Dockerfile . docker images --no-trunc | grep twenty-postgres-spilo postgres-on-docker: docker run \ --name twenty_pg \ -e PGUSER_SUPERUSER=twenty \ -e PGPASSWORD_SUPERUSER=twenty \ -e ALLOW_NOSSL=true \ -v twenty_db_data:/home/postgres/pgdata \ -p 5432:5432 \ REPLACE_WITH_IMAGE_ID ```
74 lines
1.8 KiB
TypeScript
74 lines
1.8 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) {
|
|
await performQuery(
|
|
`
|
|
CREATE FOREIGN DATA WRAPPER IF NOT EXISTS "${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);
|
|
});
|