Project

General

Profile

1 8163 aaronmk
#!/bin/bash
2
# :mode=transact-sql:
3
cd "$(dirname "$0")"
4
. ../../../lib/import.sh
5
6 8164 aaronmk
map_table
7 8163 aaronmk
psql <<'EOF'
8 8184 aaronmk
SELECT set_col_types('"COND"', ARRAY[
9 8172 aaronmk
  ('STATECD', 'integer')
10
, ('UNITCD', 'integer')
11 8170 aaronmk
, ('COUNTYCD', 'integer')
12 8172 aaronmk
, ('locationName', 'integer')
13
, ('INVYR', 'integer')
14
, ('authorEventCode', 'integer')
15 8184 aaronmk
]::col_cast[]);
16 8110 aaronmk
17 8184 aaronmk
SELECT create_if_not_exists($$
18 8174 aaronmk
ALTER TABLE "COND" ADD   COLUMN "oldGrowth"      boolean;
19
ALTER TABLE "COND" ALTER COLUMN "oldGrowth" TYPE boolean USING
20 8100 aaronmk
(
21 8186 aaronmk
    "COND
22
STDAGE"::integer>80
23
    AND ("COND
24
TRTCD1"='0' OR "COND
25
TRTCD1" IS NULL)
26
    AND (("COND
27
DSTRBCD1"<>'30' AND "COND
28
DSTRBCD1"<>'31' AND "COND
29
DSTRBCD1"<>'32' AND "COND
30
DSTRBCD1"<>'80') OR "COND
31
DSTRBCD1" IS NULL)
32
    AND ("COND
33
STUMP_CD_PNWRS"='N' OR "COND
34
STUMP_CD_PNWRS" IS NULL)
35
    AND "COND
36
HARVEST_TYPE1_SRS" IS NULL
37
    AND "COND
38
PRESNFCD" IS NULL
39
    AND ("COND
40
STDORGCD"='0' OR "COND
41
STDORGCD" IS NULL)
42 8100 aaronmk
)
43 8186 aaronmk
OR "COND
44
STND_COND_CD_PNWRS"='7'
45 8100 aaronmk
;
46
$$);
47
48 8184 aaronmk
SELECT create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.ID"     UNIQUE ("COND
49 8177 aaronmk
CN")$$);
50 8184 aaronmk
SELECT create_if_not_exists($$ALTER TABLE "COND" ADD CONSTRAINT "COND.unique" UNIQUE ("STATECD", "UNITCD", "COUNTYCD", "locationName", "INVYR", "authorEventCode")$$);
51
SELECT cluster_once('"COND"', '"COND.unique"');