twenty/server/scripts/setup-db.ts
martmull ba69435339
0.2.0 cleaning script (#2342)
* Display maxUpdatedAt for each workspace Schema

* Factorize functions

* Add max update for public workspaces

* Merge everything in a single json

* Enrich results

* Get from proper table

* Update

* Move to proper command file

* Add a dry-run option

* Remove workspaces from database

* Fix DeleteWorkspace method

* Add new option

* Remove proper data when deleting workspace

* Minor improvements
2023-11-06 23:15:02 +01:00

57 lines
1.4 KiB
TypeScript

import console from 'console';
import { connectionSource, performQuery } from './utils';
connectionSource
.initialize()
.then(async () => {
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 EXTENSION IF NOT EXISTS pg_graphql',
'create extension pg_graphql',
);
await performQuery(
'CREATE EXTENSION IF NOT EXISTS "uuid-ossp"',
'create extension "uuid-ossp"',
);
await performQuery(
`COMMENT ON SCHEMA "public" IS '@graphql({"inflect_names": true})';`,
'inflect names for graphql',
);
await performQuery(
`
DROP FUNCTION IF EXISTS graphql;
CREATE FUNCTION graphql(
"operationName" text default null,
query text default null,
variables jsonb default null,
extensions jsonb default null
)
returns jsonb
language sql
as $$
select graphql.resolve(
query := query,
variables := coalesce(variables, '{}'),
"operationName" := "operationName",
extensions := extensions
);
$$;
`,
'create function graphql',
);
})
.catch((err) => {
console.error('Error during Data Source initialization:', err);
});