DROP TABLE IF EXISTS :schema.links CASCADE;

CREATE UNLOGGED TABLE :schema.links AS
SELECT
  h.id,
  h.hwtype AS highway,
  h.surface,
  h.oneway,
  h.maxspeed,
  COALESCE(NULLIF(h.name, ''), NULLIF(h.hwtype, ''), 'Unnamed road') AS name,
  h.geom AS geom
FROM :schema.ardok_highways h;

CREATE INDEX IF NOT EXISTS links_geom_idx ON :schema.links USING GIST (geom);
ALTER TABLE :schema.links ADD PRIMARY KEY (id);
