comparison pkg/imports/st.go @ 4389:5e38667f740c stretches-for-responsibility

Use stretches as areas of responsibility. This is heavily based on a patch by Tom Gottfried (read: >90% of the work was done by Tom).
author Sascha Wilde <wilde@intevation.de>
date Thu, 12 Sep 2019 18:13:47 +0200
parents f9bb06f2dbe3
children aeb2aedd3abd
comparison
equal deleted inserted replaced
4371:4a5ed371011f 4389:5e38667f740c
55 } 55 }
56 } 56 }
57 57
58 const ( 58 const (
59 stDeleteSQL = ` 59 stDeleteSQL = `
60 DELETE FROM waterway.stretches WHERE 60 DELETE FROM users.stretches WHERE
61 staging_done AND name = ( 61 staging_done AND name = (
62 SELECT name 62 SELECT name
63 FROM waterway.stretches WHERE 63 FROM users.stretches WHERE
64 id = ( 64 id = (
65 SELECT key from import.track_imports 65 SELECT key from import.track_imports
66 WHERE import_id = $1 AND 66 WHERE import_id = $1 AND
67 relation = 'waterway.stretches'::regclass) 67 relation = 'users.stretches'::regclass)
68 AND NOT staging_done 68 AND NOT staging_done
69 )` 69 )`
70 70
71 stStageDoneSQL = ` 71 stStageDoneSQL = `
72 UPDATE waterway.stretches SET staging_done = true 72 UPDATE users.stretches SET staging_done = true
73 WHERE id IN ( 73 WHERE id IN (
74 SELECT key from import.track_imports 74 SELECT key from import.track_imports
75 WHERE import_id = $1 AND 75 WHERE import_id = $1 AND
76 relation = 'waterway.stretches'::regclass)` 76 relation = 'users.stretches'::regclass)`
77 77
78 stInsertSQL = ` 78 stInsertSQL = `
79 WITH 79 WITH
80 bounds (b) AS (VALUES ( 80 bounds (b) AS (VALUES (
81 ($1::char(2), 81 ($1::char(2),
92 r AS (SELECT isrsrange( 92 r AS (SELECT isrsrange(
93 (SELECT b FROM bounds ORDER BY b USING <~ FETCH FIRST ROW ONLY), 93 (SELECT b FROM bounds ORDER BY b USING <~ FETCH FIRST ROW ONLY),
94 (SELECT b FROM bounds ORDER BY b USING >~ FETCH FIRST ROW ONLY)) AS r), 94 (SELECT b FROM bounds ORDER BY b USING >~ FETCH FIRST ROW ONLY)) AS r),
95 axs AS ( 95 axs AS (
96 SELECT ISRSrange_axis((SELECT r FROM r), $16::double precision) AS axs) 96 SELECT ISRSrange_axis((SELECT r FROM r), $16::double precision) AS axs)
97 INSERT INTO waterway.stretches ( 97 INSERT INTO users.stretches (
98 name, 98 name,
99 stretch, 99 stretch,
100 area, 100 area,
101 objnam, 101 objnam,
102 nobjnam, 102 nobjnam,
114 $14, 114 $14,
115 $15) 115 $15)
116 RETURNING id` 116 RETURNING id`
117 117
118 stInsertCountrySQL = ` 118 stInsertCountrySQL = `
119 INSERT INTO waterway.stretch_countries ( 119 INSERT INTO users.stretch_countries (
120 stretches_id, 120 stretch_id,
121 country_code 121 country
122 ) VALUES ( 122 ) VALUES (
123 $1, 123 $1,
124 $2 124 $2
125 )` 125 )`
126 ) 126 )
212 if _, err := insertCountryStmt.ExecContext(ctx, id, c); err != nil { 212 if _, err := insertCountryStmt.ExecContext(ctx, id, c); err != nil {
213 return nil, err 213 return nil, err
214 } 214 }
215 } 215 }
216 216
217 if err := track(ctx, tx, importID, "waterway.stretches", id); err != nil { 217 if err := track(ctx, tx, importID, "users.stretches", id); err != nil {
218 return nil, err 218 return nil, err
219 } 219 }
220 220
221 feedback.Info("Storing stretch '%s' took %s", st.Name, time.Since(start)) 221 feedback.Info("Storing stretch '%s' took %s", st.Name, time.Since(start))
222 if err := tx.Commit(); err != nil { 222 if err := tx.Commit(); err != nil {