SELECT util.search_path_append('util');

SELECT set_col_types('"TREE"', ARRAY[
  ('*STATECD', 'integer')
, ('*UNITCD', 'integer')
, ('*COUNTYCD', 'integer')
, ('locationName', 'integer')
, ('*INVYR', 'integer')
, ('subplot', 'integer')
, ('authorEventCode', 'integer')
, ('*SPCD', 'integer')
]::col_cast[]);

-- ("*STATECD", "*UNITCD", "*COUNTYCD", "locationName", "*INVYR", "authorEventCode", "subplot", "*TREE", "*STATUSCD") is not ID
SELECT create_if_not_exists($$ALTER TABLE "TREE" ADD CONSTRAINT "TREE.ID" UNIQUE ("individualObservationID")$$);

SELECT create_if_not_exists($$CREATE INDEX "TREE.parent" ON "TREE" ("*STATECD", "*UNITCD", "*COUNTYCD", "locationName", "*INVYR", "authorEventCode", "subplot")$$);
SELECT cluster_once('"TREE"', '"TREE.parent"');
