-- ============================================================
-- DOWN Migration: Rollback 68_add_route_permission_codes.sql
-- Reverses the 23 permission code inserts and restores the
-- audit.view row to its pre-migration-68 state (empty name/
-- group_name, NULL sort_order), as documented in the comment
-- of 66_add_audit_permissions.sql.
--
-- Data only. No schema change. Expected effect: 23 rows deleted,
-- 1 row updated.
-- ============================================================

-- Remove the 23 permission codes inserted by migration 68
DELETE FROM `permissions` WHERE `code` IN (
    'sale_returns.view',
    'sale_returns.create',
    'financial.view',
    'purchases.view',
    'purchases.create',
    'suppliers.view',
    'suppliers.edit',
    'stock_audit.manage',
    'partners.view',
    'partners.edit',
    'transactions.receive',
    'transactions.pay',
    'used_batteries.manage',
    'warranties.view',
    'warranties.manage',
    'catalog.view',
    'catalog.manage',
    'checks.view',
    'checks.manage',
    'partner_ampere.view',
    'partner_ampere.manage',
    'brand_rates.view',
    'brand_rates.manage'
);

-- Restore audit.view to its pre-migration-68 state.
-- Migration 66 left this row without a name or group; migration 68
-- repaired it. Rolling back 68 means returning to that empty state.
UPDATE `permissions`
SET `name` = '',
    `group_name` = '',
    `sort_order` = NULL
WHERE `code` = 'audit.view';
