forked from caravancoop/sfm
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
48 lines (39 loc) · 1.62 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
SHELL := /bin/bash
LIVE_DB=sfm
IMPORT_DB=importer
IMPORT_DIRECTORY=sfm-importer
PG_HOST=localhost
PG_USER=datamade
PG_PASSWORD=
SOURCE_DATA_PATH=sfm_pc/management/commands/country_data/countries
DATA_ARCHIVE_PATH=data/wwic_download/countries
.PHONY : import_directory import_db flush_db recreate_db
import_directory :
# Fail if we are not in the correct directory
[[ "$$PWD" =~ "$(IMPORT_DIRECTORY)" ]]
import_db : import_directory
# Drop and recreate the importer database from the live database
if [ -n "$(PG_PASSWORD)" ]; then \
PGPASSWORD=$(PG_PASSWORD) dropdb -U postgres -h $(PG_HOST) $(IMPORT_DB) || echo "$(IMPORT_DB) does not exist"; \
PGPASSWORD=$(PG_PASSWORD) psql -U postgres -h $(PG_HOST) -c "CREATE DATABASE $(IMPORT_DB) WITH TEMPLATE $(LIVE_DB) OWNER $(PG_USER)"; \
else \
dropdb -U postgres -h $(PG_HOST) $(IMPORT_DB) || echo "$(IMPORT_DB) does not exist"; \
psql -U postgres -h $(PG_HOST) -c "CREATE DATABASE $(IMPORT_DB) WITH TEMPLATE $(LIVE_DB) OWNER $(PG_USER)"; \
fi
auth_models.json : import_directory import_db
# Dump the existing user data
python manage.py dumpdata auth.User auth.Group > $@
flush_db : import_directory auth_models.json
# Remove all data from the database
python manage.py flush
# Reload the user data
python manage.py loaddata auth_models.json
# Reload country codes
python manage.py update_countries_plus
recreate_db : import_directory flush_db import_docket_import data_archive
# Update data derived from entity tables
python manage.py rebuild_index --noinput
python manage.py update_composition_index --recreate
clean :
rm auth_models.json *errors.csv
include docket.mk download.mk