Initialize the D1 database
Cloudflare D1 is a distributed SQLite database. Signet uses it to store users, orders, products, licenses, and the audit log.
You've already created the database and pushed the schema in the previous step. This page explains what was created and why, so you understand the data model before you start using it.
The five tables
users
Stores registered accounts.
| Column | Purpose |
|---|---|
id | UUID, primary key |
email | Unique, lowercase |
nickname | Display name (shown publicly) |
password_hash | PBKDF2-SHA256 hash |
password_salt | Per-user salt |
created_at | Unix ms timestamp |
The email is stored in lowercase and enforced unique. The password hash uses 100,000 iterations of PBKDF2-SHA256 — same parameters as the admin password.
orders
Stores paid orders from payment providers.
| Column | Purpose |
|---|---|
id | UUID, primary key |
order_no | Order number from the provider |
provider | Adapter name (afdian, stripe, manual, …) |
provider_user | Buyer's ID on the payment platform (optional) |
provider_raw | Original webhook payload (JSON) |
amount | Payment amount as a string |
status | 2 = paid |
bound_user_id | Which user this order belongs to |
bound_at | When it was bound |
created_at | When the order arrived |
The pair (provider, order_no) is unique. This means two different providers can issue order numbers that happen to collide without conflict.
Virtual orders created by the admin panel use the prefix MANUAL- in order_no to prevent anyone from trying to bind them through the normal flow.
products
Stores products created by users.
| Column | Purpose |
|---|---|
id | UUID, primary key |
user_id | Owner |
name | Product name |
product_uid | Short ID embedded in license files |
created_at | Unix ms timestamp |
The product_uid is what ends up in the license file. It's short (16 chars) and uppercase, easy to read in support emails.
licenses
Stores every license issuance.
| Column | Purpose |
|---|---|
id | UUID, primary key |
product_id | Which product |
user_id | Which user |
fingerprint | Buyer's user ID (for tracing) |
issued_at | Unix seconds timestamp |
banned | 1 if revoked |
manual | 1 if issued by admin |
note | Free-form admin notes |
ban_reason | Shown publicly if banned |
Note that the same user can issue multiple licenses for the same product (different machines, re-downloads). Each issuance gets its own row. This is intentional — it gives you an audit trail.
audit_log
Stores every administrative action.
| Column | Purpose |
|---|---|
id | UUID, primary key |
admin_id | Admin username (not a foreign key) |
action | ban_license, grant_pro, admin_reset_password, … |
target | ID of the affected record |
detail | JSON with action-specific data |
created_at | Unix ms timestamp |
Admin usernames are stored directly, not as foreign keys, because admins are not rows in the users table — they come from environment variables.
Verifying the schema
Run:
npx wrangler d1 execute signet-db \
--command="SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;" \
--remoteExpected output:
_cf_KV
audit_log
licenses
orders
products
usersIf you see all six, you're good.
Inspecting a table
To see the structure of any table:
npx wrangler d1 execute signet-db \
--command="PRAGMA table_info(users);" \
--remoteQuerying data
You can run any SQL query through wrangler. For example:
# Count registered users
npx wrangler d1 execute signet-db \
--command="SELECT COUNT(*) FROM users;" \
--remote
# List the 10 most recent orders
npx wrangler d1 execute signet-db \
--command="SELECT order_no, provider, amount, created_at FROM orders ORDER BY created_at DESC LIMIT 10;" \
--remoteYou can also use the D1 Console in the Cloudflare dashboard — it has a nicer interface for ad-hoc queries.
Backups
D1 doesn't have automatic point-in-time recovery on the free tier. For critical data, periodically export:
npx wrangler d1 export signet-db --output=backup.sql --remoteStore the file somewhere safe. In a disaster, you can restore with:
npx wrangler d1 execute signet-db --file=backup.sql --remoteWhat's next
The infrastructure is ready. Now configure the payment provider so users can actually buy things.
→ Configure Afdian