-- Rollback: POS Session Merge Support
-- Date: 2025-11-16

DROP VIEW IF EXISTS pos_sessions_enhanced;

DROP TABLE IF EXISTS pos_session_merge_log;

ALTER TABLE pos_sessions 
    DROP CONSTRAINT IF EXISTS fk_pos_sessions_merged_by,
    DROP CONSTRAINT IF EXISTS fk_pos_sessions_merged_into;

ALTER TABLE pos_sessions 
    DROP COLUMN IF EXISTS merge_group_id,
    DROP COLUMN IF EXISTS merged_into_session_id,
    DROP COLUMN IF EXISTS merged_by,
    DROP COLUMN IF EXISTS merged_at,
    DROP COLUMN IF EXISTS merge_notes;

DROP INDEX IF EXISTS idx_pos_sessions_merge_group;
DROP INDEX IF EXISTS idx_pos_sessions_merged_into;
DROP INDEX IF EXISTS idx_pos_session_merge_target;
DROP INDEX IF EXISTS idx_pos_session_merge_group;

-- NOTE: You may need to recreate the previous version of pos_sessions_enhanced
-- by re-running the enhancement migration (20251115) if still required.

DO $$
BEGIN
    RAISE NOTICE 'Rollback of 20251116_pos_session_merge_support completed.';
END $$;
