Skip to content

Commit 0f31d4e

Browse files
committed
chore: consolidate start-server, start-client and check harness
1 parent d674b4f commit 0f31d4e

File tree

3 files changed

+136
-187
lines changed

3 files changed

+136
-187
lines changed

flake.nix

Lines changed: 19 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -599,129 +599,57 @@
599599
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
600600
pg_regress = basePackages.pg_regress;
601601
getkeyScript = ./nix/tests/util/pgsodium_getkey.sh;
602-
migrationsDir = ./migrations/db;
603-
postgresqlSchemaSql = ./nix/tools/postgresql_schema.sql;
604-
pgbouncerAuthSchemaSql = ./ansible/files/pgbouncer_config/pgbouncer_auth_schema.sql;
605-
statExtensionSql = ./ansible/files/stat_extension.sql;
606602

607-
# Function to get the version argument for start-server
608603
getVersionArg = pkg:
609604
let
610605
name = pkg.version;
611606
in
612607
if builtins.match "15.*" name != null then "15"
613608
else if builtins.match "16.*" name != null then "16"
614-
else if builtins.match "17,*" name != null then "orioledb-17"
609+
else if builtins.match "17.*" name != null then "orioledb-17"
615610
else throw "Unsupported PostgreSQL version: ${name}";
616611
in
617612
pkgs.runCommand "postgres-${pgpkg.version}-check-harness"
618613
{
619614
nativeBuildInputs = with pkgs; [
620-
coreutils bash pgpkg pg_prove pg_regress procps
615+
coreutils bash pgpkg pg_prove pg_regress procps overmind
621616
basePackages.start-server
622617
];
623618
} ''
624619
cleanup() {
625620
echo "Cleaning up..."
626-
if [[ "$(uname)" == "Darwin" ]]; then
627-
for pid in $(ps -ax | grep "[p]ostgres" | awk '{print $1}'); do
628-
echo "Killing PostgreSQL process $pid"
629-
kill $pid 2>/dev/null || true
630-
done
631-
else
632-
for pid in $(pgrep postgres); do
633-
echo "Killing PostgreSQL process $pid"
634-
kill $pid 2>/dev/null || true
635-
done
636-
fi
621+
@OVERMIND@ quit || true
637622
exit $1
638623
}
639624
640625
trap 'cleanup 1' ERR
641626
set -e
642627
643-
# Start the server using the version-specific argument
644628
export KEY_FILE="${getkeyScript}"
645-
start-postgres-server ${getVersionArg pgpkg} &
646-
# Wait for server to be ready
629+
start-postgres-server ${getVersionArg pgpkg} --daemonize
630+
647631
for i in {1..60}; do
648-
if pg_isready -h localhost -p 5435; then
649-
echo "PostgreSQL is ready"
650-
break
651-
fi
652-
sleep 1
653-
if [ $i -eq 60 ]; then
654-
echo "PostgreSQL is not ready after 60 seconds"
655-
echo "PostgreSQL status:"
656-
pg_ctl -D "$PGDATA" status
657-
echo "PostgreSQL log content:"
658-
cat $TMPDIR/logfile/postgresql.log
659-
cleanup 1
660-
fi
632+
if pg_isready -h localhost -p 5435 -U supabase_admin -q; then
633+
echo "PostgreSQL is ready"
634+
break
635+
fi
636+
sleep 1
637+
if [ $i -eq 60 ]; then
638+
echo "PostgreSQL failed to start"
639+
cleanup 1
640+
fi
661641
done
662-
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p 5435 -h localhost -d postgres <<-EOSQL
663-
create role postgres superuser login;
664-
alter database postgres owner to postgres;
665-
EOSQL
666-
then
667-
echo "Failed to create postgres role and set ownership"
668-
find /tmp -name postgresql.log -exec cat {} \;
669-
cleanup 1
670-
fi
671642
672-
# Run init scripts
673-
for sql in ${migrationsDir}/init-scripts/*.sql; do
674-
echo "Running $sql"
675-
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p 5435 -h localhost -f "$sql" postgres; then
676-
echo "Failed running init script $sql"
677-
cleanup 1
678-
fi
679-
done
680-
681-
# Run additional schema files
682-
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p 5435 -h localhost -d postgres -f ${pgbouncerAuthSchemaSql}; then
683-
echo "Failed running pgbouncer auth schema"
684-
cleanup 1
685-
fi
686-
687-
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p 5435 -h localhost -d postgres -f ${statExtensionSql}; then
688-
echo "Failed running stat extension SQL"
689-
cleanup 1
690-
fi
691-
692-
# Run migrations as superuser
693-
for sql in ${migrationsDir}/migrations/*.sql; do
694-
echo "Running $sql"
695-
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p 5435 -h localhost -f "$sql" postgres; then
696-
echo "Failed running migration $sql"
697-
cleanup 1
698-
fi
699-
done
700643
701-
# Run PostgreSQL schema
702-
if ! psql -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U supabase_admin -p 5435 -h localhost -f ${postgresqlSchemaSql} postgres; then
703-
echo "Failed running PostgreSQL schema"
704-
cleanup 1
705-
fi
706-
707-
createdb -p 5435 -h localhost --username=supabase_admin testing
708-
if ! psql -p 5435 -h localhost --username=supabase_admin -d testing -v ON_ERROR_STOP=1 -Xaf ${./nix/tests/prime.sql}; then
709-
echo "Error executing SQL file. PostgreSQL log content:"
710-
cat $TMPDIR/logfile/postgresql.log
711-
pg_ctl -D "$PGDATA" stop
644+
if ! psql -p 5435 -h localhost --no-password --username=supabase_admin -d postgres -v ON_ERROR_STOP=1 -Xaf ${./nix/tests/prime.sql}; then
645+
echo "Error executing SQL file"
712646
cleanup 1
713647
fi
714-
715-
# # Run tests
716-
# if ! pg_prove -p 5435 -h localhost --username=supabase_admin -d testing ${sqlTests}/*.sql; then
717-
# echo "pg_prove tests failed"
718-
# cleanup 1
719-
# fi
720648
721649
mkdir -p $out/regression_output
722650
if ! pg_regress \
723651
--use-existing \
724-
--dbname=testing \
652+
--dbname=postgres \
725653
--inputdir=${./nix/tests} \
726654
--outputdir=$out/regression_output \
727655
--host=localhost \
@@ -731,7 +659,8 @@
731659
echo "pg_regress tests failed"
732660
cleanup 1
733661
fi
734-
# Find the log file and copy it to output
662+
663+
# Copy logs to output
735664
for logfile in $(find /tmp -name postgresql.log -type f); do
736665
cp "$logfile" $out/postgresql.log
737666
done

nix/tests/prime.sql

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
1-
create extension address_standardizer;
2-
create extension address_standardizer_data_us;
3-
create extension adminpack;
4-
create extension amcheck;
5-
create extension autoinc;
6-
create extension bloom;
7-
create extension btree_gin;
8-
create extension btree_gist;
9-
create extension citext;
10-
create extension cube;
11-
create extension dblink;
12-
create extension dict_int;
13-
create extension dict_xsyn;
14-
create extension earthdistance;
15-
create extension file_fdw;
16-
create extension fuzzystrmatch;
17-
create extension http;
18-
create extension hstore;
19-
create extension hypopg;
20-
create extension index_advisor;
21-
create extension insert_username;
22-
create extension intagg;
23-
create extension intarray;
24-
create extension isn;
25-
create extension lo;
26-
create extension ltree;
27-
create extension moddatetime;
28-
create extension old_snapshot;
29-
create extension pageinspect;
30-
create extension pg_backtrace;
31-
create extension pg_buffercache;
1+
create extension if not exists address_standardizer;
2+
create extension if not exists address_standardizer_data_us;
3+
create extension if not exists adminpack;
4+
create extension if not exists amcheck;
5+
create extension if not exists autoinc;
6+
create extension if not exists bloom;
7+
create extension if not exists btree_gin;
8+
create extension if not exists btree_gist;
9+
create extension if not exists citext;
10+
create extension if not exists cube;
11+
create extension if not exists dblink;
12+
create extension if not exists dict_int;
13+
create extension if not exists dict_xsyn;
14+
create extension if not exists earthdistance;
15+
create extension if not exists file_fdw;
16+
create extension if not exists fuzzystrmatch;
17+
create extension if not exists http;
18+
create extension if not exists hstore;
19+
create extension if not exists hypopg;
20+
create extension if not exists index_advisor;
21+
create extension if not exists insert_username;
22+
create extension if not exists intagg;
23+
create extension if not exists intarray;
24+
create extension if not exists isn;
25+
create extension if not exists lo;
26+
create extension if not exists ltree;
27+
create extension if not exists moddatetime;
28+
create extension if not exists old_snapshot;
29+
create extension if not exists pageinspect;
30+
create extension if not exists pg_backtrace;
31+
create extension if not exists pg_buffercache;
3232

3333
/*
3434
TODO: Does not enable locally mode
3535
requires a change to postgresql.conf to set
3636
cron.database_name = 'testing'
3737
*/
38-
-- create extension pg_cron;
38+
-- create extension if not exists pg_cron;
3939

40-
create extension pg_net;
41-
create extension pg_graphql;
42-
create extension pg_freespacemap;
43-
create extension pg_hashids;
44-
create extension pg_prewarm;
45-
create extension pgmq;
46-
create extension pg_jsonschema;
47-
create extension pg_repack;
48-
create extension pg_stat_monitor;
49-
create extension pg_stat_statements;
50-
create extension pg_surgery;
51-
create extension pg_tle;
52-
create extension pg_trgm;
53-
create extension pg_visibility;
54-
create extension pg_walinspect;
55-
create extension pgaudit;
56-
create extension pgcrypto;
57-
create extension pgtap;
58-
create extension pgjwt;
59-
create extension pgroonga;
60-
create extension pgroonga_database;
61-
create extension pgsodium;
62-
create extension pgrowlocks;
63-
create extension pgstattuple;
64-
create extension plpgsql_check;
65-
create extension plv8;
66-
create extension plcoffee;
67-
create extension plls;
68-
create extension postgis;
69-
create extension postgis_raster;
70-
create extension postgis_sfcgal;
71-
create extension postgis_tiger_geocoder;
72-
create extension postgis_topology;
73-
create extension pgrouting; -- requires postgis
74-
create extension postgres_fdw;
75-
create extension rum;
76-
create extension refint;
77-
create extension seg;
78-
create extension sslinfo;
79-
create extension supabase_vault;
80-
create extension tablefunc;
81-
create extension tcn;
82-
create extension timescaledb;
83-
create extension tsm_system_rows;
84-
-- create extension tsm_system_time; not supported in apache license
85-
create extension unaccent;
86-
create extension "uuid-ossp";
87-
create extension vector;
88-
create extension wrappers;
89-
create extension xml2;
40+
create extension if not exists pg_net;
41+
create extension if not exists pg_graphql;
42+
create extension if not exists pg_freespacemap;
43+
create extension if not exists pg_hashids;
44+
create extension if not exists pg_prewarm;
45+
create extension if not exists pgmq;
46+
create extension if not exists pg_jsonschema;
47+
create extension if not exists pg_repack;
48+
create extension if not exists pg_stat_monitor;
49+
create extension if not exists pg_stat_statements;
50+
create extension if not exists pg_surgery;
51+
create extension if not exists pg_tle;
52+
create extension if not exists pg_trgm;
53+
create extension if not exists pg_visibility;
54+
create extension if not exists pg_walinspect;
55+
create extension if not exists pgaudit;
56+
create extension if not exists pgcrypto;
57+
create extension if not exists pgtap;
58+
create extension if not exists pgjwt;
59+
create extension if not exists pgroonga;
60+
create extension if not exists pgroonga_database;
61+
create extension if not exists pgsodium;
62+
create extension if not exists pgrowlocks;
63+
create extension if not exists pgstattuple;
64+
create extension if not exists plpgsql_check;
65+
create extension if not exists plv8;
66+
create extension if not exists plcoffee;
67+
create extension if not exists plls;
68+
create extension if not exists postgis;
69+
create extension if not exists postgis_raster;
70+
create extension if not exists postgis_sfcgal;
71+
create extension if not exists postgis_tiger_geocoder;
72+
create extension if not exists postgis_topology;
73+
create extension if not exists pgrouting; -- requires postgis
74+
create extension if not exists postgres_fdw;
75+
create extension if not exists rum;
76+
create extension if not exists refint;
77+
create extension if not exists seg;
78+
create extension if not exists sslinfo;
79+
create extension if not exists supabase_vault;
80+
create extension if not exists tablefunc;
81+
create extension if not exists tcn;
82+
create extension if not exists timescaledb;
83+
create extension if not exists tsm_system_rows;
84+
-- create extension if not exists tsm_system_time; not supported in apache license
85+
create extension if not exists unaccent;
86+
create extension if not exists "uuid-ossp";
87+
create extension if not exists vector;
88+
create extension if not exists wrappers;
89+
create extension if not exists xml2;

0 commit comments

Comments
 (0)