Skip to content

Commit a213177

Browse files
committed
fix: include orioledb in vm test
1 parent b090036 commit a213177

2 files changed

Lines changed: 201 additions & 2 deletions

File tree

nix/ext/tests/lib.nix

Lines changed: 164 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ let
161161
# Initialize database if it doesn't exist
162162
if [ ! -f "$DATA_DIR/PG_VERSION" ]; then
163163
echo "Initializing database at $DATA_DIR"
164-
${postgresPackage}/bin/initdb -U supabase_admin -D "$DATA_DIR"
164+
${postgresPackage}/bin/initdb --allow-group-access --data-checksums -U supabase_admin -D "$DATA_DIR"
165165
fi
166166
167167
# Deploy processed config files with @dataDir@ substituted
@@ -340,7 +340,7 @@ let
340340
mkdir -p -m 0700 "$NEW_DATA"
341341
342342
# Initialize new cluster
343-
${newPkg}/bin/initdb -U supabase_admin -D "$NEW_DATA"
343+
${newPkg}/bin/initdb --allow-group-access --data-checksums -U supabase_admin -D "$NEW_DATA"
344344
345345
# Deploy config files to new data directory
346346
for f in postgresql.conf pg_hba.conf pg_ident.conf supautils.conf read-replica.conf; do
@@ -412,12 +412,174 @@ let
412412
# breaks D-Bus policy during switch-to-configuration)
413413
environment.systemPackages = [ newPkg ];
414414
};
415+
# Create a specialisation for OrioleDB — wipes data and reinitializes from scratch
416+
# (no pg_upgrade path from regular PG to OrioleDB), then runs full Supabase init
417+
makeOrioledbSpecialisation =
418+
{
419+
postgresPort ? defaultPort,
420+
}:
421+
let
422+
orioledbPkg = self.packages.${system}."psql_orioledb-17/bin";
423+
groongaPackage = self.packages.${system}.supabase-groonga;
424+
newDataDir = "/var/lib/postgresql/data-orioledb-17";
425+
processedConfig = processAnsibleConfig { majorVersion = "orioledb-17"; };
426+
port = toString postgresPort;
427+
428+
# Wipe existing data — no upgrade path from regular PG to OrioleDB
429+
migrateScript = pkgs.pkgsLinux.writeShellScript "postgresql-orioledb-migrate" ''
430+
set -euo pipefail
431+
NEW_DATA="${newDataDir}"
432+
if [ -d "$NEW_DATA" ]; then
433+
rm -rf "$NEW_DATA"
434+
fi
435+
'';
436+
437+
# Runs as root: ensure data directory exists with correct ownership
438+
preStartRootScript = pkgs.pkgsLinux.writeShellScript "postgresql-orioledb-pre-start-root" ''
439+
set -euo pipefail
440+
DATA_DIR="${newDataDir}"
441+
if [ ! -d "$DATA_DIR" ]; then
442+
mkdir -p -m 0700 "$DATA_DIR"
443+
chown postgres:postgres "$DATA_DIR"
444+
fi
445+
'';
446+
447+
# Runs as postgres: initdb with OrioleDB-specific args, config deployment, validation
448+
initScript = pkgs.pkgsLinux.writeShellScript "postgresql-orioledb-init" ''
449+
set -euo pipefail
450+
DATA_DIR="${newDataDir}"
451+
452+
if [ ! -f "$DATA_DIR/PG_VERSION" ]; then
453+
echo "Initializing OrioleDB database at $DATA_DIR"
454+
${orioledbPkg}/bin/initdb \
455+
--allow-group-access --data-checksums \
456+
--locale-provider=icu --encoding=UTF-8 --icu-locale=en_US.UTF-8 \
457+
-U supabase_admin -D "$DATA_DIR"
458+
fi
459+
460+
# Deploy processed config files with @dataDir@ substituted
461+
for f in postgresql.conf pg_hba.conf pg_ident.conf supautils.conf read-replica.conf; do
462+
sed "s|@dataDir@|$DATA_DIR|g" ${processedConfig}/$f > "$DATA_DIR/$f"
463+
done
464+
465+
# Copy conf.d directory
466+
rm -rf "$DATA_DIR/conf.d"
467+
cp -r ${processedConfig}/conf.d "$DATA_DIR/conf.d"
468+
chmod -R u+w "$DATA_DIR/conf.d"
469+
470+
# Copy extension-custom-scripts directory
471+
rm -rf "$DATA_DIR/extension-custom-scripts"
472+
cp -r ${processedConfig}/extension-custom-scripts "$DATA_DIR/extension-custom-scripts"
473+
chmod -R u+w "$DATA_DIR/extension-custom-scripts"
474+
475+
# Validate config
476+
echo "Validating PostgreSQL configuration..."
477+
${orioledbPkg}/bin/postgres -C shared_preload_libraries -D "$DATA_DIR"
478+
'';
479+
480+
# Full db init: CREATE EXTENSION orioledb first, then init-scripts + migrations
481+
dbInitScript = pkgs.pkgsLinux.writeShellScript "supabase-orioledb-db-init" ''
482+
set -euo pipefail
483+
484+
echo "Waiting for PostgreSQL to be ready..."
485+
for i in $(seq 1 60); do
486+
if ${orioledbPkg}/bin/pg_isready -h localhost -p ${port} -q; then
487+
echo "PostgreSQL is ready"
488+
break
489+
fi
490+
if [ "$i" -eq 60 ]; then
491+
echo "PostgreSQL failed to become ready"
492+
exit 1
493+
fi
494+
sleep 1
495+
done
496+
497+
PSQL="${orioledbPkg}/bin/psql"
498+
499+
# Create orioledb extension first (before init-scripts, so tables use orioledb storage)
500+
echo "Creating orioledb extension..."
501+
$PSQL -h localhost -p ${port} -U supabase_admin -d postgres -c "CREATE EXTENSION orioledb CASCADE;"
502+
503+
# Create postgres role (matching run-server.sh.in)
504+
echo "Creating postgres role..."
505+
$PSQL -h localhost -p ${port} -U supabase_admin -d postgres -c "CREATE ROLE postgres SUPERUSER LOGIN;" || true
506+
$PSQL -h localhost -p ${port} -U supabase_admin -d postgres -c "ALTER DATABASE postgres OWNER TO postgres;" || true
507+
508+
# Run init-scripts as postgres user (matching run-server.sh.in)
509+
for sql in ${migrationsDir}/init-scripts/*.sql; do
510+
echo "Running init-script: $sql"
511+
$PSQL -v ON_ERROR_STOP=1 -h localhost -p ${port} -U postgres -f "$sql" postgres
512+
done
513+
514+
# Run pgbouncer auth schema
515+
echo "Running pgbouncer auth schema..."
516+
$PSQL -v ON_ERROR_STOP=1 -h localhost -p ${port} -U postgres -d postgres -f ${pgbouncerAuthSchemaSql}
517+
518+
# Run stat extension
519+
echo "Running stat extension..."
520+
$PSQL -v ON_ERROR_STOP=1 -h localhost -p ${port} -U postgres -d postgres -f ${statExtensionSql}
521+
522+
# Run migrations as supabase_admin (matching run-server.sh.in)
523+
for sql in ${migrationsDir}/migrations/*.sql; do
524+
echo "Running migration: $sql"
525+
$PSQL -v ON_ERROR_STOP=1 -h localhost -p ${port} -U supabase_admin -f "$sql" postgres
526+
done
527+
528+
# Run postgresql schema
529+
echo "Running postgresql schema..."
530+
$PSQL -v ON_ERROR_STOP=1 -h localhost -p ${port} -U supabase_admin -f ${postgresqlSchemaSql} postgres
531+
532+
echo "OrioleDB database initialization complete"
533+
'';
534+
in
535+
{
536+
# Reinit service wipes data for fresh orioledb cluster
537+
systemd.services.postgresql-migrate = {
538+
description = "PostgreSQL OrioleDB Reinitialization";
539+
serviceConfig = {
540+
Type = "oneshot";
541+
RemainAfterExit = true;
542+
User = "postgres";
543+
Group = "postgres";
544+
ExecStart = migrateScript;
545+
};
546+
environment = {
547+
LANG = "en_US.UTF-8";
548+
};
549+
};
550+
551+
# Override postgresql: new package, new data dir, new ExecStartPre for orioledb initdb
552+
systemd.services.postgresql = {
553+
after = [ "postgresql-migrate.service" ];
554+
requires = [ "postgresql-migrate.service" ];
555+
serviceConfig = {
556+
ExecStartPre = lib.mkForce [
557+
("+" + preStartRootScript)
558+
initScript
559+
];
560+
ExecStart = lib.mkForce "${orioledbPkg}/bin/postgres -D ${newDataDir}";
561+
};
562+
environment = {
563+
GRN_PLUGINS_DIR = lib.mkForce "${groongaPackage}/lib/groonga/plugins";
564+
};
565+
};
566+
567+
# Override db-init with orioledb-aware version (creates orioledb ext + full init)
568+
systemd.services.supabase-db-init = {
569+
wantedBy = lib.mkForce [ "multi-user.target" ];
570+
serviceConfig.ExecStart = lib.mkForce dbInitScript;
571+
};
572+
573+
# Add orioledb package to system PATH
574+
environment.systemPackages = [ orioledbPkg ];
575+
};
415576
in
416577
{
417578
inherit
418579
processAnsibleConfig
419580
makeSupabaseTestConfig
420581
makeUpgradeSpecialisation
582+
makeOrioledbSpecialisation
421583
expectedVersions
422584
defaultPort
423585
;

nix/ext/tests/pg_repack.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let
88
installedExtension =
99
postgresMajorVersion: self.legacyPackages.${system}."psql_${postgresMajorVersion}".exts."${pname}";
1010
versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions;
11+
orioledbVersions = self.legacyPackages.${system}."psql_orioledb-17".exts."${pname}".versions;
1112
in
1213
pkgs.testers.runNixOSTest {
1314
name = pname;
@@ -24,21 +25,26 @@ pkgs.testers.runNixOSTest {
2425
fromMajorVersion = "15";
2526
toMajorVersion = "17";
2627
};
28+
29+
specialisation.orioledb17.configuration = testLib.makeOrioledbSpecialisation { };
2730
};
2831
testScript =
2932
{ nodes, ... }:
3033
let
3134
pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17";
35+
orioledb17-configuration = "${nodes.server.system.build.toplevel}/specialisation/orioledb17";
3236
in
3337
''
3438
from pathlib import Path
3539
versions = {
3640
"15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}],
3741
"17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}],
42+
"orioledb-17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') orioledbVersions)}],
3843
}
3944
extension_name = "${pname}"
4045
support_upgrade = False
4146
pg17_configuration = "${pg17-configuration}"
47+
orioledb17_configuration = "${orioledb17-configuration}"
4248
sql_test_directory = Path("${../../tests}")
4349
4450
${builtins.readFile ./lib.py}
@@ -130,6 +136,37 @@ pkgs.testers.runNixOSTest {
130136
131137
with subtest("Check upgrade path with postgresql 17"):
132138
test.check_upgrade_path("17")
139+
140+
with subtest("switch to orioledb 17"):
141+
server.succeed(
142+
f"{orioledb17_configuration}/bin/switch-to-configuration test >&2"
143+
)
144+
server.wait_for_unit("supabase-db-init.service")
145+
146+
with subtest("Verify OrioleDB is running"):
147+
installed_extensions = server.succeed(
148+
"psql -U supabase_admin -d postgres -t -A -c \"SELECT extname FROM pg_extension WHERE extname = 'orioledb';\""
149+
).strip()
150+
assert "orioledb" in installed_extensions, (
151+
f"Expected orioledb extension to be installed, got: {installed_extensions}"
152+
)
153+
154+
dam = server.succeed(
155+
"psql -U supabase_admin -d postgres -t -A -c \"SHOW default_table_access_method;\""
156+
).strip()
157+
assert dam == "orioledb", (
158+
f"Expected default_table_access_method = orioledb, got: {dam}"
159+
)
160+
161+
with subtest("Verify OrioleDB init scripts and migrations ran"):
162+
roles = server.succeed(
163+
"psql -U supabase_admin -d postgres -t -A -c \"SELECT rolname FROM pg_roles ORDER BY rolname;\""
164+
).strip()
165+
for role in ["anon", "authenticated", "authenticator", "supabase_admin"]:
166+
assert role in roles, f"Expected role {role} to exist, got: {roles}"
167+
168+
with subtest("Check upgrade path with orioledb 17"):
169+
test.check_upgrade_path("orioledb-17")
133170
'';
134171
}
135172
# pg_repack does not support in-place upgrade as it doesn't provide the upgrade SQL scripts

0 commit comments

Comments
 (0)