Skip to content

Commit 68b905c

Browse files
committed
chore: mv ansible migration test to nix flake check
migration tests are now run on `nix flake check`: - tests for some extensions are adjusted to run conditionally on non-orioledb + preserves behavior from the ansible tests - ebssurrogate/files/unit-tests/unit-test-01.sql are deleted + these tests are already included nix/test/prime.sql cleanup ansible/tasks/test-image.yml: - remove pg_prove since it's no longer used - remove unit tests since the same logic is already included nix/tests/prime.sql - remove migration tests since it's now tested with nix flake check
1 parent 231bc5f commit 68b905c

File tree

7 files changed

+67
-170
lines changed

7 files changed

+67
-170
lines changed

Diff for: ansible/tasks/test-image.yml

+3-64
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
- name: install pg_prove
2-
apt:
3-
pkg:
4-
- libtap-parser-sourcehandler-pgtap-perl
5-
when: debpkg_mode
6-
71
# - name: Temporarily disable PG Sodium references in config
82
# become: yes
93
# become_user: postgres
@@ -16,9 +10,9 @@
1610
become_user: postgres
1711
shell:
1812
cmd: >
19-
sed -i.bak
20-
-e 's/\(shared_preload_libraries = '\''.*\)pgsodium,\(.*'\''\)/\1\2/'
21-
-e 's/\(shared_preload_libraries = '\''.*\)supabase_vault,\(.*'\''\)/\1\2/'
13+
sed -i.bak
14+
-e 's/\(shared_preload_libraries = '\''.*\)pgsodium,\(.*'\''\)/\1\2/'
15+
-e 's/\(shared_preload_libraries = '\''.*\)supabase_vault,\(.*'\''\)/\1\2/'
2216
-e 's/\(shared_preload_libraries = '\''.*\), *supabase_vault'\''/\1'\''/'
2317
-e 's/pgsodium.getkey_script=/#pgsodium.getkey_script=/'
2418
/etc/postgresql/postgresql.conf
@@ -74,53 +68,6 @@
7468
LOCALE_ARCHIVE: /usr/lib/locale/locale-archive
7569
when: stage2_nix
7670

77-
78-
- name: Check psql_version and modify migrations if oriole-xx
79-
block:
80-
- name: Check if psql_version is psql_orioledb-xx
81-
set_fact:
82-
is_psql_oriole: "{{ psql_version in ['psql_orioledb-16', 'psql_orioledb-17'] }}"
83-
84-
- name: Remove specified extensions from SQL file
85-
ansible.builtin.command:
86-
cmd: >
87-
sed -i '/\\ir.*\(timescaledb\|postgis\|pgrouting\|plv8\).*\.sql/d' /tmp/migrations/tests/extensions/test.sql
88-
when: is_psql_oriole
89-
become: yes
90-
91-
- name: Remove specified extension files from extensions directory
92-
ansible.builtin.find:
93-
paths: /tmp/migrations/tests/extensions
94-
patterns:
95-
- '*timescaledb*.sql'
96-
- '*plv8*.sql'
97-
- '*postgis*.sql'
98-
- '*pgrouting*.sql'
99-
register: files_to_remove
100-
when: is_psql_oriole
101-
102-
- name: Delete matched extension files
103-
ansible.builtin.file:
104-
path: "{{ item.path }}"
105-
state: absent
106-
loop: "{{ files_to_remove.files }}"
107-
when: is_psql_oriole
108-
become: yes
109-
110-
- name: Run Unit tests (with filename unit-test-*) on Postgres Database
111-
shell: /usr/bin/pg_prove -U postgres -h localhost -d postgres -v /tmp/unit-tests/unit-test-*.sql
112-
register: retval
113-
failed_when: retval.rc != 0
114-
when: debpkg_mode or stage2_nix
115-
116-
- name: Run migrations tests
117-
shell: /usr/bin/pg_prove -U supabase_admin -h localhost -d postgres -v tests/test.sql
118-
register: retval
119-
failed_when: retval.rc != 0
120-
when: debpkg_mode or stage2_nix
121-
args:
122-
chdir: /tmp/migrations
123-
12471
- name: Re-enable PG Sodium references in config
12572
become: yes
12673
become_user: postgres
@@ -132,14 +79,6 @@
13279
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();'
13380
when: debpkg_mode or stage2_nix
13481

135-
- name: remove pg_prove
136-
apt:
137-
pkg:
138-
- libtap-parser-sourcehandler-pgtap-perl
139-
state: absent
140-
autoremove: yes
141-
when: debpkg_mode
142-
14382
- name: Stop Postgres Database
14483
become: yes
14584
become_user: postgres

Diff for: ebssurrogate/files/unit-tests/unit-test-01.sql

-58
This file was deleted.

Diff for: flake.nix

+3
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@
807807
exit 1
808808
fi
809809
810+
echo "Running migrations tests"
811+
pg_prove -p 5435 -U supabase_admin -h localhost -d postgres -v ${./migrations/tests}/test.sql
812+
810813
mkdir -p $out/regression_output
811814
if ! pg_regress \
812815
--use-existing \

Diff for: migrations/tests/extensions/01-postgis.sql

+34-39
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,38 @@
1-
BEGIN;
2-
create extension if not exists postgis_sfcgal with schema "extensions" cascade;
3-
ROLLBACK;
1+
begin;
2+
do $_$
3+
begin
4+
if not exists (select 1 from pg_extension where extname = 'orioledb') then
5+
-- create postgis tiger as supabase_admin
6+
create extension if not exists postgis_tiger_geocoder cascade;
47

5-
BEGIN;
6-
create extension if not exists postgis_raster with schema "extensions" cascade;
7-
ROLLBACK;
8+
-- \ir ansible/files/postgresql_extension_custom_scripts/postgis_tiger_geocoder/after-create.sql
9+
grant usage on schema tiger, tiger_data to postgres with grant option;
10+
grant all privileges on all tables in schema tiger, tiger_data to postgres with grant option;
11+
grant all privileges on all routines in schema tiger, tiger_data to postgres with grant option;
12+
grant all privileges on all sequences in schema tiger, tiger_data to postgres with grant option;
13+
alter default privileges in schema tiger, tiger_data grant all on tables to postgres with grant option;
14+
alter default privileges in schema tiger, tiger_data grant all on routines to postgres with grant option;
15+
alter default privileges in schema tiger, tiger_data grant all on sequences to postgres with grant option;
16+
SET search_path TO extensions, public, tiger, tiger_data;
17+
-- postgres role should have access
18+
set local role postgres;
19+
perform tiger.pprint_addy(tiger.pagc_normalize_address('710 E Ben White Blvd, Austin, TX 78704'));
820

9-
BEGIN;
10-
-- create postgis tiger as supabase_admin
11-
create extension if not exists address_standardizer with schema extensions;
12-
create extension if not exists postgis_tiger_geocoder cascade;
21+
-- other roles can be granted access
22+
grant usage on schema tiger, tiger_data to authenticated;
23+
grant select on all tables in schema tiger, tiger_data to authenticated;
24+
grant execute on all routines in schema tiger, tiger_data to authenticated;
1325

14-
-- \ir ansible/files/postgresql_extension_custom_scripts/postgis_tiger_geocoder/after-create.sql
15-
grant usage on schema tiger, tiger_data to postgres with grant option;
16-
grant all privileges on all tables in schema tiger, tiger_data to postgres with grant option;
17-
grant all privileges on all routines in schema tiger, tiger_data to postgres with grant option;
18-
grant all privileges on all sequences in schema tiger, tiger_data to postgres with grant option;
19-
alter default privileges in schema tiger, tiger_data grant all on tables to postgres with grant option;
20-
alter default privileges in schema tiger, tiger_data grant all on routines to postgres with grant option;
21-
alter default privileges in schema tiger, tiger_data grant all on sequences to postgres with grant option;
22-
SET search_path TO extensions, public, tiger, tiger_data;
23-
-- postgres role should have access
24-
set local role postgres;
25-
select tiger.pprint_addy(tiger.pagc_normalize_address('710 E Ben White Blvd, Austin, TX 78704'));
26+
-- authenticated role should have access now
27+
set local role authenticated;
28+
perform tiger.pprint_addy(tiger.pagc_normalize_address('710 E Ben White Blvd, Austin, TX 78704'));
29+
reset role;
2630

27-
-- other roles can be granted access
28-
grant usage on schema tiger, tiger_data to authenticated;
29-
grant select on all tables in schema tiger, tiger_data to authenticated;
30-
grant execute on all routines in schema tiger, tiger_data to authenticated;
31-
32-
-- authenticated role should have access now
33-
set local role authenticated;
34-
select tiger.pprint_addy(tiger.pagc_normalize_address('710 E Ben White Blvd, Austin, TX 78704'));
35-
ROLLBACK;
36-
37-
BEGIN;
38-
-- address standardizer creates a table in extensions schema, owned by supabase_admin
39-
create extension if not exists address_standardizer_data_us with schema extensions;
40-
-- postgres role should have access
41-
set local role postgres;
42-
select * from extensions.us_lex;
43-
ROLLBACK;
31+
-- postgres role should have access to address_standardizer_data_us
32+
set local role postgres;
33+
perform 1 from us_lex;
34+
reset role;
35+
end if;
36+
end
37+
$_$;
38+
rollback;

Diff for: migrations/tests/extensions/02-pgrouting.sql

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
BEGIN;
2-
create extension if not exists pgrouting with schema "extensions" cascade;
3-
ROLLBACK;
1+
begin;
2+
do $_$
3+
begin
4+
if not exists (select 1 from pg_extension where extname = 'orioledb') then
5+
create extension if not exists pgrouting with schema "extensions" cascade;
6+
end if;
7+
end
8+
$_$;
9+
rollback;

Diff for: migrations/tests/extensions/10-timescaledb.sql

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
BEGIN;
2-
create extension if not exists timescaledb with schema "extensions";
3-
ROLLBACK;
1+
begin;
2+
do $_$
3+
begin
4+
if not exists (select 1 from pg_extension where extname = 'orioledb') then
5+
create extension if not exists timescaledb with schema "extensions";
6+
end if;
7+
end
8+
$_$;
9+
rollback;

Diff for: migrations/tests/extensions/13-plv8.sql

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
BEGIN;
2-
create extension if not exists plv8 with schema "pg_catalog";
3-
ROLLBACK;
1+
begin;
2+
do $_$
3+
begin
4+
if not exists (select 1 from pg_extension where extname = 'orioledb') then
5+
create extension if not exists plv8 with schema "pg_catalog";
6+
end if;
7+
end
8+
$_$;
9+
rollback;

0 commit comments

Comments
 (0)