Skip to content

Commit

Permalink
fix: Fix copy database to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kumy committed Jul 21, 2024
1 parent c0505d5 commit ffc8391
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions website/db/tests-copy-schema-geokrety-to-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
tmp_dir=$(mktemp -d -p $DIR -t copy-schema-XXXXXXXXXX)

pg_dump --file "$tmp_dir/public-schema.sql" --host "localhost" --port "5432" --username "geokrety" --format=p --encoding "UTF8" --schema "public" "geokrety"
trap cleanup EXIT HUP INT QUIT TERM
cleanup() {
echo "Removing temporary files…"
rm -rfv "$tmp_dir"
exit
}
pg_dump --file "$tmp_dir/public-schema.sql" --host "localhost" --port "5432" --username "geokrety" --format=p --exclude-table-data=public.srtm --encoding "UTF8" --schema "public" "geokrety"
pg_dump --file "$tmp_dir/geokrety-schema.sql" --host "localhost" --port "5432" --username "geokrety" --format=p --schema-only --encoding "UTF8" --schema "geokrety" "geokrety"
pg_dump --file "$tmp_dir/audit-schema.sql" --host "localhost" --port "5432" --username "geokrety" --format=p --schema-only --encoding "UTF8" --schema "audit" "geokrety"
pg_dump --file "$tmp_dir/secure-schema.sql" --host "localhost" --port "5432" --username "geokrety" --format=p --schema-only --encoding "UTF8" --schema "secure" "geokrety"
Expand All @@ -30,9 +36,6 @@ CREATE SCHEMA pgtap;
CREATE EXTENSION IF NOT EXISTS pgtap WITH SCHEMA pgtap;
DROP SCHEMA IF EXISTS public CASCADE;
-- CREATE SCHEMA public;
-- CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;
-- CREATE EXTENSION IF NOT EXISTS postgis_raster WITH SCHEMA public;
\i $tmp_dir/public-schema.sql
DROP SCHEMA IF EXISTS notify_queues CASCADE;
Expand All @@ -53,4 +56,7 @@ REFRESH MATERIALIZED VIEW "geokrety"."gk_geokrety_in_caches";
END;
EOF

export DBNAME=tests
"${DIR}"/tests-srtm-import.sh

rm -rf $tmp_dir
2 changes: 1 addition & 1 deletion website/db/tests-srtm-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ echo "SET search_path = public;" > "$QUERIES_FILE"
raster2pgsql "$SRTM_DIR"/*.zip -F -I -e public.srtm >> "$QUERIES_FILE"

echo "Importing SQL import file…"
psql -h 127.0.0.1 -U "${PGUSER:-geokrety}" -f "$QUERIES_FILE"
psql -h 127.0.0.1 -U "${PGUSER:-geokrety}" "${DBNAME:-geokrety}" -f "$QUERIES_FILE"
4 changes: 2 additions & 2 deletions website/db/tests/test-22-sessions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ SELECT * FROM no_plan();
SET CONSTRAINTS ALL IMMEDIATE;

-- on_behalf automatically generated
INSERT INTO "sessions" ("session_id") VALUES ('test 1');
SELECT isnt(on_behalf, null ) FROM sessions WHERE session_id='test 1';
INSERT INTO "geokrety"."sessions" ("session_id") VALUES ('test 1');
SELECT isnt(on_behalf, null ) FROM geokrety.sessions WHERE session_id='test 1';

-- Finish the tests and clean up.
SELECT * FROM finish();
Expand Down

0 comments on commit ffc8391

Please sign in to comment.