-- Apply this migration manually. Each statement in a separate transaction

ALTER TABLE diffalert.messages ADD COLUMN has_own_name boolean;
ALTER TABLE diffalert.messages ALTER COLUMN has_own_name SET DEFAULT FALSE;
UPDATE diffalert.messages SET has_own_name=FALSE WHERE has_own_name IS NULL;
ALTER TABLE diffalert.messages ALTER COLUMN has_own_name SET NOT NULL;

UPDATE diffalert.messages SET object_label='unknown' WHERE object_label IS NULL;
ALTER TABLE diffalert.messages ALTER COLUMN object_label SET NOT NULL;

CREATE INDEX messages_filtered_order_by_name_index
  ON diffalert.messages
  USING btree
  (task_id, attributes_id, pri_major, pri_minor, has_own_name, object_label, id);
