Create production__work_order table CREATE TABLE production__work_order ( id uuid PRIMARY KEY, code varchar(64) NOT NULL, output_item_code varchar(64) NOT NULL, output_quantity numeric(18,4) NOT NULL, status varchar(16) NOT NULL, due_date date, source_sales_order_code varchar(64), 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, CONSTRAINT production__work_order_status_check CHECK (status IN ('DRAFT', 'COMPLETED', 'CANCELLED')), CONSTRAINT production__work_order_qty_pos CHECK (output_quantity > 0) ); CREATE UNIQUE INDEX production__work_order_code_uk ON production__work_order (code); CREATE INDEX production__work_order_status_idx ON production__work_order (status); CREATE INDEX production__work_order_output_item_idx ON production__work_order (output_item_code); CREATE INDEX production__work_order_source_so_idx ON production__work_order (source_sales_order_code); CREATE INDEX production__work_order_due_date_idx ON production__work_order (due_date); CREATE INDEX production__work_order_ext_gin ON production__work_order USING GIN (ext jsonb_path_ops); DROP TABLE production__work_order;