1
|
##### Vars/functions
|
2
|
|
3
|
# Paths
|
4
|
bin := ../bin
|
5
|
|
6
|
# Terminal
|
7
|
esc := '['
|
8
|
reset := $(esc)'0m'
|
9
|
emph := $(esc)'7m '
|
10
|
endEmph := ' '$(reset)
|
11
|
|
12
|
# User interaction
|
13
|
|
14
|
confirm = $(if $(shell read -p $(emph)"$(1)"$(endEmph)$$'$(if\
|
15
|
$(2),\n$(2))\nContinue? (y/n) ' REPLY; test "$$REPLY" = y && echo t),,\
|
16
|
$(error Aborting))
|
17
|
|
18
|
# DB
|
19
|
psqlVerbose := $(bin)/psql_script_vegbien --echo-all
|
20
|
pg_dump := $(bin)/pg_dump_vegbien
|
21
|
rmSchema = 'DROP SCHEMA IF EXISTS "$(1)" CASCADE;'
|
22
|
|
23
|
##### General targets
|
24
|
|
25
|
all:
|
26
|
|
27
|
.SUFFIXES: # turn off built-in suffix rules
|
28
|
.SECONDARY: # don't automatically delete intermediate files
|
29
|
.DELETE_ON_ERROR: # delete target if recipe fails
|
30
|
|
31
|
_always:
|
32
|
.PHONY: _always
|
33
|
|
34
|
##### Backups
|
35
|
|
36
|
# Must come before %.sql with no prerequisites to be matched first
|
37
|
%.sql: %
|
38
|
$(restore) $< >$@ 2>$<.extract.log
|
39
|
|
40
|
# Note: This can't be used for the current (unrotated) public schema because
|
41
|
# pg_dump doesn't back up the CREATE SCHEMA statement for it, assuming falsely
|
42
|
# that public already exists because it's in template1.
|
43
|
%.backup %.sql:
|
44
|
"time" env data=1 $(if $(filter %.sql,$@),plain=1) $(pg_dump) $* >$@
|
45
|
|
46
|
restore := "time" $(bin)/postgres_vegbien pg_restore --exit-on-error --verbose
|
47
|
restoreBien := $(restore) --dbname=vegbien
|
48
|
# pg_restore doesn't support PGDATABASE env var
|
49
|
|
50
|
%/restore: % _always
|
51
|
$(restoreBien) $< &>$<.log
|
52
|
|
53
|
##### Archived imports
|
54
|
|
55
|
confirmRm = $(call confirm,WARNING: This will delete the archived import $(1)!)
|
56
|
|
57
|
%.backup/remove: %.backup _always
|
58
|
@$(call confirmRm,$*)
|
59
|
echo $(call rmSchema,$*)|$(bin)/psql_script_vegbien
|
60
|
|
61
|
%.backup/rm_indexes: %.backup _always
|
62
|
$(pg_dump) $*|$(bin)/mk_rm_indexes|$(psqlVerbose)
|