Add admin and customer interfaces, orders, signed activation and leases, protected package delivery, keyring verification, migrations, security controls, tests and deployment documentation. Co-Authored-By: Craft Agent <agents-noreply@craft.do>
33 lines
1.6 KiB
SQL
33 lines
1.6 KiB
SQL
CREATE TABLE licenses (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
license_key CHAR(32) NOT NULL,
|
|
customer_id BIGINT UNSIGNED NOT NULL,
|
|
product_id BIGINT UNSIGNED NOT NULL,
|
|
status VARCHAR(32) NOT NULL DEFAULT 'active',
|
|
starts_at TIMESTAMP(6) NOT NULL,
|
|
expires_at TIMESTAMP(6) NOT NULL,
|
|
idempotency_key VARCHAR(128) NOT NULL,
|
|
issued_by BIGINT UNSIGNED NOT NULL,
|
|
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
|
revoked_at TIMESTAMP(6) NULL,
|
|
PRIMARY KEY (id),
|
|
UNIQUE KEY uq_licenses_key (license_key),
|
|
UNIQUE KEY uq_licenses_idempotency (issued_by, idempotency_key),
|
|
KEY idx_licenses_customer (customer_id), KEY idx_licenses_product (product_id), KEY idx_licenses_status (status),
|
|
CONSTRAINT fk_licenses_customer FOREIGN KEY (customer_id) REFERENCES customers(id),
|
|
CONSTRAINT fk_licenses_product FOREIGN KEY (product_id) REFERENCES products(id),
|
|
CONSTRAINT fk_licenses_admin FOREIGN KEY (issued_by) REFERENCES admins(id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
|
|
CREATE TABLE audit_events (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
actor_admin_id BIGINT UNSIGNED NOT NULL,
|
|
action VARCHAR(64) NOT NULL,
|
|
resource_type VARCHAR(64) NOT NULL,
|
|
resource_id BIGINT UNSIGNED NOT NULL,
|
|
details JSON NOT NULL,
|
|
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
|
PRIMARY KEY (id), KEY idx_audit_resource (resource_type, resource_id), KEY idx_audit_actor (actor_admin_id),
|
|
CONSTRAINT fk_audit_admin FOREIGN KEY (actor_admin_id) REFERENCES admins(id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|