Skip to content

Commit

Permalink
Fix search wetland sites by site code, fix db restore (#3646)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Dec 27, 2023
1 parent 2664da1 commit ff02242
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
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();

0 comments on commit ff02242

Please sign in to comment.