1 dnl Copyright (C) 2013 The Meme Factory, Inc., http://www.meme.com/
3 dnl This file is part of GombeMI.
5 dnl GombeMI is free software; you can redistribute it and/or modify
6 dnl it under the terms of the GNU General Public License as published by
7 dnl the Free Software Foundation; either version 3 of the License, or
8 dnl (at your option) any later version.
10 dnl This program is distributed in the hope that it will be useful,
11 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 dnl GNU General Public License for more details.
15 dnl You should have received a copy of the GNU General Public License
16 dnl along with GombeMI. If not, see <http://www.gnu.org/licenses/>.
18 dnl Creates fully populated conversion schema.
20 dnl Karl O. Pinc <kop@meme.com>
26 dnl Intended to be piped to psql run as gombemi_admin.
28 include(`copyright.m4')
29 include(`constants.m4')
33 -- The gombemi schema where the production system lives.
36 CREATE SCHEMA conversion;
38 GRANT USAGE ON SCHEMA conversion TO gombemi_editors
41 SET SEARCH_PATH TO conversion;
44 -- Create all the tables.
47 -- cross_reference_for_program
48 create table cross_reference_forprogram (
49 tableid serial primary key
57 ,"Start Entry Date" date
58 ,"End Entry Date" date
62 ,"Group comp problem?" text
65 ,"Also Checked By" text
66 ,"Last Checked By Date" text
67 ,"Absent Mother/Infant" text
73 ,"Paper Follow Location" text
78 create unique index crfp_date_mom
79 on cross_reference_forprogram("Follow Date", "Focal mom");
81 grant_priv(`cross_reference_forprogram')
82 grant_seq_priv(`cross_reference_forprogram', `tableid')
86 create table page_followtype (
87 tableid serial primary key
94 create index page_followtype_date_mom_page
95 on page_followtype(date, mom, page);
97 grant_priv(`page_followtype')
98 grant_seq_priv(`page_followtype', `tableid')
102 create table follow (
103 tableid serial primary key
107 ,"Infant2_id" varchar
108 ,"Sibling_id" varchar
109 ,"Sibling2_id" varchar
110 ,"Conducted_by" varchar
111 ,"Entered_by" varchar
114 ,"Right_group_id" int
115 ,"Follow_status" varchar
121 create unique index follow_follow_id on follow ("Follow_id");
122 create index follow_date on follow ("Follow_date");
125 grant_seq_priv(`follow', `tableid')
129 create table follow_page (
130 tableid serial primary key
138 create index follow_page_follow_id on follow_page("Follow_id");
139 create unique index follow_page_page_id on follow_page ("Page_id");
141 grant_priv(`follow_page')
142 grant_seq_priv(`follow_page', `tableid')
146 create table follow_1_minute (
147 tableid serial primary key
149 ,"Interval_number" int
150 ,"Interval_time" timestamp without time zone
151 ,"Bad_observation" varchar
154 ,"CommentRTF" varchar
155 ,"Interval_id" varchar
159 follow_1_minute_interval_id on follow_1_minute ("Interval_id");
161 grant_priv(`follow_1_minute')
162 grant_seq_priv(`follow_1_minute', `tableid')
165 -- follow_1_minute_infant
166 create table follow_1_minute_infant (
167 tableid serial primary key
168 ,"Interval_id" varchar
169 constraint "follow_1_minute_infant.Interval_id must be a follow_1_minute.Interval_id"
170 REFERENCES follow_1_minute("Interval_id")
177 ,"In_contact" varchar
178 ,"Within_reach" varchar
179 ,"Within_0_5_meters" varchar
180 ,"Between_5_15_meters" varchar
181 ,"More_than_15_meters" varchar
182 ,"Rides_on_stomach" varchar
183 ,"Rides_on_back" varchar
185 ,"Contacts_other" varchar
186 ,"Grooms_other" varchar
187 ,"Groomed_by" varchar
192 ,"Vocalizations" varchar
194 ,"Aggression" varchar
195 ,"Infant_interval_id" varchar
198 create unique index follow_1_minute_infant_infant_interval_id
199 on follow_1_minute_infant ("Infant_interval_id");
201 create index follow_1_minute_infant_interval_id
202 on follow_1_minute_infant ("Interval_id");
204 grant_priv(`follow_1_minute_infant')
205 grant_seq_priv(`follow_1_minute_infant', `tableid')
208 -- follow_1_minute_mother
209 create table follow_1_minute_mother (
210 tableid serial primary key
211 ,"Interval_id" varchar
212 constraint "follow_1_minute_mother.Interval_id must be a follow_1_minute.Interval_id"
213 REFERENCES follow_1_minute("Interval_id")
216 ,"Grooms_other" varchar
217 ,"Groomed_by" varchar
218 ,"Vocalizations" varchar
221 create index follow_1_minute_mother_interval_id
222 on follow_1_minute_mother ("Interval_id");
224 grant_priv(`follow_1_minute_mother')
225 grant_seq_priv(`follow_1_minute_mother', `tableid')
228 -- follow_1_minute_sibling
229 create table follow_1_minute_sibling (
230 tableid serial primary key
231 ,"Interval_id" varchar
232 constraint "follow_1_minute_sibling.Interval_id must be a follow_1_minute.Interval_id"
233 REFERENCES follow_1_minute("Interval_id")
234 ,"Sibling_id" varchar
235 ,"Bad_observation" varchar
237 ,"Distance_from_mother" varchar
238 ,"Vocalizations" varchar
240 ,"Grooms_other" varchar
241 ,"Groomed_by" varchar
242 ,"Distance_from_infant" varchar
243 ,"Sibling_interval_id" varchar
246 create unique index follow_1_minute_sibling_sibling_interval_id
247 on follow_1_minute_sibling ("Sibling_interval_id");
249 create index follow_1_minute_sibling_interval_id
250 on follow_1_minute_sibling ("Interval_id");
252 grant_priv(`follow_1_minute_sibling')
253 grant_seq_priv(`follow_1_minute_sibling', `tableid')
257 create table follow_5_minute (
258 tableid serial primary key
260 ,"Interval_number" int
261 ,"Interval_time" timestamp without time zone
262 ,"Mother_feeding" varchar
263 ,"Food_part_initials" varchar
265 ,"Infant_feeding" varchar
266 ,"Strange_chimp" varchar
267 ,"Other_animals" varchar
268 ,"Interval_id" varchar
271 create unique index follow_5_minute_interval_id
272 on follow_5_minute ("Interval_id");
274 grant_priv(`follow_5_minute')
275 grant_seq_priv(`follow_5_minute', `tableid')
278 -- follow_5_minute_left_group
279 create table follow_5_minute_left_group (
280 tableid serial primary key
281 ,"Interval_id" varchar
282 constraint "follow_5_minute_left_group.Interval_id must be a follow_5_minute.Interval_id"
283 REFERENCES follow_5_minute("Interval_id")
284 ,"Position_number" int
287 ,"Position_id" varchar
290 create index follow_5_minute_left_group_interval_id
291 on follow_5_minute_left_group ("Interval_id");
293 grant_priv(`follow_5_minute_left_group')
294 grant_seq_priv(`follow_5_minute_left_group', `tableid')
297 -- follow_5_minute_right_group
298 create table follow_5_minute_right_group (
299 tableid serial primary key
300 ,"Interval_id" varchar
301 constraint "follow_5_minute_right_group.Interval_id must be a follow_5_minute.Interval_id"
302 REFERENCES follow_5_minute("Interval_id")
303 ,"Position_number" int
306 ,"Position_id" varchar
309 create index follow_5_minute_right_group_interval_id
310 on follow_5_minute_right_group ("Interval_id");
312 grant_priv(`follow_5_minute_right_group')
313 grant_seq_priv(`follow_5_minute_right_group', `tableid')