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