Create production__work_order_operation (routing step child table) CREATE TABLE production__work_order_operation ( id uuid PRIMARY KEY, work_order_id uuid NOT NULL REFERENCES production__work_order(id) ON DELETE CASCADE, line_no integer NOT NULL, operation_code varchar(64) NOT NULL, work_center varchar(64) NOT NULL, standard_minutes numeric(10,2) NOT NULL, status varchar(16) NOT NULL, actual_minutes numeric(10,2), started_at timestamptz, completed_at timestamptz, 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_operation_status_check CHECK (status IN ('PENDING', 'IN_PROGRESS', 'COMPLETED')), CONSTRAINT production__work_order_operation_line_no_pos CHECK (line_no > 0), CONSTRAINT production__work_order_operation_std_min_pos CHECK (standard_minutes >= 0), CONSTRAINT production__work_order_operation_act_min_pos CHECK (actual_minutes IS NULL OR actual_minutes >= 0), CONSTRAINT production__work_order_operation_line_uk UNIQUE (work_order_id, line_no) ); CREATE INDEX production__work_order_operation_wo_idx ON production__work_order_operation (work_order_id); CREATE INDEX production__work_order_operation_status_idx ON production__work_order_operation (status); CREATE INDEX production__work_order_operation_work_center_idx ON production__work_order_operation (work_center); DROP TABLE production__work_order_operation;