[
  {
    "type": "update",
    "description": "Data migration: Ensure all existing bsBin_Cat entries are marked as 'custom' type (they predate POS integration). New column has DEFAULT 'custom' but we ensure consistency.",
    "database": "{{store}}",
    "check_query": "SELECT 1 FROM bsBin_Cat WHERE categoryType IS NULL OR categoryType = '' LIMIT 1",
    "sql": "UPDATE bsBin_Cat SET categoryType = 'custom' WHERE categoryType IS NULL OR categoryType = ''"
  },
  {
    "type": "insert",
    "description": "Data migration: Copy ALL existing mainCategory values from bsBins to bsBin_Cat as custom tags. Since POS integration doesn't exist yet, all existing mainCategory values are custom categories. Skip if tag already exists for the bin.",
    "database": "{{store}}",
    "check_query": "SELECT 1 FROM bsBins b WHERE b.mainCategory IS NOT NULL AND b.mainCategory > 0 AND NOT EXISTS (SELECT 1 FROM bsBin_Cat bc WHERE bc.binID = b.id AND bc.catID = b.mainCategory) LIMIT 1",
    "sql": "INSERT INTO bsBin_Cat (binID, catID, categoryType) SELECT b.id, b.mainCategory, 'custom' FROM bsBins b WHERE b.mainCategory IS NOT NULL AND b.mainCategory > 0 AND NOT EXISTS (SELECT 1 FROM bsBin_Cat bc WHERE bc.binID = b.id AND bc.catID = b.mainCategory)"
  },
  {
    "type": "update",
    "description": "Data migration: Clear ALL mainCategory values from bsBins (they've been migrated to bsBin_Cat as custom tags). This prepares the column for POS-only usage going forward.",
    "database": "{{store}}",
    "check_query": "SELECT 1 FROM bsBins WHERE mainCategory IS NOT NULL AND mainCategory > 0 LIMIT 1",
    "sql": "UPDATE bsBins SET mainCategory = NULL WHERE mainCategory IS NOT NULL AND mainCategory > 0"
  }
]
