mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-27 01:05:08 +03:00
Build linux pg graphql (#3206)
* Build pg_graphql for linux * Build for amd * Fixes
This commit is contained in:
parent
974498d57a
commit
41f3a74bf4
@ -27,10 +27,12 @@ RUN set -eux; \
|
|||||||
RUN apt update && apt install build-essential git curl default-libmysqlclient-dev -y
|
RUN apt update && apt install build-essential git curl default-libmysqlclient-dev -y
|
||||||
|
|
||||||
# Install precompiled pg_graphql extensions
|
# Install precompiled pg_graphql extensions
|
||||||
RUN curl -L "https://github.com/supabase/pg_graphql/releases/download/v${PG_GRAPHQL_VERSION}/pg_graphql-v${PG_GRAPHQL_VERSION}-pg${PG_MAIN_VERSION}-${TARGETARCH}-linux-gnu.deb" -o pg_graphql.deb
|
COPY ./packages/twenty-postgres/linux/${TARGETARCH}/${PG_MAIN_VERSION}/pg_graphql/${PG_GRAPHQL_VERSION}/pg_graphql--${PG_GRAPHQL_VERSION}.sql \
|
||||||
RUN dpkg --install pg_graphql.deb
|
/opt/bitnami/postgresql/share/extension/
|
||||||
RUN cp /usr/share/postgresql/${PG_MAIN_VERSION}/extension/pg_graphql* /opt/bitnami/postgresql/share/extension/
|
COPY ./packages/twenty-postgres/linux/${TARGETARCH}/${PG_MAIN_VERSION}/pg_graphql/${PG_GRAPHQL_VERSION}/pg_graphql.control \
|
||||||
RUN cp /usr/lib/postgresql/${PG_MAIN_VERSION}/lib/pg_graphql* /opt/bitnami/postgresql/lib/
|
/opt/bitnami/postgresql/share/extension/
|
||||||
|
COPY ./packages/twenty-postgres/linux/${TARGETARCH}/${PG_MAIN_VERSION}/pg_graphql/${PG_GRAPHQL_VERSION}/pg_graphql.so \
|
||||||
|
/opt/bitnami/postgresql/lib/
|
||||||
|
|
||||||
# Install precompiled supabase wrappers extensions
|
# Install precompiled supabase wrappers extensions
|
||||||
RUN curl -L "https://github.com/supabase/wrappers/releases/download/v${WRAPPERS_VERSION}/wrappers-v${WRAPPERS_VERSION}-pg${PG_MAIN_VERSION}-${TARGETARCH}-linux-gnu.deb" -o wrappers.deb
|
RUN curl -L "https://github.com/supabase/wrappers/releases/download/v${WRAPPERS_VERSION}/wrappers-v${WRAPPERS_VERSION}-pg${PG_MAIN_VERSION}-${TARGETARCH}-linux-gnu.deb" -o wrappers.deb
|
||||||
|
116
packages/twenty-postgres/linux/amd64/15/pg_graphql/1.4.2/pg_graphql--1.4.2.sql
vendored
Normal file
116
packages/twenty-postgres/linux/amd64/15/pg_graphql/1.4.2/pg_graphql--1.4.2.sql
vendored
Normal 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:26
|
||||||
|
-- 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 or replace function graphql.exception(message text)
|
||||||
|
returns text
|
||||||
|
language plpgsql
|
||||||
|
as $$
|
||||||
|
begin
|
||||||
|
raise exception using errcode='22000', message=message;
|
||||||
|
end;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
|
||||||
|
-- src/lib.rs:19
|
||||||
|
-- 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
|
||||||
|
-- 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
|
||||||
|
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()
|
||||||
|
)
|
||||||
|
$$;
|
||||||
|
|
6
packages/twenty-postgres/linux/amd64/15/pg_graphql/1.4.2/pg_graphql.control
vendored
Normal file
6
packages/twenty-postgres/linux/amd64/15/pg_graphql/1.4.2/pg_graphql.control
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
comment = 'pg_graphql: GraphQL support'
|
||||||
|
default_version = '1.4.2'
|
||||||
|
module_pathname = '$libdir/pg_graphql'
|
||||||
|
relocatable = false
|
||||||
|
superuser = true
|
||||||
|
schema = 'graphql'
|
BIN
packages/twenty-postgres/linux/amd64/15/pg_graphql/1.4.2/pg_graphql.so
vendored
Executable file
BIN
packages/twenty-postgres/linux/amd64/15/pg_graphql/1.4.2/pg_graphql.so
vendored
Executable file
Binary file not shown.
116
packages/twenty-postgres/linux/arm64/15/pg_graphql/1.4.2/pg_graphql--1.4.2.sql
vendored
Normal file
116
packages/twenty-postgres/linux/arm64/15/pg_graphql/1.4.2/pg_graphql--1.4.2.sql
vendored
Normal 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:26
|
||||||
|
-- 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:19
|
||||||
|
-- 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
|
||||||
|
-- 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:21
|
||||||
|
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
|
||||||
|
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()
|
||||||
|
)
|
||||||
|
$$;
|
||||||
|
|
6
packages/twenty-postgres/linux/arm64/15/pg_graphql/1.4.2/pg_graphql.control
vendored
Normal file
6
packages/twenty-postgres/linux/arm64/15/pg_graphql/1.4.2/pg_graphql.control
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
comment = 'pg_graphql: GraphQL support'
|
||||||
|
default_version = '1.4.2'
|
||||||
|
module_pathname = '$libdir/pg_graphql'
|
||||||
|
relocatable = false
|
||||||
|
superuser = true
|
||||||
|
schema = 'graphql'
|
BIN
packages/twenty-postgres/linux/arm64/15/pg_graphql/1.4.2/pg_graphql.so
vendored
Executable file
BIN
packages/twenty-postgres/linux/arm64/15/pg_graphql/1.4.2/pg_graphql.so
vendored
Executable file
Binary file not shown.
120
packages/twenty-postgres/linux/build-postgres-linux.sh
Executable file
120
packages/twenty-postgres/linux/build-postgres-linux.sh
Executable file
@ -0,0 +1,120 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED=31
|
||||||
|
GREEN=32
|
||||||
|
BLUE=34
|
||||||
|
|
||||||
|
# Function to display colored output
|
||||||
|
echo_header () {
|
||||||
|
COLOR=$1
|
||||||
|
MESSAGE=$2
|
||||||
|
echo "\e[${COLOR}m\n=======================================================\e[0m"
|
||||||
|
echo "\e[${COLOR}m${MESSAGE}\e[0m"
|
||||||
|
echo "\e[${COLOR}m=======================================================\e[0m"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to handle errors
|
||||||
|
handle_error () {
|
||||||
|
echo_header $RED "Error: $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
cat << "EOF"
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
@@@@@@@#*+=================@@@@@%*+=========++*%@@@@@@@
|
||||||
|
@@@@#- .+@@%=. .+@@@@@
|
||||||
|
@@@- .*@@%- .#@@@
|
||||||
|
@@= .=+++++++++++*#@@@= -++++++++++- %@@
|
||||||
|
@@. %@@@@@@@@@@@@@@@+ =%@@@@@@@@@@@@= +@@
|
||||||
|
@@. .@@@@@@@@@@@@@@+. -%@@@@@@@@@@@@@@+ +@@
|
||||||
|
@@. .@@@@@@@@@@@@*. -#@@#:=@@@@@@@@@@@= +@@
|
||||||
|
@@ @@@@@@@@@@#: :#@@#: -@@@@@@@@@@@= +@@
|
||||||
|
@@#====#@@@@@@@@#- .*@@@= -@@@@@@@@@@@= +@@
|
||||||
|
@@@@@@@@@@@@@@%- .*@@@@# -@@@@@@@@@@@= +@@
|
||||||
|
@@@@@@@@@@@@%= +@@@@@@# -@@@@@@@@@@@= +@@
|
||||||
|
@@@@@@@@@@@+ =@@@@@@@@# -@@@@@@@@@@@= +@@
|
||||||
|
@@@@@@@@@+. -%@@@@@@@@@# -@@@@@@@@@@@= +@@
|
||||||
|
@@@@@@@*. -%@@@@@@@@@@@# -@@@@@@@@@@@= +@@
|
||||||
|
@@@@@#: :#@@@@@@@@@@@@@# -@@@@@@@@@@@+ +@@
|
||||||
|
@@@#: :#@@@@@@@@@@@@@@@# :@@@@@@@@@@@= +@@
|
||||||
|
@@= :+*+++++++++++*%@@@. :+++++++++- %@@
|
||||||
|
@@ :@@@%. .#@@@
|
||||||
|
@@- :@@@@@+: .+@@@@@
|
||||||
|
@@@#+===================+%@@@@@@@%*++=======++*%@@@@@@@
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo_header $BLUE " DATABASE SETUP"
|
||||||
|
|
||||||
|
PG_MAIN_VERSION=15
|
||||||
|
PG_GRAPHQL_VERSION=1.4.2
|
||||||
|
CARGO_PGRX_VERSION=0.10.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 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."
|
||||||
|
apt install libreadline-dev -y || handle_error "Failed to install libreadline-dev."
|
||||||
|
apt install zlib1g-dev -y || handle_error "Failed to install zlib1g-dev."
|
||||||
|
apt install unzip -y || handle_error "Failed to install unzip."
|
||||||
|
apt install libclang-dev -y || handle_error "Failed to install libclang-dev."
|
||||||
|
|
||||||
|
# Install pg_graphql extensions
|
||||||
|
current_directory=$(pwd)
|
||||||
|
script_directory="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
|
||||||
|
existing_rust_path=$(which rustc)
|
||||||
|
if [ -n "$existing_rust_path" ]; then
|
||||||
|
echo "Uninstalling existing Rust installation..."
|
||||||
|
rm -rf "$existing_rust_path"
|
||||||
|
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
|
||||||
|
|
||||||
|
# Create a temporary directory
|
||||||
|
temp_dir=$(mktemp -d)
|
||||||
|
cd "$temp_dir"
|
||||||
|
|
||||||
|
curl -LJO https://github.com/supabase/pg_graphql/archive/refs/tags/v$PG_GRAPHQL_VERSION.zip || handle_error "Failed to download pg_graphql package."
|
||||||
|
|
||||||
|
unzip pg_graphql-$PG_GRAPHQL_VERSION.zip
|
||||||
|
|
||||||
|
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
|
||||||
|
echo "Applying patch: $patch_file"
|
||||||
|
patch -p1 < "$patch_file"
|
||||||
|
done
|
||||||
|
|
||||||
|
cargo pgrx install --release --pg-config /opt/bitnami/postgresql/bin/pg_config
|
||||||
|
|
||||||
|
|
||||||
|
# Clean up the temporary directory
|
||||||
|
echo "Cleaning up..."
|
||||||
|
cd "$current_directory"
|
||||||
|
rm -rf "$temp_dir"
|
||||||
|
|
||||||
|
# Start postgresql service
|
||||||
|
echo_header $GREEN "Step [3/4]: Starting PostgreSQL service..."
|
||||||
|
if sudo service postgresql start; then
|
||||||
|
echo "PostgreSQL service started successfully."
|
||||||
|
else
|
||||||
|
handle_error "Failed to start PostgreSQL service."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run the init.sql to setup database
|
||||||
|
echo_header $GREEN "Step [4/4]: Setting up database..."
|
||||||
|
cp ./init.sql /tmp/init.sql
|
||||||
|
sudo -u postgres psql -f /tmp/init.sql || handle_error "Failed to execute init.sql script."
|
Loading…
Reference in New Issue
Block a user