BEGIN;

ALTER TABLE mock.shop_amazon_events
	ADD COLUMN processed BOOLEAN DEFAULT FALSE,
	ADD COLUMN processed_successfully BOOLEAN DEFAULT FALSE;

UPDATE mock.shop_amazon_events
	SET processed = (processed_at IS NOT NULL),
		processed_successfully = (processed_at IS NOT NULL);

DROP INDEX IF EXISTS mock.shop_amazon_events_by_timestamp_unprocessed;
CREATE INDEX shop_amazon_events_by_timestamp_unprocessed ON mock.shop_amazon_events (shop_id, event_timestamp) WHERE NOT processed;

ALTER TABLE mock.shop_amazon_events
	DROP COLUMN notified_at,
	DROP COLUMN processed_at;

COMMIT;
