Skip to content

Commit ac48c0b

Browse files
samrosejfroche
andauthored
fix: covering migrations for wrappers across all versions` (#1876)
* fix: covering migrations for wrappers across all versions` * chore: remove comment * fix: remove copy and deref * Always run in-place upgrade extension in default nixos tests We do not want to uninstall and install the extension during an upgrade test. * chore: bump to release --------- Co-authored-by: Jean-François Roche <[email protected]>
1 parent a354427 commit ac48c0b

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
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.051-orioledb"
14-
postgres17: "17.6.1.030"
15-
postgres15: "15.14.1.030"
13+
postgresorioledb-17: "17.5.1.052-orioledb"
14+
postgres17: "17.6.1.031"
15+
postgres15: "15.14.1.031"
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: 1.19.0

nix/ext/tests/default.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ let
131131
"17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}],
132132
}
133133
extension_name = "${pname}"
134-
support_upgrade = False
135134
pg17_configuration = "${pg17-configuration}"
136135
ext_has_background_worker = ${
137136
if (installedExtension "15") ? hasBackgroundWorker then "True" else "False"
@@ -146,7 +145,7 @@ let
146145
server.wait_for_unit("multi-user.target")
147146
server.wait_for_unit("postgresql.service")
148147
149-
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade)
148+
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory)
150149
151150
with subtest("Check upgrade path with postgresql 15"):
152151
test.check_upgrade_path("15")

nix/ext/wrappers/default.nix

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ let
171171
};
172172
}
173173
);
174-
previouslyPackagedVersions = [
174+
# All versions that were previously packaged (historical list)
175+
allPreviouslyPackagedVersions = [
176+
"0.4.3"
177+
"0.4.2"
178+
"0.4.1"
179+
"0.3.0"
175180
"0.2.0"
176181
"0.1.19"
177182
"0.1.18"
@@ -191,14 +196,19 @@ let
191196
"0.1.1"
192197
"0.1.0"
193198
];
194-
numberOfPreviouslyPackagedVersions = builtins.length previouslyPackagedVersions;
195199
allVersions = (builtins.fromJSON (builtins.readFile ../versions.json)).wrappers;
196200
supportedVersions = lib.filterAttrs (
197201
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
198202
) allVersions;
199203
versions = lib.naturalSort (lib.attrNames supportedVersions);
200204
latestVersion = lib.last versions;
201205
numberOfVersions = builtins.length versions;
206+
# Filter out previously packaged versions that are actually built for this PG version
207+
# This prevents double-counting when a version appears in both lists
208+
previouslyPackagedVersions = builtins.filter (
209+
v: !(builtins.elem v versions)
210+
) allPreviouslyPackagedVersions;
211+
numberOfPreviouslyPackagedVersions = builtins.length previouslyPackagedVersions;
202212
packages = builtins.attrValues (
203213
lib.mapAttrs (name: value: build name value.hash value.rust value.pgrx) supportedVersions
204214
);
@@ -231,26 +241,40 @@ buildEnv {
231241
}
232242
233243
create_migration_sql_files() {
244+
245+
234246
PREVIOUS_VERSION=""
235247
while IFS= read -r i; do
236248
FILENAME=$(basename "$i")
237-
DIRNAME=$(dirname "$i")
238249
VERSION="$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+' <<< $FILENAME)"
239250
if [[ "$PREVIOUS_VERSION" != "" ]]; then
240-
echo "Processing $i"
241-
MIGRATION_FILENAME="$DIRNAME/''${FILENAME/$VERSION/$PREVIOUS_VERSION--$VERSION}"
242-
cp "$i" "$MIGRATION_FILENAME"
251+
# Always write to $out/share/postgresql/extension, not $DIRNAME
252+
# because $DIRNAME might be a symlinked read-only path from the Nix store
253+
# We use -L with cp to dereference symlinks (copy the actual file content, not the symlink)
254+
MIGRATION_FILENAME="$out/share/postgresql/extension/''${FILENAME/$VERSION/$PREVIOUS_VERSION--$VERSION}"
255+
cp -L "$i" "$MIGRATION_FILENAME"
243256
fi
244257
PREVIOUS_VERSION="$VERSION"
245258
done < <(find $out -name '*.sql' | sort -V)
246259
260+
# Create empty SQL files for previously packaged versions that don't exist
261+
# This compensates for versions that failed to produce SQL files in the past
262+
for prev_version in ${lib.concatStringsSep " " previouslyPackagedVersions}; do
263+
sql_file="$out/share/postgresql/extension/wrappers--$prev_version.sql"
264+
if [ ! -f "$sql_file" ]; then
265+
echo "-- Empty migration file for previously packaged version $prev_version" > "$sql_file"
266+
fi
267+
done
268+
247269
# Create migration SQL files from previous versions to newer versions
270+
# Skip if the migration file already exists (to avoid conflicts with the first loop)
248271
for prev_version in ${lib.concatStringsSep " " previouslyPackagedVersions}; do
249272
for curr_version in ${lib.concatStringsSep " " versions}; do
250273
if [[ "$(printf '%s\n%s' "$prev_version" "$curr_version" | sort -V | head -n1)" == "$prev_version" ]] && [[ "$prev_version" != "$curr_version" ]]; then
251274
main_sql_file="$out/share/postgresql/extension/wrappers--$curr_version.sql"
252-
if [ -f "$main_sql_file" ]; then
253-
new_file="$out/share/postgresql/extension/wrappers--$prev_version--$curr_version.sql"
275+
new_file="$out/share/postgresql/extension/wrappers--$prev_version--$curr_version.sql"
276+
# Only create if it doesn't already exist (first loop may have created it)
277+
if [ -f "$main_sql_file" ] && [ ! -f "$new_file" ]; then
254278
cp "$main_sql_file" "$new_file"
255279
sed -i 's|$libdir/wrappers-[0-9.]*|$libdir/wrappers|g' "$new_file"
256280
fi
@@ -263,6 +287,7 @@ buildEnv {
263287
create_lib_files
264288
create_migration_sql_files
265289
290+
# Verify library count matches expected
266291
(test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${
267292
toString (numberOfVersions + numberOfPreviouslyPackagedVersions + 1)
268293
}")

0 commit comments

Comments
 (0)