Skip to content

Commit a789b0e

Browse files
committed
Use GENERATED AS IDENTITY instead of serial column type
And make re-creating the tables work that use this.
1 parent ed5e789 commit a789b0e

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

lua/themepark.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ function themepark:add_table(data)
285285
if themepark.options.unique_id then
286286
table.insert(data.columns, {
287287
column = themepark.options.unique_id,
288-
sql_type = 'bigserial',
288+
sql_type = 'bigint GENERATED BY DEFAULT AS IDENTITY',
289289
create_only = true
290290
})
291291
table.insert(data.indexes, {

themes/shortbread_v1_gen/topics/boundaries.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ end)
193193
local function gen_commands(sql, level)
194194
local c = gen_config[level]
195195

196-
table.insert(sql, 'CREATE TABLE {schema}.boundaries_' .. level .. '_new (LIKE {schema}.boundaries_' .. level .. ')')
196+
table.insert(sql, 'CREATE TABLE {schema}.boundaries_' .. level .. '_new (LIKE {schema}.boundaries_' .. level .. ' INCLUDING IDENTITY)')
197197

198198
table.insert(sql, [[
199199
WITH simplified AS (
200200
SELECT way_ids, relation_ids, admin_level, maritime, disputed, ST_SimplifyVW(geom, ]] .. c.simplify .. [[) AS geom
201201
FROM {schema}.boundaries ]] .. c.condition .. [[
202202
)
203-
INSERT INTO {schema}.boundaries_]] .. level .. [[_new
204-
SELECT * FROM simplified WHERE ST_Length(geom) > ]] .. c.minlength)
203+
INSERT INTO {schema}.boundaries_]] .. level .. [[_new (way_ids, relation_ids, admin_level, maritime, disputed, geom)
204+
SELECT way_ids, relation_ids, admin_level, maritime, disputed, geom FROM simplified WHERE ST_Length(geom) > ]] .. c.minlength)
205205

206206
table.insert(sql, 'ANALYZE {schema}.boundaries_' .. level .. '_new')
207207
table.insert(sql, 'CREATE INDEX ON {schema}.boundaries_' .. level .. '_new USING GIST (geom)')
@@ -211,7 +211,7 @@ end
211211

212212
themepark:add_proc('gen', function(data)
213213
local sql = {
214-
'CREATE TABLE {schema}.boundaries_new (LIKE {schema}.boundaries)',
214+
'CREATE TABLE {schema}.boundaries_new (LIKE {schema}.boundaries INCLUDING IDENTITY)',
215215
[[
216216
WITH multigeom AS (
217217
SELECT array_agg(way_id ORDER BY way_id) AS way_ids,
@@ -224,7 +224,7 @@ SELECT array_agg(way_id ORDER BY way_id) AS way_ids,
224224
WHERE closure_segment IS FALSE
225225
GROUP BY relation_ids, maritime OR coastline, disputed
226226
)
227-
INSERT INTO {schema}.boundaries_new
227+
INSERT INTO {schema}.boundaries_new (way_ids, relation_ids, admin_level, maritime, disputed, geom)
228228
SELECT way_ids, relation_ids, admin_level, maritime, disputed, (ST_Dump(geom)).geom AS geom
229229
FROM multigeom ]],
230230
'ANALYZE {schema}.boundaries_new',

themes/shortbread_v1_gen/topics/streets.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ themepark:add_proc('gen', function(data)
424424
description = 'Merge street lines for medium zoom levels',
425425
transaction = true,
426426
sql = {
427-
themepark.expand_template('CREATE TABLE {schema}.streets_med_new (LIKE {schema}.streets_med)'),
427+
themepark.expand_template('CREATE TABLE {schema}.streets_med_new (LIKE {schema}.streets_med INCLUDING IDENTITY)'),
428428
themepark.expand_template([[
429429
CREATE OR REPLACE FUNCTION osm2pgsql_shortbread_streets_med() RETURNS void AS $$
430430
DECLARE
@@ -469,7 +469,7 @@ $$ LANGUAGE plpgsql]]),
469469
description = 'Merge street lines for low zoom levels',
470470
transaction = true,
471471
sql = {
472-
themepark.expand_template('CREATE TABLE {schema}.streets_low_new (LIKE {schema}.streets_low)'),
472+
themepark.expand_template('CREATE TABLE {schema}.streets_low_new (LIKE {schema}.streets_low INCLUDING IDENTITY)'),
473473
themepark.expand_template([[
474474
WITH
475475
merged AS

themes/shortbread_v1_gen/topics/water.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ themepark:add_proc('gen', function(data)
268268
if_has_rows = themepark.expand_template('SELECT 1 FROM {schema}.expire_water_lines LIMIT 1'),
269269
transaction = true,
270270
sql = {
271-
themepark.expand_template('CREATE TABLE {schema}.water_lines_gen_new (LIKE {schema}.water_lines_gen)'),
271+
themepark.expand_template('CREATE TABLE {schema}.water_lines_gen_new (LIKE {schema}.water_lines_gen INCLUDING IDENTITY)'),
272272
themepark.expand_template([[
273273
WITH merged AS
274274
(SELECT ]] .. name_list .. [[, kind, tunnel, bridge, ST_LineMerge(ST_Collect(geom)) AS geom

0 commit comments

Comments
 (0)