CREATE TABLE offline_orders ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, order_no CHAR(32) NOT NULL, customer_id BIGINT UNSIGNED NOT NULL, product_id BIGINT UNSIGNED NOT NULL, amount_cents BIGINT UNSIGNED NOT NULL, currency CHAR(3) NOT NULL DEFAULT 'CNY', status VARCHAR(32) NOT NULL DEFAULT 'pending_payment', payment_reference VARCHAR(190) NULL, paid_at TIMESTAMP(6) NULL, paid_by BIGINT UNSIGNED NULL, issued_license_id BIGINT UNSIGNED NULL, created_by BIGINT UNSIGNED NOT NULL, created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (id), UNIQUE KEY uq_offline_orders_no (order_no), UNIQUE KEY uq_offline_orders_license (issued_license_id), KEY idx_offline_orders_customer (customer_id), KEY idx_offline_orders_status (status), CONSTRAINT fk_offline_orders_customer FOREIGN KEY (customer_id) REFERENCES customers(id), CONSTRAINT fk_offline_orders_product FOREIGN KEY (product_id) REFERENCES products(id), CONSTRAINT fk_offline_orders_license FOREIGN KEY (issued_license_id) REFERENCES licenses(id), CONSTRAINT fk_offline_orders_admin FOREIGN KEY (created_by) REFERENCES admins(id), CONSTRAINT fk_offline_orders_paid_by FOREIGN KEY (paid_by) REFERENCES admins(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; CREATE TABLE order_operations ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, order_id BIGINT UNSIGNED NOT NULL, actor_admin_id BIGINT UNSIGNED NOT NULL, operation VARCHAR(32) NOT NULL, idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, request_fingerprint BINARY(32) NOT NULL, response JSON NOT NULL, created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), PRIMARY KEY (id), UNIQUE KEY uq_order_operations_key (actor_admin_id, operation, idempotency_key), CONSTRAINT fk_order_operations_order FOREIGN KEY (order_id) REFERENCES offline_orders(id), CONSTRAINT fk_order_operations_admin FOREIGN KEY (actor_admin_id) REFERENCES admins(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;