Skip to content

Commit e10de49

Browse files
committed
fix: migration handling
1 parent c9d6b4f commit e10de49

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

ansible/vars.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ postgres_major:
1010

1111
# Full version strings for each major version
1212
postgres_release:
13-
postgresorioledb-17: 17.5.1.043-orioledb-pgaudit-2
14-
postgres17: 17.6.1.022-pgaudit-2
15-
postgres15: 15.14.1.022-pgaudit-2
13+
postgresorioledb-17: 17.5.1.043-orioledb-pgaudit-3
14+
postgres17: 17.6.1.022-pgaudit-3
15+
postgres15: 15.14.1.022-pgaudit-3
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: 1.19.0

nix/ext/pgaudit.nix

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ let
9999
100100
mkdir -p $out/{lib,share/postgresql/extension}
101101
102+
# Extract the actual default_version from the control file
103+
# This is what PostgreSQL will record in pg_extension, not necessarily the git tag
104+
controlVersion=$(grep "^default_version" ${pname}.control | sed "s/default_version = '\(.*\)'/\1/")
105+
echo "$controlVersion" > $out/control_version
106+
102107
# Install shared library with version suffix
103108
mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}
104109
@@ -170,6 +175,49 @@ buildEnv {
170175
fi
171176
'') bridgeMigrations}
172177
178+
# Read actual control file versions from each built package
179+
# This handles cases where git tag differs from control file default_version
180+
# (e.g., git tag 1.7.0 but control file says default_version = '1.7')
181+
${lib.concatMapStringsSep "\n" (pkg: ''
182+
if [[ -f "${pkg}/control_version" ]]; then
183+
controlVer=$(cat "${pkg}/control_version")
184+
echo "Found control version: $controlVer from package ${pkg}"
185+
186+
# Create migrations from control version to all supported versions on this PG major
187+
${
188+
lib.concatMapStringsSep "\n" (targetVer: ''
189+
# Skip if control version equals target version
190+
if [[ "$controlVer" != "${targetVer}" ]]; then
191+
# Skip if migration already exists
192+
if [[ ! -f "$out/share/postgresql/extension/${pname}--$controlVer--${targetVer}.sql" ]]; then
193+
# Create symlink to migration if target SQL exists
194+
if [[ -f "$out/share/postgresql/extension/${pname}--${targetVer}.sql" ]]; then
195+
echo "Creating migration symlink from control version $controlVer to ${targetVer}"
196+
ln -s "$out/share/postgresql/extension/${pname}--${targetVer}.sql" \
197+
"$out/share/postgresql/extension/${pname}--$controlVer--${targetVer}.sql"
198+
fi
199+
fi
200+
fi
201+
'') versions
202+
}
203+
fi
204+
'') packages}
205+
206+
# Special cross-major-version handling for pgaudit 1.7
207+
# Upstream pgaudit git tag 1.7.0 has control file with default_version = '1.7'
208+
# Users upgrading from PG 15 to PG 17 will have version 1.7 installed
209+
# We can't read the control file from PG 15 packages when building PG 17,
210+
# so we hardcode this known mismatch
211+
${lib.concatMapStringsSep "\n" (targetVer: ''
212+
if [[ ! -f "$out/share/postgresql/extension/${pname}--1.7--${targetVer}.sql" ]]; then
213+
if [[ -f "$out/share/postgresql/extension/${pname}--${targetVer}.sql" ]]; then
214+
echo "Creating cross-major migration symlink from pgaudit 1.7 to ${targetVer}"
215+
ln -s "$out/share/postgresql/extension/${pname}--${targetVer}.sql" \
216+
"$out/share/postgresql/extension/${pname}--1.7--${targetVer}.sql"
217+
fi
218+
fi
219+
'') versions}
220+
173221
# Verify all expected library files are present (one per version + symlink)
174222
expectedFiles=${toString (numberOfVersions + 1)}
175223
actualFiles=$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)

0 commit comments

Comments
 (0)