-- SQL for the License Manager Database
-- Create a new database called 'license_manager_db' and run this script.

CREATE TABLE IF NOT EXISTS licenses (
    id INT AUTO_INCREMENT PRIMARY KEY,
    license_key VARCHAR(255) UNIQUE NOT NULL,
    max_activations INT DEFAULT 1,
    status ENUM('active', 'suspended', 'expired') DEFAULT 'active',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS activations (
    id INT AUTO_INCREMENT PRIMARY KEY,
    license_id INT NOT NULL,
    fingerprint VARCHAR(255) NOT NULL,
    domain VARCHAR(255),
    product VARCHAR(255),
    activated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (license_id) REFERENCES licenses(id) ON DELETE CASCADE,
    UNIQUE KEY (license_id, fingerprint)
) ENGINE=InnoDB;

-- Seed some test data
INSERT INTO licenses (license_key, max_activations) VALUES ('FLAT-8822-1192-3301', 1);
INSERT INTO licenses (license_key, max_activations) VALUES ('FLAT-TEST-KEY-0001', 5);
INSERT INTO licenses (license_key, max_activations) VALUES ('FLAT-DEV-UNLIMITED', 999);
