Project

General

Profile

1
#!/bin/bash
2
# :mode=transact-sql:
3
cd "$(dirname "$0")"
4
. ../../../lib/import.sh
5

    
6
psql <<'EOF'
7
SELECT functions.to_global_col_names('"TREE"');
8

    
9
SELECT functions.rename_if_exists($$ALTER TABLE "TREE" RENAME "TREE.STATECD"  TO ".STATECD" $$);
10
SELECT functions.rename_if_exists($$ALTER TABLE "TREE" RENAME "TREE.UNITCD"   TO ".UNITCD"  $$);
11
SELECT functions.rename_if_exists($$ALTER TABLE "TREE" RENAME "TREE.COUNTYCD" TO ".COUNTYCD"$$);
12
SELECT functions.rename_if_exists($$ALTER TABLE "TREE" RENAME "TREE.PLOT"     TO ".PLOT"    $$);
13
SELECT functions.rename_if_exists($$ALTER TABLE "TREE" RENAME "TREE.INVYR"    TO ".INVYR"   $$);
14
SELECT functions.rename_if_exists($$ALTER TABLE "TREE" RENAME "TREE.CONDID"   TO ".CONDID"  $$);
15
SELECT functions.rename_if_exists($$ALTER TABLE "TREE" RENAME "TREE.SUBP"     TO ".SUBP"    $$);
16
SELECT functions.rename_if_exists($$ALTER TABLE "TREE" RENAME "TREE.SPCD"     TO ".SPCD"    $$);
17

    
18
SELECT functions.set_col_types('"TREE"', ARRAY[
19
  ('.STATECD' , 'integer')
20
, ('.UNITCD'  , 'integer')
21
, ('.COUNTYCD', 'integer')
22
, ('.PLOT'    , 'integer')
23
, ('.INVYR'   , 'integer')
24
, ('.SUBP'    , 'integer')
25
, ('.CONDID'  , 'integer')
26
, ('.SPCD'    , 'integer')
27
]::functions.col_cast[]);
28

    
29
-- ("STATECD", "UNITCD", "COUNTYCD", "PLOT", "INVYR", "CONDID", "SUBP", "TREE", "STATUSCD") is not ID
30
SELECT functions.create_if_not_exists($$ALTER TABLE "TREE" ADD CONSTRAINT "TREE.ID" UNIQUE ("TREE.CN")$$);
31
SELECT functions.cluster_once('"TREE"', '"TREE.ID"');
32

    
33
SELECT functions.create_if_not_exists($$CREATE INDEX "TREE.parent" ON "TREE" (".STATECD", ".UNITCD", ".COUNTYCD", ".PLOT", ".INVYR", ".CONDID", ".SUBP")$$);
    (1-1/1)