Skip to content
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

Fix search wetland sites by site code, fix db restore #3646

Merged
merged 1 commit into from
Dec 27, 2023
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
3 changes: 2 additions & 1 deletion bims/api_views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,8 @@ def get_summary_data(self):
sites_without_occurrences = LocationSite.objects.exclude(
id__in=sites.values('site_id')
).filter(
site_code__icontains=self.search_query
site_code__icontains=self.search_query,
ecosystem_type__in=self.ecosystem_type
).extra(
select={
'name': 'site_code'
Expand Down
16 changes: 16 additions & 0 deletions deployment/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,19 @@ reset-search-results:
@docker-compose exec dev python /home/web/django_project/manage.py clear_search_results
@docker-compose ${ARGS} restart worker
@docker-compose ${ARGS} restart cache


dbrestore:
@echo
@echo "------------------------------------------------------------------"
@echo "Stopping the database service"
@echo "------------------------------------------------------------------"
@docker-compose ${ARGS} stop db
@echo
@echo "------------------------------------------------------------------"
@echo "Starting the database restoration process"
@echo "------------------------------------------------------------------"
@docker-compose ${ARGS} up -d db-restore
@docker-compose ${ARGS} exec db-restore /restore-db.sh
@docker-compose ${ARGS }stop db-restore
@docker-compose ${ARGS} up -d db
15 changes: 15 additions & 0 deletions deployment/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ services:
ports:
- "6543:5432"

db-restore:
image: kartoza/postgis:15-3.3
profiles:
- dev
volumes:
- ./pg/postgres_data:/var/lib/postgresql
- ./backups:/backups
- ./restore-db.sh:/restore-db.sh
- ./revoke.sql:/revoke.sql
environment:
ALLOW_IP_RANGE: 0.0.0.0/0
POSTGRES_USER: ${POSTGRES_USER:-docker}
POSTGRES_PASS: ${POSTGRES_PASS:-docker}
POSTGRES_DBNAME: ${POSTGRES_DBNAME:-gis}

geoserver:
container_name: bims_dev_geoserver
image: kartoza/geoserver:2.19.0
Expand Down
19 changes: 19 additions & 0 deletions deployment/restore-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Wait for the PostgreSQL server to start
echo "Waiting for PostgreSQL to start..."
while ! pg_isready -h db-restore -p 5432 -U ${POSTGRES_USER}; do
sleep 1
done
echo "PostgreSQL started."

# Revoke connections and terminate backends
su - postgres -c "psql gis -f /revoke.sql"

# Sleep for a short time to ensure that the sessions are terminated
sleep 2

# Drop the database
su - postgres -c "psql -c 'DROP DATABASE IF EXISTS gis;'"

su - postgres -c "createdb -O docker gis"
su - postgres -c 'pg_restore -d gis /backups/latest.dmp'
5 changes: 5 additions & 0 deletions deployment/revoke.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
REVOKE CONNECT ON DATABASE gis FROM public;

SELECT pid, pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE datname = current_database() AND pid <> pg_backend_pid();
Loading