Skip to content

Commit c518a38

Browse files
committed
Add option to create and index unique id columns on all tables
They are useful for instance if you want to be able to edit the data in QGIS.
1 parent 82b54cb commit c518a38

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

config/shortbread_gen.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ themepark.debug = false
1313
-- Add JSONB column `tags` with original OSM tags in debug mode
1414
themepark:set_option('tags', 'all_tags')
1515

16+
-- Set this to add a column 'id' with unique IDs (and corresponding unique
17+
-- index). This is needed for instance when you want to edit the data in QGIS.
18+
--themepark:set_option('unique_id', 'id')
19+
1620
-- ---------------------------------------------------------------------------
1721

1822
-- themepark:add_topic('core/name-single', { column = 'name' })

lua/themepark.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ function themepark:add_table(data)
282282
})
283283
end
284284

285+
if themepark.options.unique_id then
286+
table.insert(data.columns, {
287+
column = themepark.options.unique_id,
288+
sql_type = 'bigserial',
289+
create_only = true
290+
})
291+
table.insert(data.indexes, {
292+
column = themepark.options.unique_id,
293+
unique = true,
294+
method = 'btree'
295+
})
296+
end
297+
285298
if data.geom then
286299
if type(data.geom) == 'string' then
287300
data.geom_type = data.geom

0 commit comments

Comments
 (0)