1 |
6912
|
aaronmk
|
selfDir_AkFFYJ := $(dir $(lastword $(MAKEFILE_LIST)))
|
2 |
|
|
root := $(selfDir_AkFFYJ)..
|
3 |
|
|
include $(root)/lib/common.Makefile
|
4 |
|
|
|
5 |
|
|
|
6 |
6979
|
aaronmk
|
##### Vars/functions
|
7 |
|
|
|
8 |
|
|
# Make
|
9 |
|
|
SHELL := /bin/bash
|
10 |
|
|
|
11 |
785
|
aaronmk
|
##### General targets
|
12 |
387
|
aaronmk
|
|
13 |
8183
|
aaronmk
|
all = vegbien.sql vegbien.my.sql util.sql py_util.sql
|
14 |
387
|
aaronmk
|
|
15 |
418
|
aaronmk
|
all: _always $(all) ;
|
16 |
387
|
aaronmk
|
|
17 |
|
|
clean: _always
|
18 |
|
|
$(RM) $(all)
|
19 |
|
|
|
20 |
6916
|
aaronmk
|
%/reinstall: _always %/uninstall %/install ;
|
21 |
|
|
|
22 |
|
|
##### Installation
|
23 |
|
|
|
24 |
8183
|
aaronmk
|
schemas := temp util py_util
|
25 |
6916
|
aaronmk
|
install: $(schemas:%=%/install) ;
|
26 |
|
|
|
27 |
8183
|
aaronmk
|
schemasReversed := py_util util temp
|
28 |
6916
|
aaronmk
|
uninstall: $(schemasReversed:%=%/uninstall) ;
|
29 |
|
|
|
30 |
|
|
psqlAsAdminVegbien := $(psqlAsAdmin) vegbien
|
31 |
|
|
psqlNoSearchPath := env no_search_path=1 ../bin/psql_script_vegbien
|
32 |
|
|
|
33 |
6935
|
aaronmk
|
# Must come before `%/install: vegbien.sql` to override it
|
34 |
|
|
%/install: %.sql _always
|
35 |
|
|
-<$< $(psqlNoSearchPath)
|
36 |
|
|
# ignore errors if schema exists
|
37 |
|
|
|
38 |
6933
|
aaronmk
|
%/uninstall: _always
|
39 |
|
|
@$(if $(filter public% r%,$*),$(call confirmRmPublicSchema,$*))
|
40 |
|
|
echo $(call rmSchemaCmd,$*)|$(psqlNoSearchPath)
|
41 |
|
|
|
42 |
6916
|
aaronmk
|
#### public
|
43 |
|
|
|
44 |
6928
|
aaronmk
|
confirmRmPublicSchema = $(call confirm,WARNING: This will delete the $(1)\
|
45 |
|
|
schema of your VegBIEN DB!,$(2))
|
46 |
6916
|
aaronmk
|
|
47 |
6919
|
aaronmk
|
# Installs a version of the public schema
|
48 |
6935
|
aaronmk
|
%/install: vegbien.sql _always
|
49 |
6982
|
aaronmk
|
echo $(call mkSchemaCmd,$*)\
|
50 |
10882
|
aaronmk
|
"COMMENT ON SCHEMA \"$*\" IS 'Version: $* ($(date))';"|$(psqlNoSearchPath)
|
51 |
10883
|
aaronmk
|
<$< $(sed) 's/( )public([,; ])/\1"$*"\2/g'|$(psqlNoSearchPath)
|
52 |
6919
|
aaronmk
|
|
53 |
6922
|
aaronmk
|
# Replaces the current public schema with the given version
|
54 |
6932
|
aaronmk
|
%/publish: _always
|
55 |
6928
|
aaronmk
|
@$(call confirmRmPublicSchema,public,To save it: make schemas/rotate)
|
56 |
6986
|
aaronmk
|
echo $(call rmSchemaCmd,public)'ALTER SCHEMA "$*" RENAME TO public;'\
|
57 |
|
|
|$(psqlNoSearchPath) --file - --single-transaction
|
58 |
6945
|
aaronmk
|
@echo $(emph)'In your shell, run:'$(endEmph)'unset version'
|
59 |
6922
|
aaronmk
|
|
60 |
6916
|
aaronmk
|
rename/%: _always
|
61 |
|
|
echo 'ALTER SCHEMA public RENAME TO "$*";'|$(psqlNoSearchPath)
|
62 |
|
|
$(MAKE) public/install
|
63 |
|
|
|
64 |
6936
|
aaronmk
|
rotate: _always rename/$(version) ;
|
65 |
6916
|
aaronmk
|
|
66 |
8183
|
aaronmk
|
#### py_util
|
67 |
6916
|
aaronmk
|
|
68 |
8183
|
aaronmk
|
py_util/install: py_util.sql _always
|
69 |
6955
|
aaronmk
|
-<$< $(psqlAsAdminVegbien)
|
70 |
6916
|
aaronmk
|
# ignore errors if schema exists
|
71 |
|
|
|
72 |
|
|
#### Others
|
73 |
|
|
|
74 |
|
|
# Needed on Ubuntu 12.04 (also other Linuxes?) because %/reinstall is ignored.
|
75 |
|
|
temp/reinstall: _always temp/uninstall temp/install ;
|
76 |
|
|
|
77 |
785
|
aaronmk
|
##### MySQL schema for ERD
|
78 |
533
|
aaronmk
|
|
79 |
809
|
aaronmk
|
repl = ../bin/repl
|
80 |
541
|
aaronmk
|
|
81 |
809
|
aaronmk
|
%.my.sql: %.sql ../lib/PostgreSQL-MySQL.csv filter_ERD.csv
|
82 |
|
|
$(repl) <$(wordlist 1,2,$+)|$(repl) $(word 3,$+) >$@
|
83 |
2979
|
aaronmk
|
|
84 |
6916
|
aaronmk
|
##### DDL generation
|
85 |
2979
|
aaronmk
|
|
86 |
6029
|
aaronmk
|
pg_dump = env schema= ../bin/pg_dump_vegbien $(1) >$@
|
87 |
2979
|
aaronmk
|
|
88 |
|
|
vegbien.sql:
|
89 |
7093
|
aaronmk
|
unset version dump_opts; $(call pg_dump,public)
|
90 |
2979
|
aaronmk
|
|
91 |
8183
|
aaronmk
|
py_util.sql:
|
92 |
|
|
env owners=1 $(call pg_dump,py_util)
|
93 |
2979
|
aaronmk
|
|
94 |
|
|
# Must come after %.my.sql so that gets matched first
|
95 |
|
|
%.sql:
|
96 |
|
|
$(call pg_dump,$*)
|