2023-10-14 14:43:45 +03:00
|
|
|
import console from 'console';
|
|
|
|
|
2023-11-07 01:15:02 +03:00
|
|
|
import { connectionSource, performQuery } from './utils';
|
2023-10-14 14:43:45 +03:00
|
|
|
|
2023-10-14 12:48:55 +03:00
|
|
|
connectionSource
|
|
|
|
.initialize()
|
|
|
|
.then(async () => {
|
2023-10-27 18:48:06 +03:00
|
|
|
await performQuery(
|
|
|
|
'CREATE SCHEMA IF NOT EXISTS "public"',
|
|
|
|
'create schema "public"',
|
|
|
|
);
|
2023-10-14 14:43:45 +03:00
|
|
|
await performQuery(
|
|
|
|
'CREATE SCHEMA IF NOT EXISTS "metadata"',
|
|
|
|
'create schema "metadata"',
|
|
|
|
);
|
2023-11-19 20:25:47 +03:00
|
|
|
await performQuery(
|
|
|
|
'CREATE SCHEMA IF NOT EXISTS "core"',
|
|
|
|
'create schema "core"',
|
|
|
|
);
|
2023-10-14 14:43:45 +03:00
|
|
|
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"',
|
|
|
|
);
|
|
|
|
|
2023-10-14 23:40:05 +03:00
|
|
|
await performQuery(
|
2023-11-19 20:25:47 +03:00
|
|
|
`COMMENT ON SCHEMA "core" IS '@graphql({"inflect_names": true})';`,
|
2023-10-14 23:40:05 +03:00
|
|
|
'inflect names for graphql',
|
|
|
|
);
|
|
|
|
|
2023-10-14 14:43:45 +03:00
|
|
|
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',
|
|
|
|
);
|
2023-10-14 12:48:55 +03:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error('Error during Data Source initialization:', err);
|
|
|
|
});
|