1
|
-- Ensure globally unique column names when tables are joined
|
2
|
ALTER TABLE "lookup_MethodCode" RENAME "Description" TO "lookup_MethodCode_Description";
|
3
|
|
4
|
-- Enable cascading deletes
|
5
|
|
6
|
CREATE INDEX ON "plotMetadata" (project_id);
|
7
|
ALTER TABLE "plotMetadata" ADD FOREIGN KEY (project_id) REFERENCES projects(project_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
8
|
|
9
|
CREATE INDEX ON "plotObservations" ("PlotID");
|
10
|
ALTER TABLE "plotObservations" ADD FOREIGN KEY ("PlotID") REFERENCES "plotMetadata"("PlotID") ON UPDATE CASCADE ON DELETE CASCADE;
|
11
|
|
12
|
CREATE INDEX ON stems ("PlotObsID");
|
13
|
ALTER TABLE stems ADD FOREIGN KEY ("PlotObsID") REFERENCES "plotObservations"("PlotObsID") ON UPDATE CASCADE ON DELETE CASCADE;
|
14
|
|
15
|
-- Remove private data that should not be publicly visible
|
16
|
DELETE FROM "plotMetadata" WHERE "AccessCode" = 1;
|