[
  {
    "type": "create_table",
    "description": "Create qb_mapping_learning: anonymized aggregate of which generic account names stores commonly map each POS field to. Used to suggest sensible defaults during auto-map.",
    "database": "kiosk_buykiosk",
    "check_query": "SELECT 1 FROM information_schema.tables WHERE table_schema = 'kiosk_buykiosk' AND table_name = 'qb_mapping_learning'",
    "sql": "CREATE TABLE IF NOT EXISTS `qb_mapping_learning` (`fieldName` VARCHAR(80) NOT NULL, `qbAccountType` VARCHAR(80) NOT NULL, `qbAccountNameNormalized` VARCHAR(160) NOT NULL, `qbAccountNameDisplay` VARCHAR(160) NOT NULL, `storeCount` INT UNSIGNED NOT NULL DEFAULT 1, `lastUpdated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`fieldName`, `qbAccountType`, `qbAccountNameNormalized`), KEY `idx_field_count` (`fieldName`, `storeCount`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
  },
  {
    "type": "create_table",
    "description": "Create qb_mapping_learning_contributions: one row per store per field, enforces one-vote-per-store and lets us decrement the old aggregate row when a store changes its mapping.",
    "database": "kiosk_buykiosk",
    "check_query": "SELECT 1 FROM information_schema.tables WHERE table_schema = 'kiosk_buykiosk' AND table_name = 'qb_mapping_learning_contributions'",
    "sql": "CREATE TABLE IF NOT EXISTS `qb_mapping_learning_contributions` (`typeNum` VARCHAR(8) NOT NULL, `fieldName` VARCHAR(80) NOT NULL, `qbAccountType` VARCHAR(80) NOT NULL, `qbAccountNameNormalized` VARCHAR(160) NOT NULL, `contributedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`typeNum`, `fieldName`), KEY `idx_aggregate_lookup` (`fieldName`, `qbAccountType`, `qbAccountNameNormalized`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
  }
]
