Skip to content
Draft
6 changes: 3 additions & 3 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ postgres_major:

# Full version strings for each major version
postgres_release:
postgresorioledb-17: "17.5.1.051-orioledb"
postgres17: "17.6.1.030"
postgres15: "15.14.1.030"
postgresorioledb-17: "17.5.1.051-orioledb-test-partman"
postgres17: "17.6.1.030-test-partman"
postgres15: "15.14.1.030-test-partman"

# Non Postgres Extensions
pgbouncer_release: 1.19.0
Expand Down
6 changes: 6 additions & 0 deletions migrations/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ CREATE EXTENSION IF NOT EXISTS pg_graphql WITH SCHEMA graphql;

COMMENT ON EXTENSION pg_graphql IS 'pg_graphql: GraphQL support';

--
-- Name: pg_partman; Type: EXTENSION; Schema: -; Owner: -
--

CREATE SCHEMA partman;
CREATE EXTENSION pg_partman SCHEMA partman;

--
-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: -
Expand Down
4 changes: 4 additions & 0 deletions migrations/tests/extensions/30-pg_partman.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BEGIN;
create schema if not exists "partman";
create extension if not exists pg_partman with schema "partman";
ROLLBACK;
1 change: 1 addition & 0 deletions migrations/tests/extensions/test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
\ir 27-pg_repack.sql
\ir 28-pgvector.sql
\ir 29-pg_tle.sql
\ir 30-pg_partman.sql
113 changes: 91 additions & 22 deletions nix/ext/pg_partman.nix
Original file line number Diff line number Diff line change
@@ -1,38 +1,107 @@
{
pkgs,
lib,
stdenv,
fetchFromGitHub,
postgresql,
makeWrapper,
switch-ext-version,
}:

stdenv.mkDerivation rec {
let
pname = "pg_partman";
version = "5.1.0";
build =
version: hash:
stdenv.mkDerivation rec {
inherit pname version;

buildInputs = [ postgresql ];
buildInputs = [ postgresql ];

src = fetchFromGitHub {
owner = "pgpartman";
repo = pname;
rev = "refs/tags/v${version}";
inherit hash;
};

installPhase = ''
mkdir -p $out/{lib,share/postgresql/extension}

# Install versioned library
install -Dm755 src/*${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}

# Only install SQL files for the latest version
if [[ "${version}" == "${latestVersion}" ]]; then
# Install all SQL files from sql/ directory
cp -r sql/* $out/share/postgresql/extension/

# Install upgrade scripts
cp updates/* $out/share/postgresql/extension/
fi

# Create versioned control file with modified module path
sed -e "/^default_version =/d" \
-e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}'|" \
${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control
'';

meta = with lib; {
description = "Partition management extension for PostgreSQL";
homepage = "https://github.com/pgpartman/pg_partman";
changelog = "https://github.com/pgpartman/pg_partman/blob/v${version}/CHANGELOG.md";
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
};
};
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).pg_partman;
supportedVersions = lib.filterAttrs (
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
) allVersions;
versions = lib.naturalSort (lib.attrNames supportedVersions);
latestVersion = lib.last versions;
numberOfVersions = builtins.length versions;
packages = builtins.attrValues (
lib.mapAttrs (name: value: build name value.hash) supportedVersions
);
in
pkgs.buildEnv {
name = pname;
paths = packages;
nativeBuildInputs = [ makeWrapper ];

pathsToLink = [
"/lib"
"/share/postgresql/extension"
];

postBuild = ''
{
echo "default_version = '${latestVersion}'"
cat $out/share/postgresql/extension/${pname}--${latestVersion}.control
} > $out/share/postgresql/extension/${pname}.control
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}

src = fetchFromGitHub {
owner = "pgpartman";
repo = pname;
rev = "refs/tags/v${version}";
sha256 = "sha256-GrVOJ5ywZMyqyDroYDLdKkXDdIJSDGhDfveO/ZvrmYs=";
};

installPhase = ''
mkdir -p $out/{lib,share/postgresql/extension}
# checks
(set -x
test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${
toString (numberOfVersions + 1)
}"
)

cp src/*${postgresql.dlSuffix} $out/lib
cp updates/* $out/share/postgresql/extension
cp -r sql/* $out/share/postgresql/extension
cp *.control $out/share/postgresql/extension
makeWrapper ${lib.getExe switch-ext-version} $out/bin/switch_pg_partman_version \
--prefix EXT_WRAPPER : "$out" --prefix EXT_NAME : "${pname}"
'';

meta = with lib; {
description = "Partition management extension for PostgreSQL";
homepage = "https://github.com/pgpartman/pg_partman";
changelog = "https://github.com/pgpartman/pg_partman/blob/v${version}/CHANGELOG.md";
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
broken = versionOlder postgresql.version "14";
passthru = {
inherit versions numberOfVersions switch-ext-version;
pname = "${pname}-all";
hasBackgroundWorker = true;
defaultSchema = "partman";
defaultSettings = {
shared_preload_libraries = [ "pg_partman" ];
};
version =
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
};
}
5 changes: 4 additions & 1 deletion nix/ext/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ let
}
sql_test_directory = Path("${../../tests}")
pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}"
ext_schema = "${(installedExtension "15").defaultSchema or "public"}"

${builtins.readFile ./lib.py}

Expand All @@ -146,7 +147,8 @@ let
server.wait_for_unit("multi-user.target")
server.wait_for_unit("postgresql.service")

test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade)
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema)
test.create_schema()

with subtest("Check upgrade path with postgresql 15"):
test.check_upgrade_path("15")
Expand Down Expand Up @@ -206,6 +208,7 @@ builtins.listToAttrs (
"pg_graphql"
"pg_jsonschema"
"pg_net"
"pg_partman"
"vector"
"wrappers"
]
Expand Down
11 changes: 10 additions & 1 deletion nix/ext/tests/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(
versions: Versions,
sql_test_dir: Path,
support_upgrade: bool = True,
schema: str = "public",
):
"""Initialize the PostgreSQL extension test framework.

Expand All @@ -35,6 +36,10 @@ def __init__(
self.versions = versions
self.support_upgrade = support_upgrade
self.sql_test_dir = sql_test_dir
self.schema = schema

def create_schema(self):
self.run_sql(f"CREATE SCHEMA IF NOT EXISTS {self.schema};")

def run_sql(self, query: str) -> str:
return self.vm.succeed(
Expand All @@ -50,8 +55,12 @@ def drop_extension(self):
self.run_sql(f"DROP EXTENSION IF EXISTS {self.extension_name};")

def install_extension(self, version: str):
if self.schema != "public":
ext_schema = f"SCHEMA {self.schema} "
else:
ext_schema = ""
self.run_sql(
f"""CREATE EXTENSION {self.extension_name} WITH VERSION '{version}' CASCADE;"""
f"""CREATE EXTENSION {self.extension_name} WITH {ext_schema}VERSION '{version}' CASCADE;"""
)
# Verify version was installed correctly
self.assert_version_matches(version)
Expand Down
10 changes: 10 additions & 0 deletions nix/ext/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@
],
"hash": "sha256-Cpi2iASi1QJoED0Qs1dANqg/BNZTsz5S+pw8iYyW03Y="
}
},
"pg_partman": {
"5.2.4": {
"postgresql": [
"15",
"17",
"orioledb-17"
],
"hash": "sha256-i/o+JZEXnJRO17kfdTw87aca28+I8pvuFZsPMA/kf+w="
}
},
"pgmq": {
"1.4.4": {
Expand Down
1 change: 1 addition & 0 deletions nix/packages/postgres.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
../ext/pg_graphql
../ext/pg_stat_monitor.nix
../ext/pg_jsonschema
../ext/pg_partman.nix
../ext/pgvector.nix
../ext/vault.nix
../ext/hypopg.nix
Expand Down
24 changes: 24 additions & 0 deletions nix/tests/expected/pg_partman.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE SCHEMA IF NOT EXISTS partman_test;
CREATE TABLE partman_test.time_taptest_table
(col1 int,
col2 text default 'stuff',
col3 timestamptz NOT NULL DEFAULT now())
PARTITION BY RANGE (col3);
CREATE INDEX ON partman_test.time_taptest_table (col3);
CREATE TABLE partman_test.time_taptest_table_template (LIKE partman_test.time_taptest_table);
ALTER TABLE partman_test.time_taptest_table_template ADD PRIMARY KEY (col1);
SELECT partman.create_parent(
p_parent_table := 'partman_test.time_taptest_table'
, p_control := 'col3'
, p_interval := '1 day'
, p_template_table := 'partman_test.time_taptest_table_template'
);
create_parent
---------------
t
(1 row)

DROP SCHEMA partman_test CASCADE;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table partman_test.time_taptest_table
drop cascades to table partman_test.time_taptest_table_template
Loading