This repository has been archived by the owner on Jul 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sql
160 lines (135 loc) · 4.36 KB
/
install.sql
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* Install SQL
* Required if the module has menu entries
* - Add profile exceptions for the module to appear in the menu
* - Add program config options if any (to every schools)
* - Add module specific tables (and their eventual sequences & indexes)
* if any: see rosariosis.sql file for examples
*
* @package Reports module
*/
-- Fix #102 error language "plpgsql" does not exist
-- http://timmurphy.org/2011/08/27/create-language-if-it-doesnt-exist-in-postgresql/
--
-- Name: create_language_plpgsql(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION create_language_plpgsql()
RETURNS BOOLEAN AS $$
CREATE LANGUAGE plpgsql;
SELECT TRUE;
$$ LANGUAGE SQL;
SELECT CASE WHEN NOT (
SELECT TRUE AS exists FROM pg_language
WHERE lanname='plpgsql'
UNION
SELECT FALSE AS exists
ORDER BY exists DESC
LIMIT 1
) THEN
create_language_plpgsql()
ELSE
FALSE
END AS plpgsql_created;
DROP FUNCTION create_language_plpgsql();
--
-- Data for Name: profile_exceptions; Type: TABLE DATA;
--
INSERT INTO profile_exceptions (profile_id, modname, can_use, can_edit)
SELECT 1, 'Reports/SavedReports.php', 'Y', 'Y'
WHERE NOT EXISTS (SELECT profile_id
FROM profile_exceptions
WHERE modname='Reports/SavedReports.php'
AND profile_id=1);
INSERT INTO profile_exceptions (profile_id, modname, can_use, can_edit)
SELECT 1, 'Reports/Calculations.php', 'Y', 'Y'
WHERE NOT EXISTS (SELECT profile_id
FROM profile_exceptions
WHERE modname='Reports/Calculations.php'
AND profile_id=1);
INSERT INTO profile_exceptions (profile_id, modname, can_use, can_edit)
SELECT 1, 'Reports/CalculationsReports.php', 'Y', 'Y'
WHERE NOT EXISTS (SELECT profile_id
FROM profile_exceptions
WHERE modname='Reports/CalculationsReports.php'
AND profile_id=1);
--
-- Name: saved_calculations; Type: TABLE; ; Tablespace:
--
CREATE OR REPLACE FUNCTION create_table_saved_calculations() RETURNS void AS
$func$
BEGIN
IF EXISTS (SELECT 1 FROM pg_catalog.pg_tables
WHERE schemaname=CURRENT_SCHEMA()
AND tablename='saved_calculations') THEN
RAISE NOTICE 'Table "saved_calculations" already exists.';
ELSE
CREATE TABLE saved_calculations (
id numeric NOT NULL,
title character varying(100),
url character varying(5000)
);
END IF;
END
$func$ LANGUAGE plpgsql;
SELECT create_table_saved_calculations();
DROP FUNCTION create_table_saved_calculations();
--
-- Name: saved_calculations_seq; Type: SEQUENCE;
--
CREATE OR REPLACE FUNCTION create_sequence_saved_calculations_seq() RETURNS void AS
$func$
BEGIN
CREATE SEQUENCE saved_calculations_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
EXCEPTION WHEN duplicate_table THEN
RAISE NOTICE 'Sequence "saved_calculations_seq" already exists.';
END
$func$ LANGUAGE plpgsql;
SELECT create_sequence_saved_calculations_seq();
DROP FUNCTION create_sequence_saved_calculations_seq();
--
-- Name: saved_reports; Type: TABLE; ; Tablespace:
--
CREATE OR REPLACE FUNCTION create_table_saved_reports() RETURNS void AS
$func$
BEGIN
IF EXISTS (SELECT 1 FROM pg_catalog.pg_tables
WHERE schemaname=CURRENT_SCHEMA()
AND tablename='saved_reports') THEN
RAISE NOTICE 'Table "saved_reports" already exists.';
ELSE
CREATE TABLE saved_reports (
id numeric NOT NULL,
title character varying(100),
staff_id numeric,
php_self character varying(5000),
search_php_self character varying(5000),
search_vars character varying(5000)
);
END IF;
END
$func$ LANGUAGE plpgsql;
SELECT create_table_saved_reports();
DROP FUNCTION create_table_saved_reports();
--
-- Name: saved_reports_seq; Type: SEQUENCE;
--
CREATE OR REPLACE FUNCTION create_sequence_saved_reports_seq() RETURNS void AS
$func$
BEGIN
CREATE SEQUENCE saved_reports_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
EXCEPTION WHEN duplicate_table THEN
RAISE NOTICE 'Sequence "saved_reports_seq" already exists.';
END
$func$ LANGUAGE plpgsql;
SELECT create_sequence_saved_reports_seq();
DROP FUNCTION create_sequence_saved_reports_seq();