1
|
selfDir_AkFFYJ := $(dir $(lastword $(MAKEFILE_LIST)))
|
2
|
root := $(selfDir_AkFFYJ)..
|
3
|
include $(root)/lib/common.Makefile
|
4
|
|
5
|
|
6
|
##### General targets
|
7
|
|
8
|
all = vegbien.sql vegbien.my.sql functions.sql py_functions.sql
|
9
|
|
10
|
all: _always $(all) ;
|
11
|
|
12
|
clean: _always
|
13
|
$(RM) $(all)
|
14
|
|
15
|
%/reinstall: _always %/uninstall %/install ;
|
16
|
|
17
|
##### Installation
|
18
|
|
19
|
schemas := temp functions py_functions public
|
20
|
install: $(schemas:%=%/install) ;
|
21
|
|
22
|
schemasReversed := public py_functions functions temp
|
23
|
uninstall: $(schemasReversed:%=%/uninstall) ;
|
24
|
|
25
|
psqlOpts := --set ON_ERROR_STOP=1 --quiet
|
26
|
asAdmin := sudo -E -u postgres
|
27
|
psqlAsAdmin := $(asAdmin) psql $(psqlOpts)
|
28
|
# -E preserves env vars so PGOPTIONS is passed to psql
|
29
|
psqlAsAdminVegbien := $(psqlAsAdmin) vegbien
|
30
|
psqlNoSearchPath := env no_search_path=1 ../bin/psql_script_vegbien
|
31
|
|
32
|
#### public
|
33
|
|
34
|
confirmRmPublicSchema = $(call confirm,WARNING: This will delete the current\
|
35
|
public schema of your VegBIEN DB!,To save it: make schemas/rotate)
|
36
|
|
37
|
rmPublicSchema := $(call rmSchemaCmd,public)
|
38
|
|
39
|
public/install: vegbien.sql _always
|
40
|
-echo $(call mkSchemaCmd,public)|$(psqlNoSearchPath)
|
41
|
<$< $(psqlNoSearchPath)
|
42
|
# ignore errors if schema exists
|
43
|
# public schema will be owned by bien
|
44
|
# don't include public in the search_path
|
45
|
|
46
|
public/uninstall: _always
|
47
|
@$(confirmRmPublicSchema)
|
48
|
echo $(rmPublicSchema)|$(psqlNoSearchPath)
|
49
|
|
50
|
rename/%: _always
|
51
|
echo 'ALTER SCHEMA public RENAME TO "$*";'|$(psqlNoSearchPath)
|
52
|
$(MAKE) public/install
|
53
|
|
54
|
rotate: _always rename/public.$(version) ;
|
55
|
|
56
|
#### py_functions
|
57
|
|
58
|
py_functions/install: py_functions.sql _always
|
59
|
-<$< env public= $(psqlAsAdminVegbien)
|
60
|
# ignore errors if schema exists
|
61
|
|
62
|
#### Others
|
63
|
|
64
|
%/install: %.sql _always
|
65
|
-<$< $(psqlNoSearchPath)
|
66
|
# ignore errors if schema exists
|
67
|
|
68
|
%/uninstall: _always
|
69
|
echo $(call rmSchemaCmd,$*)|$(psqlNoSearchPath)
|
70
|
|
71
|
# Needed on Ubuntu 12.04 (also other Linuxes?) because %/reinstall is ignored.
|
72
|
temp/reinstall: _always temp/uninstall temp/install ;
|
73
|
|
74
|
##### MySQL schema for ERD
|
75
|
|
76
|
repl = ../bin/repl
|
77
|
|
78
|
%.my.sql: %.sql ../lib/PostgreSQL-MySQL.csv filter_ERD.csv
|
79
|
$(repl) <$(wordlist 1,2,$+)|$(repl) $(word 3,$+) >$@
|
80
|
|
81
|
##### DDL generation
|
82
|
|
83
|
pg_dump = env schema= ../bin/pg_dump_vegbien $(1) >$@
|
84
|
|
85
|
vegbien.sql:
|
86
|
$(call pg_dump,public)
|
87
|
|
88
|
py_functions.sql:
|
89
|
env owners=1 $(call pg_dump,py_functions)
|
90
|
|
91
|
# Must come after %.my.sql so that gets matched first
|
92
|
%.sql:
|
93
|
$(call pg_dump,$*)
|