-- Activation codes + worker UI hot-update path (run once on existing DB).
-- mysql -uroot -proot -P8889 -h127.0.0.1 aiworker < schema_migrate_activation.sql

USE aiworker;

CREATE TABLE IF NOT EXISTS activation_codes (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  activation_code VARCHAR(64) NOT NULL,
  status ENUM('unused','active','disabled') NOT NULL DEFAULT 'unused',
  bound_fingerprint VARCHAR(128) DEFAULT NULL,
  bound_worker_id VARCHAR(32) DEFAULT NULL,
  note VARCHAR(255) DEFAULT NULL,
  created_at DATETIME NOT NULL,
  updated_at DATETIME NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY uk_activation_code (activation_code),
  KEY idx_bound_worker_id (bound_worker_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO activation_codes (activation_code, status, note, created_at, updated_at)
SELECT 'AIGY-BEE-DEMO-2026', 'unused', 'Demo / dev', NOW(), NOW()
FROM DUAL
WHERE NOT EXISTS (
  SELECT 1 FROM activation_codes WHERE activation_code = 'AIGY-BEE-DEMO-2026'
);
