Project

General

Profile

« Previous | Next » 

Revision 684

vegbien.sql: Made planttag a child of plantobservation instead of plant, since tags change over time

View differences:

schemas/vegbien.for_ERD.my.sql
243 243
  CONSTRAINT aggregateoccurrence_keys_accessioncode UNIQUE (taxonoccurrence_id , sourceaccessioncode )
244 244
);
245 245

  
246
CREATE TABLE plant -- A physical, tagged plant.
247
(
248
  plant_id int(11) NOT NULL AUTO_INCREMENT,
249
  CONSTRAINT plant_pkey PRIMARY KEY (plant_id )
250
);
251

  
252 246
CREATE TABLE planttag
253 247
(
254 248
  planttag_id int(11) NOT NULL AUTO_INCREMENT,
255
  plant_id int(11) NOT NULL,
249
  plantobservation_id int(11) NOT NULL,
256 250
  tag character varying(255) NOT NULL,
251
  iscurrent int(1) NOT NULL DEFAULT true,
257 252
  CONSTRAINT planttag_pkey PRIMARY KEY (planttag_id ),
258
  CONSTRAINT planttag_plant_id FOREIGN KEY (plant_id)
259
      REFERENCES plant (plant_id) MATCH SIMPLE
253
  CONSTRAINT planttag_plantobservation_id FOREIGN KEY (plantobservation_id)
254
      REFERENCES plantobservation (plantobservation_id) MATCH SIMPLE
260 255
      ON UPDATE CASCADE ON DELETE CASCADE,
261
  CONSTRAINT planttag_keys UNIQUE (plant_id , tag )
256
  CONSTRAINT planttag_current_unique UNIQUE (plantobservation_id , iscurrent ),
257
  CONSTRAINT planttag_keys UNIQUE (plantobservation_id , tag )
262 258
);
263 259

  
260
CREATE TABLE plant -- A physical, tagged plant.
261
(
262
  plant_id int(11) NOT NULL AUTO_INCREMENT,
263
  CONSTRAINT plant_pkey PRIMARY KEY (plant_id )
264
);
265

  
264 266
CREATE TABLE plantobservation -- VegBank's stemcount table.
265 267
(
266 268
  plantobservation_id int(11) NOT NULL AUTO_INCREMENT,
schemas/vegbien.for_wiki.sql
63 63
  coverindex_id integer,
64 64
);
65 65

  
66
CREATE TABLE plant -- A physical, tagged plant.
67
(
68
  plant_id serial NOT NULL,
69
);
70

  
71 66
CREATE TABLE planttag
72 67
(
73 68
  planttag_id serial NOT NULL,
74
  plant_id integer NOT NULL,
69
  plantobservation_id integer NOT NULL,
75 70
  tag character varying(255) NOT NULL,
71
  iscurrent boolean NOT NULL DEFAULT true,
76 72
);
77 73

  
74
CREATE TABLE plant -- A physical, tagged plant.
75
(
76
  plant_id serial NOT NULL,
77
);
78

  
78 79
CREATE TABLE plantobservation -- VegBank's stemcount table.
79 80
(
80 81
  plantobservation_id serial NOT NULL,
schemas/vegbien.for_ERD.sql
243 243
  CONSTRAINT aggregateoccurrence_keys_accessioncode UNIQUE (taxonoccurrence_id , sourceaccessioncode )
244 244
);
245 245

  
246
CREATE TABLE plant -- A physical, tagged plant.
247
(
248
  plant_id serial NOT NULL,
249
  CONSTRAINT plant_pkey PRIMARY KEY (plant_id )
250
);
251

  
252 246
CREATE TABLE planttag
253 247
(
254 248
  planttag_id serial NOT NULL,
255
  plant_id integer NOT NULL,
249
  plantobservation_id integer NOT NULL,
256 250
  tag character varying(255) NOT NULL,
251
  iscurrent boolean NOT NULL DEFAULT true,
257 252
  CONSTRAINT planttag_pkey PRIMARY KEY (planttag_id ),
258
  CONSTRAINT planttag_plant_id FOREIGN KEY (plant_id)
259
      REFERENCES plant (plant_id) MATCH SIMPLE
253
  CONSTRAINT planttag_plantobservation_id FOREIGN KEY (plantobservation_id)
254
      REFERENCES plantobservation (plantobservation_id) MATCH SIMPLE
260 255
      ON UPDATE CASCADE ON DELETE CASCADE,
261
  CONSTRAINT planttag_keys UNIQUE (plant_id , tag )
256
  CONSTRAINT planttag_current_unique UNIQUE (plantobservation_id , iscurrent ),
257
  CONSTRAINT planttag_keys UNIQUE (plantobservation_id , tag )
262 258
);
263 259

  
260
CREATE TABLE plant -- A physical, tagged plant.
261
(
262
  plant_id serial NOT NULL,
263
  CONSTRAINT plant_pkey PRIMARY KEY (plant_id )
264
);
265

  
264 266
CREATE TABLE plantobservation -- VegBank's stemcount table.
265 267
(
266 268
  plantobservation_id serial NOT NULL,
schemas/vegbien.sql
1822 1822

  
1823 1823
CREATE TABLE planttag (
1824 1824
    planttag_id integer NOT NULL,
1825
    plant_id integer NOT NULL,
1826
    tag character varying(255) NOT NULL
1825
    plantobservation_id integer NOT NULL,
1826
    tag character varying(255) NOT NULL,
1827
    iscurrent boolean DEFAULT true NOT NULL
1827 1828
);
1828 1829

  
1829 1830

  
......
4369 4370

  
4370 4371

  
4371 4372
--
4373
-- Name: planttag_current_unique; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4374
--
4375

  
4376
ALTER TABLE ONLY planttag
4377
    ADD CONSTRAINT planttag_current_unique UNIQUE (plantobservation_id, iscurrent);
4378

  
4379

  
4380
--
4372 4381
-- Name: planttag_keys; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
4373 4382
--
4374 4383

  
4375 4384
ALTER TABLE ONLY planttag
4376
    ADD CONSTRAINT planttag_keys UNIQUE (plant_id, tag);
4385
    ADD CONSTRAINT planttag_keys UNIQUE (plantobservation_id, tag);
4377 4386

  
4378 4387

  
4379 4388
--
......
5163 5172
-- Name: fki_planttag_plant_id; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5164 5173
--
5165 5174

  
5166
CREATE INDEX fki_planttag_plant_id ON planttag USING btree (plant_id);
5175
CREATE INDEX fki_planttag_plant_id ON planttag USING btree (plantobservation_id);
5167 5176

  
5168 5177

  
5169 5178
--
5179
-- Name: fki_planttag_plantobservation_id; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5180
--
5181

  
5182
CREATE INDEX fki_planttag_plantobservation_id ON planttag USING btree (plantobservation_id);
5183

  
5184

  
5185
--
5170 5186
-- Name: fki_specimenreplicate_museum_id; Type: INDEX; Schema: public; Owner: -; Tablespace: 
5171 5187
--
5172 5188

  
......
6565 6581

  
6566 6582

  
6567 6583
--
6568
-- Name: planttag_plant_id; Type: FK CONSTRAINT; Schema: public; Owner: -
6584
-- Name: planttag_plantobservation_id; Type: FK CONSTRAINT; Schema: public; Owner: -
6569 6585
--
6570 6586

  
6571 6587
ALTER TABLE ONLY planttag
6572
    ADD CONSTRAINT planttag_plant_id FOREIGN KEY (plant_id) REFERENCES plant(plant_id) ON UPDATE CASCADE ON DELETE CASCADE;
6588
    ADD CONSTRAINT planttag_plantobservation_id FOREIGN KEY (plantobservation_id) REFERENCES plantobservation(plantobservation_id) ON UPDATE CASCADE ON DELETE CASCADE;
6573 6589

  
6574 6590

  
6575 6591
--

Also available in: Unified diff