-- Existing installations: import this migration once. New installations import schema.sql then this file.
CREATE TABLE course_pdfs (
 id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
 plan_id BIGINT UNSIGNED NOT NULL,
 title VARCHAR(160) NOT NULL,
 storage_key CHAR(64) NOT NULL UNIQUE,
 size_bytes INT UNSIGNED NOT NULL,
 enabled BOOLEAN NOT NULL DEFAULT TRUE,
 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
 FOREIGN KEY(plan_id) REFERENCES plans(id)
);
CREATE TABLE course_access (
 user_id BIGINT UNSIGNED NOT NULL,
 plan_id BIGINT UNSIGNED NOT NULL,
 payment_reference VARCHAR(190) NOT NULL,
 granted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
 revoked_at TIMESTAMP NULL,
 PRIMARY KEY(user_id,plan_id),
 FOREIGN KEY(user_id) REFERENCES users(id),
 FOREIGN KEY(plan_id) REFERENCES plans(id)
);
-- Only the future verified-payment backend may grant access. No browser grant endpoint exists.
