Create catalog__uom table CREATE TABLE catalog__uom ( id uuid PRIMARY KEY, code varchar(16) NOT NULL, name varchar(128) NOT NULL, dimension varchar(32) NOT NULL, ext jsonb NOT NULL DEFAULT '{}'::jsonb, created_at timestamptz NOT NULL, created_by varchar(128) NOT NULL, updated_at timestamptz NOT NULL, updated_by varchar(128) NOT NULL, version bigint NOT NULL DEFAULT 0 ); CREATE UNIQUE INDEX catalog__uom_code_uk ON catalog__uom (code); CREATE INDEX catalog__uom_ext_gin ON catalog__uom USING GIN (ext jsonb_path_ops); DROP TABLE catalog__uom; Create catalog__item table (FK to catalog__uom by code) CREATE TABLE catalog__item ( id uuid PRIMARY KEY, code varchar(64) NOT NULL, name varchar(256) NOT NULL, description text, item_type varchar(32) NOT NULL, base_uom_code varchar(16) NOT NULL REFERENCES catalog__uom(code), active boolean NOT NULL DEFAULT true, ext jsonb NOT NULL DEFAULT '{}'::jsonb, created_at timestamptz NOT NULL, created_by varchar(128) NOT NULL, updated_at timestamptz NOT NULL, updated_by varchar(128) NOT NULL, version bigint NOT NULL DEFAULT 0 ); CREATE UNIQUE INDEX catalog__item_code_uk ON catalog__item (code); CREATE INDEX catalog__item_ext_gin ON catalog__item USING GIN (ext jsonb_path_ops); CREATE INDEX catalog__item_active_idx ON catalog__item (active); DROP TABLE catalog__item; Seed canonical UoMs INSERT INTO catalog__uom (id, code, name, dimension, created_at, created_by, updated_at, updated_by) VALUES (gen_random_uuid(), 'kg', 'Kilogram', 'mass', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'g', 'Gram', 'mass', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 't', 'Tonne', 'mass', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'm', 'Metre', 'length', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'cm', 'Centimetre','length', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'mm', 'Millimetre','length', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'km', 'Kilometre', 'length', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'm2', 'Square metre','area', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'l', 'Litre', 'volume', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'ml', 'Millilitre','volume', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'ea', 'Each', 'count', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'sheet', 'Sheet', 'count', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'pack', 'Pack', 'count', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'h', 'Hour', 'time', now(), '__seed__', now(), '__seed__'), (gen_random_uuid(), 'min', 'Minute', 'time', now(), '__seed__', now(), '__seed__'); DELETE FROM catalog__uom WHERE created_by = '__seed__';