|
| 1 | +{ self, pkgs }: |
| 2 | +let |
| 3 | + pname = "safeupdate"; |
| 4 | + inherit (pkgs) lib; |
| 5 | + system = pkgs.pkgsLinux.stdenv.hostPlatform.system; |
| 6 | + testLib = import ./lib.nix { inherit self pkgs; }; |
| 7 | + installedExtension = |
| 8 | + postgresMajorVersion: self.legacyPackages.${system}."psql_${postgresMajorVersion}".exts."${pname}"; |
| 9 | + versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; |
| 10 | + orioledbVersions = self.legacyPackages.${system}."psql_orioledb-17".exts."${pname}".versions; |
| 11 | +in |
| 12 | +self.inputs.nixpkgs.lib.nixos.runTest { |
| 13 | + name = pname; |
| 14 | + hostPkgs = pkgs; |
| 15 | + nodes.server = |
| 16 | + { ... }: |
| 17 | + { |
| 18 | + imports = [ |
| 19 | + (testLib.makeSupabaseTestConfig { |
| 20 | + majorVersion = "15"; |
| 21 | + }) |
| 22 | + ]; |
| 23 | + |
| 24 | + specialisation.postgresql17.configuration = testLib.makeUpgradeSpecialisation { |
| 25 | + fromMajorVersion = "15"; |
| 26 | + toMajorVersion = "17"; |
| 27 | + }; |
| 28 | + |
| 29 | + specialisation.orioledb17.configuration = testLib.makeOrioledbSpecialisation { }; |
| 30 | + }; |
| 31 | + testScript = |
| 32 | + { nodes, ... }: |
| 33 | + let |
| 34 | + pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17"; |
| 35 | + in |
| 36 | + '' |
| 37 | + from pathlib import Path |
| 38 | + versions = { |
| 39 | + "15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}], |
| 40 | + "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], |
| 41 | + "orioledb-17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') orioledbVersions)}], |
| 42 | + } |
| 43 | + extension_name = "${pname}" |
| 44 | + support_upgrade = False |
| 45 | + pg17_configuration = "${pg17-configuration}" |
| 46 | + ext_has_background_worker = ${ |
| 47 | + if (installedExtension "15") ? hasBackgroundWorker then "True" else "False" |
| 48 | + } |
| 49 | + sql_test_directory = Path("${../../tests}") |
| 50 | + pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}" |
| 51 | + |
| 52 | + ${builtins.readFile ./lib.py} |
| 53 | + |
| 54 | + start_all() |
| 55 | + |
| 56 | + server.wait_for_unit("supabase-db-init.service") |
| 57 | + |
| 58 | + |
| 59 | + with subtest("Verify PostgreSQL 15 is our custom build"): |
| 60 | + pg_version = server.succeed( |
| 61 | + "psql -U supabase_admin -d postgres -t -A -c \"SELECT version();\"" |
| 62 | + ).strip() |
| 63 | + assert "${testLib.expectedVersions."15"}" in pg_version, ( |
| 64 | + f"Expected version ${testLib.expectedVersions."15"}, got: {pg_version}" |
| 65 | + ) |
| 66 | + |
| 67 | + postgres_path = server.succeed("readlink -f $(which postgres)").strip() |
| 68 | + assert "postgresql-and-plugins-${testLib.expectedVersions."15"}" in postgres_path, ( |
| 69 | + f"Expected our custom build (${testLib.expectedVersions."15"}), got: {postgres_path}" |
| 70 | + ) |
| 71 | + |
| 72 | + with subtest("Verify ansible config loaded"): |
| 73 | + spl = server.succeed( |
| 74 | + "psql -U supabase_admin -d postgres -t -A -c \"SHOW shared_preload_libraries;\"" |
| 75 | + ).strip() |
| 76 | + for ext in ["pg_stat_statements", "pgaudit", "pgsodium", "pg_cron", "pg_net"]: |
| 77 | + assert ext in spl, f"Expected {ext} in shared_preload_libraries, got: {spl}" |
| 78 | + |
| 79 | + session_pl = server.succeed( |
| 80 | + "psql -U supabase_admin -d postgres -t -A -c \"SHOW session_preload_libraries;\"" |
| 81 | + ).strip() |
| 82 | + assert "supautils" in session_pl, ( |
| 83 | + f"Expected supautils in session_preload_libraries, got: {session_pl}" |
| 84 | + ) |
| 85 | + |
| 86 | + with subtest("Verify init scripts and migrations ran"): |
| 87 | + roles = server.succeed( |
| 88 | + "psql -U supabase_admin -d postgres -t -A -c \"SELECT rolname FROM pg_roles ORDER BY rolname;\"" |
| 89 | + ).strip() |
| 90 | + for role in ["anon", "authenticated", "authenticator", "dashboard_user", "pgbouncer", "service_role", "supabase_admin", "supabase_auth_admin", "supabase_storage_admin"]: |
| 91 | + assert role in roles, f"Expected role {role} to exist, got: {roles}" |
| 92 | + |
| 93 | + schemas = server.succeed( |
| 94 | + "psql -U supabase_admin -d postgres -t -A -c \"SELECT schema_name FROM information_schema.schemata ORDER BY schema_name;\"" |
| 95 | + ).strip() |
| 96 | + for schema in ["auth", "storage", "extensions"]: |
| 97 | + assert schema in schemas, f"Expected schema {schema} to exist, got: {schemas}" |
| 98 | + |
| 99 | + test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade) |
| 100 | + |
| 101 | + with subtest("Check upgrade path with postgresql 15"): |
| 102 | + test.check_upgrade_path("15") |
| 103 | + |
| 104 | + last_version = None |
| 105 | + with subtest("Check the install of the last version of the extension"): |
| 106 | + last_version = test.check_install_last_version("15") |
| 107 | + |
| 108 | + with subtest("switch to postgresql 17"): |
| 109 | + server.succeed( |
| 110 | + f"{pg17_configuration}/bin/switch-to-configuration test >&2" |
| 111 | + ) |
| 112 | + server.wait_for_unit("postgresql.service") |
| 113 | + |
| 114 | + with subtest("Verify PostgreSQL 17 is our custom build"): |
| 115 | + pg_version = server.succeed( |
| 116 | + "psql -U supabase_admin -d postgres -t -A -c \"SELECT version();\"" |
| 117 | + ).strip() |
| 118 | + assert "${testLib.expectedVersions."17"}" in pg_version, ( |
| 119 | + f"Expected version ${testLib.expectedVersions."17"}, got: {pg_version}" |
| 120 | + ) |
| 121 | + |
| 122 | + postgres_pid = server.succeed( |
| 123 | + "head -1 /var/lib/postgresql/data-17/postmaster.pid" |
| 124 | + ).strip() |
| 125 | + postgres_path = server.succeed( |
| 126 | + f"readlink -f /proc/{postgres_pid}/exe" |
| 127 | + ).strip() |
| 128 | + assert "postgresql-and-plugins-${testLib.expectedVersions."17"}" in postgres_path, ( |
| 129 | + f"Expected our custom build (${testLib.expectedVersions."17"}), got: {postgres_path}" |
| 130 | + ) |
| 131 | +
|
| 132 | + with subtest("Check last version of the extension after upgrade"): |
| 133 | + test.assert_version_matches(last_version) |
| 134 | +
|
| 135 | + with subtest("Check upgrade path with postgresql 17"): |
| 136 | + test.check_upgrade_path("17") |
| 137 | +
|
| 138 | + with subtest("switch to orioledb 17"): |
| 139 | + server.succeed( |
| 140 | + f"{orioledb17_configuration}/bin/switch-to-configuration test >&2" |
| 141 | + ) |
| 142 | + server.wait_for_unit("supabase-db-init.service") |
| 143 | +
|
| 144 | + with subtest("Verify OrioleDB is running"): |
| 145 | + installed_extensions = server.succeed( |
| 146 | + "psql -U supabase_admin -d postgres -t -A -c \"SELECT extname FROM pg_extension WHERE extname = 'orioledb';\"" |
| 147 | + ).strip() |
| 148 | + assert "orioledb" in installed_extensions, ( |
| 149 | + f"Expected orioledb extension to be installed, got: {installed_extensions}" |
| 150 | + ) |
| 151 | + |
| 152 | + dam = server.succeed( |
| 153 | + "psql -U supabase_admin -d postgres -t -A -c \"SHOW default_table_access_method;\"" |
| 154 | + ).strip() |
| 155 | + assert dam == "orioledb", ( |
| 156 | + f"Expected default_table_access_method = orioledb, got: {dam}" |
| 157 | + ) |
| 158 | +
|
| 159 | + with subtest("Verify OrioleDB init scripts and migrations ran"): |
| 160 | + roles = server.succeed( |
| 161 | + "psql -U supabase_admin -d postgres -t -A -c \"SELECT rolname FROM pg_roles ORDER BY rolname;\"" |
| 162 | + ).strip() |
| 163 | + for role in ["anon", "authenticated", "authenticator", "supabase_admin"]: |
| 164 | + assert role in roles, f"Expected role {role} to exist, got: {roles}" |
| 165 | + |
| 166 | + with subtest("Check upgrade path with orioledb 17"): |
| 167 | + test.check_upgrade_path("orioledb-17") |
| 168 | +} |
0 commit comments