|
1 | 1 | CREATE EXTENSION postgis; |
2 | 2 |
|
3 | 3 | -- bandaid |
4 | | -insert into spatial_ref_sys select 9311, 'EPSG', 9311, srtext, proj4text from spatial_ref_sys where srid = 2163; |
| 4 | +INSERT INTO spatial_ref_sys |
| 5 | +SELECT |
| 6 | + 9311 AS srid, |
| 7 | + 'EPSG' AS auth_name, |
| 8 | + 9311 AS auth_srid, |
| 9 | + srtext, |
| 10 | + proj4text |
| 11 | +FROM spatial_ref_sys |
| 12 | +WHERE srid = 2163; |
5 | 13 |
|
6 | 14 | -- Boilerplate IEM schema_manager_version, the version gets incremented each |
7 | 15 | -- time we make an upgrade script |
8 | | -CREATE TABLE iem_schema_manager_version( |
9 | | - version int, |
10 | | - updated timestamptz); |
11 | | -INSERT into iem_schema_manager_version values (1, now()); |
| 16 | +CREATE TABLE iem_schema_manager_version ( |
| 17 | + version int, |
| 18 | + updated timestamptz |
| 19 | +); |
| 20 | +INSERT INTO iem_schema_manager_version VALUES (1, now()); |
12 | 21 |
|
13 | 22 |
|
14 | 23 | --- |
15 | 24 | --- Quasi synced from mesosite database |
16 | 25 | --- |
17 | | -CREATE TABLE stations( |
18 | | - id varchar(64), |
19 | | - synop int, |
20 | | - name varchar(64), |
21 | | - state char(2), |
22 | | - country char(2), |
23 | | - elevation real, |
24 | | - network varchar(20), |
25 | | - online boolean, |
26 | | - params varchar(300), |
27 | | - county varchar(50), |
28 | | - plot_name varchar(64), |
29 | | - climate_site varchar(6), |
30 | | - remote_id int, |
31 | | - nwn_id int, |
32 | | - spri smallint, |
33 | | - wfo varchar(3), |
34 | | - archive_begin date, |
35 | | - archive_end date, |
36 | | - modified timestamp with time zone, |
37 | | - tzname varchar(32), |
38 | | - iemid SERIAL, |
39 | | - metasite boolean, |
40 | | - sigstage_low real, |
41 | | - sigstage_action real, |
42 | | - sigstage_bankfull real, |
43 | | - sigstage_flood real, |
44 | | - sigstage_moderate real, |
45 | | - sigstage_major real, |
46 | | - sigstage_record real, |
47 | | - ugc_county char(6), |
48 | | - ugc_zone char(6), |
49 | | - ncdc81 varchar(11), |
| 26 | +CREATE TABLE stations ( |
| 27 | + id varchar(64), |
| 28 | + synop int, |
| 29 | + name varchar(64), |
| 30 | + state char(2), |
| 31 | + country char(2), |
| 32 | + elevation real, |
| 33 | + network varchar(20), |
| 34 | + online boolean, |
| 35 | + params varchar(300), |
| 36 | + county varchar(50), |
| 37 | + plot_name varchar(64), |
| 38 | + climate_site varchar(6), |
| 39 | + remote_id int, |
| 40 | + nwn_id int, |
| 41 | + spri smallint, |
| 42 | + wfo varchar(3), |
| 43 | + archive_begin date, |
| 44 | + archive_end date, |
| 45 | + modified timestamp with time zone, |
| 46 | + tzname varchar(32), |
| 47 | + iemid serial, |
| 48 | + metasite boolean, |
| 49 | + sigstage_low real, |
| 50 | + sigstage_action real, |
| 51 | + sigstage_bankfull real, |
| 52 | + sigstage_flood real, |
| 53 | + sigstage_moderate real, |
| 54 | + sigstage_major real, |
| 55 | + sigstage_record real, |
| 56 | + ugc_county char(6), |
| 57 | + ugc_zone char(6), |
| 58 | + ncdc81 varchar(11), |
50 | 59 | ncei91 varchar(11), |
51 | | - temp24_hour smallint, |
52 | | - precip24_hour smallint, |
53 | | - wigos varchar(64) |
| 60 | + temp24_hour smallint, |
| 61 | + precip24_hour smallint, |
| 62 | + wigos varchar(64) |
54 | 63 | ); |
55 | | -ALTER TABLE stations OWNER to mesonet; |
56 | | -CREATE UNIQUE index stations_idx on stations(id, network); |
57 | | -create UNIQUE index stations_iemid_idx on stations(iemid); |
58 | | -SELECT AddGeometryColumn('stations', 'geom', 4326, 'POINT', 2); |
59 | | -GRANT SELECT on stations to nobody; |
60 | | -grant all on stations_iemid_seq to nobody; |
61 | | -GRANT ALL on stations to mesonet,ldm; |
62 | | -GRANT ALL on stations_iemid_seq to mesonet,ldm; |
| 64 | +ALTER TABLE stations OWNER TO mesonet; |
| 65 | +CREATE UNIQUE INDEX stations_idx ON stations (id, network); |
| 66 | +CREATE UNIQUE INDEX stations_iemid_idx ON stations (iemid); |
| 67 | +SELECT addgeometrycolumn('stations', 'geom', 4326, 'POINT', 2); |
| 68 | +GRANT SELECT ON stations TO nobody; |
| 69 | +GRANT ALL ON stations_iemid_seq TO nobody; |
| 70 | +GRANT ALL ON stations TO mesonet, ldm; |
| 71 | +GRANT ALL ON stations_iemid_seq TO mesonet, ldm; |
63 | 72 |
|
64 | 73 | --- |
65 | 74 | --- One Minute ASOS data |
66 | 75 | --- |
67 | | -CREATE TABLE alldata_1minute( |
68 | | - station varchar(4), |
69 | | - valid timestamptz, |
70 | | - vis1_coeff real, |
71 | | - vis1_nd char(1), |
72 | | - vis2_coeff real, |
73 | | - vis2_nd char(1), |
74 | | - vis3_coeff real, |
75 | | - vis3_nd char(1), |
76 | | - drct smallint, |
77 | | - sknt smallint, |
78 | | - gust_drct smallint, |
79 | | - gust_sknt smallint, |
80 | | - ptype char(2), |
81 | | - precip real, |
82 | | - pres1 real, |
83 | | - pres2 real, |
84 | | - pres3 real, |
85 | | - tmpf smallint, |
86 | | - dwpf smallint |
87 | | -) PARTITION by range(valid); |
88 | | -ALTER TABLE alldata_1minute OWNER to mesonet; |
89 | | -GRANT ALL on alldata_1minute to ldm; |
90 | | -GRANT SELECT on alldata_1minute to nobody; |
| 76 | +CREATE TABLE alldata_1minute ( |
| 77 | + station varchar(4), |
| 78 | + valid timestamptz, |
| 79 | + vis1_coeff real, |
| 80 | + vis1_nd char(1), |
| 81 | + vis2_coeff real, |
| 82 | + vis2_nd char(1), |
| 83 | + vis3_coeff real, |
| 84 | + vis3_nd char(1), |
| 85 | + drct smallint, |
| 86 | + sknt smallint, |
| 87 | + gust_drct smallint, |
| 88 | + gust_sknt smallint, |
| 89 | + ptype char(2), |
| 90 | + precip real, |
| 91 | + pres1 real, |
| 92 | + pres2 real, |
| 93 | + pres3 real, |
| 94 | + tmpf smallint, |
| 95 | + dwpf smallint |
| 96 | +) PARTITION BY RANGE (valid); |
| 97 | +ALTER TABLE alldata_1minute OWNER TO mesonet; |
| 98 | +GRANT ALL ON alldata_1minute TO ldm; |
| 99 | +GRANT SELECT ON alldata_1minute TO nobody; |
91 | 100 |
|
92 | | -do |
| 101 | +DO |
93 | 102 | $do$ |
94 | 103 | declare |
95 | 104 | year int; |
|
0 commit comments