-- backend/database.sql

CREATE TABLE IF NOT EXISTS `licenses` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `license_key` varchar(255) NOT NULL,
  `device_id` varchar(255) DEFAULT NULL,
  `max_workspaces` int(11) NOT NULL DEFAULT '1', -- -1 means unlimited
  `duration_days` int(11) DEFAULT NULL, -- NULL means lifetime (if expires_at is also NULL)
  `expires_at` datetime DEFAULT NULL,
  `status` enum('active','revoked') NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_license_key` (`license_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
