4525 upgrade pg graphql (#4646)

* TO remove: add multiple workspace with command

* TO remove: update build script

* Update script and add doc

* TO remove: add more seed workspaces

* Build pg_graphql files for 1.5.1

* Build pg_graphql files for 1.5.1 macos arm

* Remove 600 seed workspaces

* Build pg_graphql files for 1.5.1 macos intel
This commit is contained in:
martmull 2024-03-25 15:08:17 +01:00 committed by GitHub
parent e576fe0d67
commit e2af5b8628
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 539 additions and 16 deletions

View File

@ -3,7 +3,7 @@ ARG IMAGE_TAG='15.5.0-debian-11-r15'
FROM bitnami/postgresql:${IMAGE_TAG}
ARG PG_MAIN_VERSION=15
ARG PG_GRAPHQL_VERSION=1.4.2
ARG PG_GRAPHQL_VERSION=1.5.1
ARG WRAPPERS_VERSION=0.2.0
ARG TARGETARCH

View File

@ -0,0 +1,12 @@
ARG IMAGE_TAG='15.5.0-debian-11-r15'
FROM bitnami/postgresql:${IMAGE_TAG}
ARG PG_MAIN_VERSION=15
ARG PG_GRAPHQL_VERSION=1.5.1
ARG WRAPPERS_VERSION=0.2.0
ARG TARGETARCH
USER root
CMD ["tail", "-f", "/dev/null"]

View File

@ -0,0 +1,116 @@
/*
This file is auto generated by pgrx.
The ordering of items is not stable, it is driven by a dependency graph.
*/
-- src/lib.rs:27
-- pg_graphql::_internal_resolve
CREATE FUNCTION graphql."_internal_resolve"(
"query" TEXT, /* &str */
"variables" jsonb DEFAULT '{}', /* core::option::Option<pgrx::datum::json::JsonB> */
"operationName" TEXT DEFAULT null, /* core::option::Option<alloc::string::String> */
"extensions" jsonb DEFAULT null /* core::option::Option<pgrx::datum::json::JsonB> */
) RETURNS jsonb /* pgrx::datum::json::JsonB */
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'resolve_wrapper';
-- src/lib.rs:23
-- requires:
-- resolve
create or replace function graphql.resolve(
"query" text,
"variables" jsonb default '{}',
"operationName" text default null,
"extensions" jsonb default null
)
returns jsonb
language plpgsql
as $$
declare
res jsonb;
message_text text;
begin
begin
select graphql._internal_resolve("query" := "query",
"variables" := "variables",
"operationName" := "operationName",
"extensions" := "extensions") into res;
return res;
exception
when others then
get stacked diagnostics message_text = message_text;
return
jsonb_build_object('data', null,
'errors', jsonb_build_array(jsonb_build_object('message', message_text)));
end;
end;
$$;
-- src/lib.rs:22
create or replace function graphql.exception(message text)
returns text
language plpgsql
as $$
begin
raise exception using errcode='22000', message=message;
end;
$$;
-- src/lib.rs:20
-- Is updated every time the schema changes
create sequence if not exists graphql.seq_schema_version as int cycle;
create or replace function graphql.increment_schema_version()
returns event_trigger
security definer
language plpgsql
as $$
begin
perform nextval('graphql.seq_schema_version');
end;
$$;
create or replace function graphql.get_schema_version()
returns int
security definer
language sql
as $$
select last_value from graphql.seq_schema_version;
$$;
-- On DDL event, increment the schema version number
create event trigger graphql_watch_ddl
on ddl_command_end
execute procedure graphql.increment_schema_version();
create event trigger graphql_watch_drop
on sql_drop
execute procedure graphql.increment_schema_version();
-- src/lib.rs:21
create function graphql.comment_directive(comment_ text)
returns jsonb
language sql
immutable
as $$
/*
comment on column public.account.name is '@graphql.name: myField'
*/
select
coalesce(
(
regexp_match(
comment_,
'@graphql\((.+?)\)'
)
)[1]::jsonb,
jsonb_build_object()
)
$$;

View File

@ -0,0 +1,6 @@
comment = 'pg_graphql: GraphQL support'
default_version = '1.5.1'
module_pathname = '$libdir/pg_graphql'
relocatable = false
superuser = true
schema = 'graphql'

Binary file not shown.

View File

@ -0,0 +1,116 @@
/*
This file is auto generated by pgrx.
The ordering of items is not stable, it is driven by a dependency graph.
*/
-- src/lib.rs:27
-- pg_graphql::_internal_resolve
CREATE FUNCTION graphql."_internal_resolve"(
"query" TEXT, /* &str */
"variables" jsonb DEFAULT '{}', /* core::option::Option<pgrx::datum::json::JsonB> */
"operationName" TEXT DEFAULT null, /* core::option::Option<alloc::string::String> */
"extensions" jsonb DEFAULT null /* core::option::Option<pgrx::datum::json::JsonB> */
) RETURNS jsonb /* pgrx::datum::json::JsonB */
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'resolve_wrapper';
-- src/lib.rs:21
create function graphql.comment_directive(comment_ text)
returns jsonb
language sql
immutable
as $$
/*
comment on column public.account.name is '@graphql.name: myField'
*/
select
coalesce(
(
regexp_match(
comment_,
'@graphql\((.+?)\)'
)
)[1]::jsonb,
jsonb_build_object()
)
$$;
-- src/lib.rs:20
-- Is updated every time the schema changes
create sequence if not exists graphql.seq_schema_version as int cycle;
create or replace function graphql.increment_schema_version()
returns event_trigger
security definer
language plpgsql
as $$
begin
perform nextval('graphql.seq_schema_version');
end;
$$;
create or replace function graphql.get_schema_version()
returns int
security definer
language sql
as $$
select last_value from graphql.seq_schema_version;
$$;
-- On DDL event, increment the schema version number
create event trigger graphql_watch_ddl
on ddl_command_end
execute procedure graphql.increment_schema_version();
create event trigger graphql_watch_drop
on sql_drop
execute procedure graphql.increment_schema_version();
-- src/lib.rs:22
create or replace function graphql.exception(message text)
returns text
language plpgsql
as $$
begin
raise exception using errcode='22000', message=message;
end;
$$;
-- src/lib.rs:23
-- requires:
-- resolve
create or replace function graphql.resolve(
"query" text,
"variables" jsonb default '{}',
"operationName" text default null,
"extensions" jsonb default null
)
returns jsonb
language plpgsql
as $$
declare
res jsonb;
message_text text;
begin
begin
select graphql._internal_resolve("query" := "query",
"variables" := "variables",
"operationName" := "operationName",
"extensions" := "extensions") into res;
return res;
exception
when others then
get stacked diagnostics message_text = message_text;
return
jsonb_build_object('data', null,
'errors', jsonb_build_array(jsonb_build_object('message', message_text)));
end;
end;
$$;

View File

@ -0,0 +1,6 @@
comment = 'pg_graphql: GraphQL support'
default_version = '1.5.1'
module_pathname = '$libdir/pg_graphql'
relocatable = false
superuser = true
schema = 'graphql'

Binary file not shown.

View File

@ -48,15 +48,15 @@ EOF
echo_header $BLUE " DATABASE SETUP"
PG_MAIN_VERSION=15
PG_GRAPHQL_VERSION=1.4.2
CARGO_PGRX_VERSION=0.10.2
PG_GRAPHQL_VERSION=1.5.1
CARGO_PGRX_VERSION=0.11.2
TARGETARCH=$(dpkg --print-architecture)
# Install PostgresSQL
echo_header $GREEN "Step [1/4]: Installing PostgreSQL..."
apt update -y || handle_error "Failed to update package list."
apt install -y postgresql-$PG_MAIN_VERSION postgresql-contrib || handle_error "Failed to install PostgreSQL."su
apt install -y curl || handle_error "Failed to install curl."
apt install -y sudo || handle_error "Failed to install sudo."
apt install build-essential -y || handle_error "Failed to install build-essential."
apt install pkg-config -y || handle_error "Failed to install pkg-config."
apt install libssl-dev -y || handle_error "Failed to install libssl-dev."
@ -77,9 +77,9 @@ fi
# To force a reinstall of cargo-pgrx, pass --force to the command below
curl https://sh.rustup.rs -sSf | sh
source "$HOME/.cargo/env"
cargo install --locked cargo-pgrx@$CARGO_PGRX_VERSION --force
cargo pgrx init --pg$PG_MAIN_VERSION download
source "$HOME/.cargo/env" || . "$HOME/.cargo/env"
cargo install --locked cargo-pgrx@$CARGO_PGRX_VERSION --force || handle_error "Failed to install cargo"
cargo pgrx init --pg$PG_MAIN_VERSION download || handle_error "Failed to init postgresql"
# Create a temporary directory
temp_dir=$(mktemp -d)
@ -93,12 +93,13 @@ cd "pg_graphql-$PG_GRAPHQL_VERSION"
# Apply patches to pg_graphql files
echo "Applying patches to pg_graphql files..."
for patch_file in "/patches/pg_graphql/"*.patch; do
for patch_file in "/twenty/patches/pg_graphql/"*.patch; do
echo "Applying patch: $patch_file"
patch -p1 < "$patch_file"
done
cargo pgrx install --release --pg-config /opt/bitnami/postgresql/bin/pg_config
echo_header $GREEN "Step [2/4]: Building PostgreSQL service..."
cargo pgrx install --release --pg-config /opt/bitnami/postgresql/bin/pg_config || handle_error "Failed to build postgresql"
# Clean up the temporary directory

View File

@ -0,0 +1,22 @@
This doc explains how to build postgresql for Twenty
Build .control, .so and .pg_graphql--version.sql
> docker buildx create --name mybuilder
> docker buildx use mybuilder
Do the same for <PLATFORM> in ['amd64', 'arm64'] ('amd64' builds faster)
> cd packages/twenty-postgres
> docker buildx build --platform linux/<PLATFORM> --load -t twenty-bitnami-postgres-<PLATFORM> linux
> docker run --name twenty-bitnami-<PLATFORM> -v ~/Desktop/twenty/packages/twenty-postgres:/twenty <IMAGE_TAG>
In another terminal
> docker exec -it <CONTAINER_TAG> sh
> sh twenty/linux/build-postgres-linux.sh
> cp opt/bitnami/postgresql/lib/pg_graphql.so twenty/linux/<PLATFORM>/15/pg_graphql/<PG_GRAPHQL_VERSION>
> cp opt/bitnami/postgresql/share/extension/pg_graphql.control twenty/linux/<PLATFORM>/15/pg_graphql/<PG_GRAPHQL_VERSION>
> cp opt/bitnami/postgresql/share/extension/pg_graphql--<PG_GRAPHQL_VERSION>.sql twenty/linux/<PLATFORM>/15/pg_graphql/<PG_GRAPHQL_VERSION>
Then
> prod-server-build
> prod-server-run

View File

@ -48,7 +48,7 @@ EOF
echo_header $BLUE " DATABASE SETUP"
PG_MAIN_VERSION=15
PG_GRAPHQL_VERSION=1.3.0
PG_GRAPHQL_VERSION=1.5.1
TARGETARCH=$(dpkg --print-architecture)
# Install PostgresSQL

View File

@ -0,0 +1,116 @@
/*
This file is auto generated by pgrx.
The ordering of items is not stable, it is driven by a dependency graph.
*/
-- src/lib.rs:27
-- pg_graphql::_internal_resolve
CREATE FUNCTION graphql."_internal_resolve"(
"query" TEXT, /* &str */
"variables" jsonb DEFAULT '{}', /* core::option::Option<pgrx::datum::json::JsonB> */
"operationName" TEXT DEFAULT null, /* core::option::Option<alloc::string::String> */
"extensions" jsonb DEFAULT null /* core::option::Option<pgrx::datum::json::JsonB> */
) RETURNS jsonb /* pgrx::datum::json::JsonB */
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'resolve_wrapper';
-- src/lib.rs:21
create function graphql.comment_directive(comment_ text)
returns jsonb
language sql
immutable
as $$
/*
comment on column public.account.name is '@graphql.name: myField'
*/
select
coalesce(
(
regexp_match(
comment_,
'@graphql\((.+?)\)'
)
)[1]::jsonb,
jsonb_build_object()
)
$$;
-- src/lib.rs:22
create or replace function graphql.exception(message text)
returns text
language plpgsql
as $$
begin
raise exception using errcode='22000', message=message;
end;
$$;
-- src/lib.rs:23
-- requires:
-- resolve
create or replace function graphql.resolve(
"query" text,
"variables" jsonb default '{}',
"operationName" text default null,
"extensions" jsonb default null
)
returns jsonb
language plpgsql
as $$
declare
res jsonb;
message_text text;
begin
begin
select graphql._internal_resolve("query" := "query",
"variables" := "variables",
"operationName" := "operationName",
"extensions" := "extensions") into res;
return res;
exception
when others then
get stacked diagnostics message_text = message_text;
return
jsonb_build_object('data', null,
'errors', jsonb_build_array(jsonb_build_object('message', message_text)));
end;
end;
$$;
-- src/lib.rs:20
-- Is updated every time the schema changes
create sequence if not exists graphql.seq_schema_version as int cycle;
create or replace function graphql.increment_schema_version()
returns event_trigger
security definer
language plpgsql
as $$
begin
perform nextval('graphql.seq_schema_version');
end;
$$;
create or replace function graphql.get_schema_version()
returns int
security definer
language sql
as $$
select last_value from graphql.seq_schema_version;
$$;
-- On DDL event, increment the schema version number
create event trigger graphql_watch_ddl
on ddl_command_end
execute procedure graphql.increment_schema_version();
create event trigger graphql_watch_drop
on sql_drop
execute procedure graphql.increment_schema_version();

View File

@ -0,0 +1,6 @@
comment = 'pg_graphql: GraphQL support'
default_version = '1.5.1'
module_pathname = '$libdir/pg_graphql'
relocatable = false
superuser = true
schema = 'graphql'

Binary file not shown.

View File

@ -48,8 +48,8 @@ EOF
echo_header $BLUE " DATABASE SETUP"
PG_MAIN_VERSION=15
PG_GRAPHQL_VERSION=1.4.2
CARGO_PGRX_VERSION=0.10.2
PG_GRAPHQL_VERSION=1.5.1
CARGO_PGRX_VERSION=0.11.2
current_directory=$(pwd)
script_directory="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

View File

@ -1,7 +1,7 @@
#!/bin/bash
PG_MAIN_VERSION=15
PG_GRAPHQL_VERSION=1.4.2
PG_GRAPHQL_VERSION=1.5.1
current_directory=$(pwd)

View File

@ -0,0 +1,116 @@
/*
This file is auto generated by pgrx.
The ordering of items is not stable, it is driven by a dependency graph.
*/
-- src/lib.rs:27
-- pg_graphql::_internal_resolve
CREATE FUNCTION graphql."_internal_resolve"(
"query" TEXT, /* &str */
"variables" jsonb DEFAULT '{}', /* core::option::Option<pgrx::datum::json::JsonB> */
"operationName" TEXT DEFAULT null, /* core::option::Option<alloc::string::String> */
"extensions" jsonb DEFAULT null /* core::option::Option<pgrx::datum::json::JsonB> */
) RETURNS jsonb /* pgrx::datum::json::JsonB */
LANGUAGE c /* Rust */
AS 'MODULE_PATHNAME', 'resolve_wrapper';
-- src/lib.rs:23
-- requires:
-- resolve
create or replace function graphql.resolve(
"query" text,
"variables" jsonb default '{}',
"operationName" text default null,
"extensions" jsonb default null
)
returns jsonb
language plpgsql
as $$
declare
res jsonb;
message_text text;
begin
begin
select graphql._internal_resolve("query" := "query",
"variables" := "variables",
"operationName" := "operationName",
"extensions" := "extensions") into res;
return res;
exception
when others then
get stacked diagnostics message_text = message_text;
return
jsonb_build_object('data', null,
'errors', jsonb_build_array(jsonb_build_object('message', message_text)));
end;
end;
$$;
-- src/lib.rs:22
create or replace function graphql.exception(message text)
returns text
language plpgsql
as $$
begin
raise exception using errcode='22000', message=message;
end;
$$;
-- src/lib.rs:21
create function graphql.comment_directive(comment_ text)
returns jsonb
language sql
immutable
as $$
/*
comment on column public.account.name is '@graphql.name: myField'
*/
select
coalesce(
(
regexp_match(
comment_,
'@graphql\((.+?)\)'
)
)[1]::jsonb,
jsonb_build_object()
)
$$;
-- src/lib.rs:20
-- Is updated every time the schema changes
create sequence if not exists graphql.seq_schema_version as int cycle;
create or replace function graphql.increment_schema_version()
returns event_trigger
security definer
language plpgsql
as $$
begin
perform nextval('graphql.seq_schema_version');
end;
$$;
create or replace function graphql.get_schema_version()
returns int
security definer
language sql
as $$
select last_value from graphql.seq_schema_version;
$$;
-- On DDL event, increment the schema version number
create event trigger graphql_watch_ddl
on ddl_command_end
execute procedure graphql.increment_schema_version();
create event trigger graphql_watch_drop
on sql_drop
execute procedure graphql.increment_schema_version();

View File

@ -0,0 +1,6 @@
comment = 'pg_graphql: GraphQL support'
default_version = '1.5.1'
module_pathname = '$libdir/pg_graphql'
relocatable = false
superuser = true
schema = 'graphql'

View File

@ -48,8 +48,8 @@ EOF
echo_header $BLUE " DATABASE SETUP"
PG_MAIN_VERSION=15
PG_GRAPHQL_VERSION=1.4.2
CARGO_PGRX_VERSION=0.10.2
PG_GRAPHQL_VERSION=1.5.1
CARGO_PGRX_VERSION=0.11.2
current_directory=$(pwd)
script_directory="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

View File

@ -1,7 +1,7 @@
#!/bin/bash
PG_MAIN_VERSION=15
PG_GRAPHQL_VERSION=1.3.0
PG_GRAPHQL_VERSION=1.5.1
current_directory=$(pwd)