Skip to content

chore: move ansible migration tests to nix flake check #1493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions amazon-arm64-nix.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ build {
destination = "/tmp"
}

provisioner "file" {
source = "ebssurrogate/files/unit-tests"
destination = "/tmp"
}

# Copy ansible playbook
provisioner "shell" {
inline = ["mkdir /tmp/ansible-playbook"]
Expand Down
67 changes: 3 additions & 64 deletions ansible/tasks/test-image.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
- name: install pg_prove
apt:
pkg:
- libtap-parser-sourcehandler-pgtap-perl
when: debpkg_mode

# - name: Temporarily disable PG Sodium references in config
# become: yes
# become_user: postgres
Expand All @@ -16,9 +10,9 @@
become_user: postgres
shell:
cmd: >
sed -i.bak
-e 's/\(shared_preload_libraries = '\''.*\)pgsodium,\(.*'\''\)/\1\2/'
-e 's/\(shared_preload_libraries = '\''.*\)supabase_vault,\(.*'\''\)/\1\2/'
sed -i.bak
-e 's/\(shared_preload_libraries = '\''.*\)pgsodium,\(.*'\''\)/\1\2/'
-e 's/\(shared_preload_libraries = '\''.*\)supabase_vault,\(.*'\''\)/\1\2/'
-e 's/\(shared_preload_libraries = '\''.*\), *supabase_vault'\''/\1'\''/'
-e 's/pgsodium.getkey_script=/#pgsodium.getkey_script=/'
/etc/postgresql/postgresql.conf
Expand Down Expand Up @@ -74,53 +68,6 @@
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
when: stage2_nix


- name: Check psql_version and modify migrations if oriole-xx
block:
- name: Check if psql_version is psql_orioledb-xx
set_fact:
is_psql_oriole: "{{ psql_version in ['psql_orioledb-16', 'psql_orioledb-17'] }}"

- name: Remove specified extensions from SQL file
ansible.builtin.command:
cmd: >
sed -i '/\\ir.*\(timescaledb\|postgis\|pgrouting\|plv8\).*\.sql/d' /tmp/migrations/tests/extensions/test.sql
when: is_psql_oriole
become: yes

- name: Remove specified extension files from extensions directory
ansible.builtin.find:
paths: /tmp/migrations/tests/extensions
patterns:
- '*timescaledb*.sql'
- '*plv8*.sql'
- '*postgis*.sql'
- '*pgrouting*.sql'
register: files_to_remove
when: is_psql_oriole

- name: Delete matched extension files
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ files_to_remove.files }}"
when: is_psql_oriole
become: yes
Comment on lines -91 to -108
Copy link
Member Author

@steve-chavez steve-chavez Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These exceptions from orioledb are now done properly using SQL on each test by checking if the orioledb extension is loaded. (there's no file removal needed)


- name: Run Unit tests (with filename unit-test-*) on Postgres Database
shell: /usr/bin/pg_prove -U postgres -h localhost -d postgres -v /tmp/unit-tests/unit-test-*.sql
register: retval
failed_when: retval.rc != 0
when: debpkg_mode or stage2_nix

- name: Run migrations tests
shell: /usr/bin/pg_prove -U supabase_admin -h localhost -d postgres -v tests/test.sql
register: retval
failed_when: retval.rc != 0
when: debpkg_mode or stage2_nix
args:
chdir: /tmp/migrations

- name: Re-enable PG Sodium references in config
become: yes
become_user: postgres
Expand All @@ -132,14 +79,6 @@
shell: /usr/lib/postgresql/bin/psql --no-password --no-psqlrc -d postgres -h localhost -U supabase_admin -c 'SELECT pg_stat_statements_reset(); SELECT pg_stat_reset();'
when: debpkg_mode or stage2_nix

- name: remove pg_prove
apt:
pkg:
- libtap-parser-sourcehandler-pgtap-perl
state: absent
autoremove: yes
when: debpkg_mode

- name: Stop Postgres Database
become: yes
become_user: postgres
Expand Down
58 changes: 0 additions & 58 deletions ebssurrogate/files/unit-tests/unit-test-01.sql

This file was deleted.

3 changes: 0 additions & 3 deletions ebssurrogate/scripts/surrogate-bootstrap-nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ function setup_chroot_environment {
# Copy migrations
cp -r /tmp/migrations /mnt/tmp/

# Copy unit tests
cp -r /tmp/unit-tests /mnt/tmp/

# Copy the bootstrap script into place and execute inside chroot
cp /tmp/chroot-bootstrap-nix.sh /mnt/tmp/chroot-bootstrap-nix.sh
chroot /mnt /tmp/chroot-bootstrap-nix.sh
Expand Down
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,9 @@
exit 1
fi

echo "Running migrations tests"
pg_prove -p 5435 -U supabase_admin -h localhost -d postgres -v ${./migrations/tests}/test.sql

mkdir -p $out/regression_output
if ! pg_regress \
--use-existing \
Expand Down
73 changes: 34 additions & 39 deletions migrations/tests/extensions/01-postgis.sql
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
BEGIN;
create extension if not exists postgis_sfcgal with schema "extensions" cascade;
ROLLBACK;
begin;
do $_$
begin
if not exists (select 1 from pg_extension where extname = 'orioledb') then
-- create postgis tiger as supabase_admin
create extension if not exists postgis_tiger_geocoder cascade;

BEGIN;
create extension if not exists postgis_raster with schema "extensions" cascade;
ROLLBACK;
-- \ir ansible/files/postgresql_extension_custom_scripts/postgis_tiger_geocoder/after-create.sql
grant usage on schema tiger, tiger_data to postgres with grant option;
grant all privileges on all tables in schema tiger, tiger_data to postgres with grant option;
grant all privileges on all routines in schema tiger, tiger_data to postgres with grant option;
grant all privileges on all sequences in schema tiger, tiger_data to postgres with grant option;
alter default privileges in schema tiger, tiger_data grant all on tables to postgres with grant option;
alter default privileges in schema tiger, tiger_data grant all on routines to postgres with grant option;
alter default privileges in schema tiger, tiger_data grant all on sequences to postgres with grant option;
SET search_path TO extensions, public, tiger, tiger_data;
-- postgres role should have access
set local role postgres;
perform tiger.pprint_addy(tiger.pagc_normalize_address('710 E Ben White Blvd, Austin, TX 78704'));

BEGIN;
-- create postgis tiger as supabase_admin
create extension if not exists address_standardizer with schema extensions;
create extension if not exists postgis_tiger_geocoder cascade;
-- other roles can be granted access
grant usage on schema tiger, tiger_data to authenticated;
grant select on all tables in schema tiger, tiger_data to authenticated;
grant execute on all routines in schema tiger, tiger_data to authenticated;

-- \ir ansible/files/postgresql_extension_custom_scripts/postgis_tiger_geocoder/after-create.sql
grant usage on schema tiger, tiger_data to postgres with grant option;
grant all privileges on all tables in schema tiger, tiger_data to postgres with grant option;
grant all privileges on all routines in schema tiger, tiger_data to postgres with grant option;
grant all privileges on all sequences in schema tiger, tiger_data to postgres with grant option;
alter default privileges in schema tiger, tiger_data grant all on tables to postgres with grant option;
alter default privileges in schema tiger, tiger_data grant all on routines to postgres with grant option;
alter default privileges in schema tiger, tiger_data grant all on sequences to postgres with grant option;
SET search_path TO extensions, public, tiger, tiger_data;
-- postgres role should have access
set local role postgres;
select tiger.pprint_addy(tiger.pagc_normalize_address('710 E Ben White Blvd, Austin, TX 78704'));
-- authenticated role should have access now
set local role authenticated;
perform tiger.pprint_addy(tiger.pagc_normalize_address('710 E Ben White Blvd, Austin, TX 78704'));
reset role;

-- other roles can be granted access
grant usage on schema tiger, tiger_data to authenticated;
grant select on all tables in schema tiger, tiger_data to authenticated;
grant execute on all routines in schema tiger, tiger_data to authenticated;

-- authenticated role should have access now
set local role authenticated;
select tiger.pprint_addy(tiger.pagc_normalize_address('710 E Ben White Blvd, Austin, TX 78704'));
ROLLBACK;

BEGIN;
-- address standardizer creates a table in extensions schema, owned by supabase_admin
create extension if not exists address_standardizer_data_us with schema extensions;
Copy link
Member Author

@steve-chavez steve-chavez Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This create extension was removed because it's already included on

create extension if not exists address_standardizer_data_us;

but the logic that tests the postgres role is able to select us_lex is still preserved on the following lines.

-- postgres role should have access
set local role postgres;
select * from extensions.us_lex;
ROLLBACK;
-- postgres role should have access to address_standardizer_data_us
set local role postgres;
perform 1 from us_lex;
reset role;
end if;
end
$_$;
rollback;
12 changes: 9 additions & 3 deletions migrations/tests/extensions/02-pgrouting.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
BEGIN;
create extension if not exists pgrouting with schema "extensions" cascade;
ROLLBACK;
begin;
do $_$
begin
if not exists (select 1 from pg_extension where extname = 'orioledb') then
create extension if not exists pgrouting with schema "extensions" cascade;
end if;
end
$_$;
rollback;
12 changes: 9 additions & 3 deletions migrations/tests/extensions/10-timescaledb.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
BEGIN;
create extension if not exists timescaledb with schema "extensions";
ROLLBACK;
begin;
do $_$
begin
if not exists (select 1 from pg_extension where extname = 'orioledb') then
create extension if not exists timescaledb with schema "extensions";
end if;
end
$_$;
rollback;
12 changes: 9 additions & 3 deletions migrations/tests/extensions/13-plv8.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
BEGIN;
create extension if not exists plv8 with schema "pg_catalog";
ROLLBACK;
begin;
do $_$
begin
if not exists (select 1 from pg_extension where extname = 'orioledb') then
create extension if not exists plv8 with schema "pg_catalog";
end if;
end
$_$;
rollback;
1 change: 0 additions & 1 deletion nix/docs/adding-new-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ buildPgrxExtension_0_11_3 rec {
meta = with lib; {
description = "JSON Schema Validation for PostgreSQL";
homepage = "https://github.com/supabase/${pname}";
maintainers = with maintainers; [ samrose ];
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
};
Expand Down
1 change: 0 additions & 1 deletion nix/ext/hypopg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ stdenv.mkDerivation rec {
meta = with lib; {
description = "Hypothetical Indexes for PostgreSQL";
homepage = "https://github.com/HypoPG/${pname}";
maintainers = with maintainers; [ samrose ];
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
};
Expand Down
1 change: 0 additions & 1 deletion nix/ext/index_advisor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ stdenv.mkDerivation rec {
meta = with lib; {
description = "Recommend indexes to improve query performance in PostgreSQL";
homepage = "https://github.com/olirice/index_advisor";
maintainers = with maintainers; [ samrose ];
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
};
Expand Down
11 changes: 5 additions & 6 deletions nix/ext/mecab-naist-jdic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ stdenv.mkDerivation rec {
${mecab}/libexec/mecab/mecab-dict-index -d . -o . -f UTF-8 -t utf-8
runHook postBuild
'';

installPhase = ''
runHook preInstall

mkdir -p $out/lib/mecab/dic/naist-jdic
cp *.dic *.bin *.def $out/lib/mecab/dic/naist-jdic/

runHook postInstall
'';

meta = with lib; {
description = "Naist Japanese Dictionary for MeCab";
homepage = "https://taku910.github.io/mecab/";
license = licenses.gpl2;
platforms = platforms.unix;
maintainers = with maintainers; [ samrose ];
};
}
}
9 changes: 4 additions & 5 deletions nix/ext/orioledb.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@ stdenv.mkDerivation rec {
buildPhase = "make USE_PGXS=1 ORIOLEDB_PATCHSET_VERSION=5";
installPhase = ''
runHook preInstall

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

# Copy the extension library
cp orioledb${postgresql.dlSuffix} $out/lib/

# Copy sql files from the sql directory
cp sql/*.sql $out/share/postgresql/extension/

# Copy control file
cp orioledb.control $out/share/postgresql/extension/

runHook postInstall
'';
doCheck = true;
meta = with lib; {
description = "orioledb";
maintainers = with maintainers; [ samrose ];
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
};
Expand Down
1 change: 0 additions & 1 deletion nix/ext/pg-safeupdate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ stdenv.mkDerivation rec {
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
broken = versionOlder postgresql.version "14";
maintainers = with maintainers; [ samrose ];
};
}
1 change: 0 additions & 1 deletion nix/ext/pg_backtrace.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ stdenv.mkDerivation rec {
meta = with lib; {
description = "Updated fork of pg_backtrace";
homepage = "https://github.com/pashkinelfe/pg_backtrace";
maintainers = with maintainers; [ samrose ];
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
};
Expand Down
Loading