Skip to main content

Module db

Module db 

Source
Expand description

Database access layer for the SaaS domain management module.

All queries run against the schema defined in migrations/20240115000001_saas_domains.sql. Queries use runtime sqlx (query/query_as) rather than the compile-time-checked macros so the crate builds without a live database connection.

Functions§

check_domain_quota
Return (current_domain_count, max_domains) for a tenant.
create_api_key
Insert a new API key row (the raw key is never stored, only its hash).
create_backend
Add a backend to an upstream.
create_domain
Insert a new domain and return it.
create_route
Create a route for a domain.
create_upstream
Create an upstream (and any backends supplied inline).
create_verification_challenge
Record a verification challenge for a domain.
delete_api_key
Delete an API key scoped to a tenant.
delete_backend
Delete a backend, verifying it belongs to the tenant’s upstream.
delete_domain
Delete a domain scoped to a tenant. Returns whether a row was removed.
delete_route
Delete a route scoped to a tenant.
delete_upstream
Delete an upstream scoped to a tenant.
disable_api_key
Disable an API key without deleting it.
disable_domain
Disable a domain.
domain_exists
Check whether a domain is already registered (globally unique).
enable_api_key
Re-enable a disabled API key.
enable_domain
Enable a domain.
get_api_key_for_tenant
Fetch an API key scoped to a tenant.
get_domain_for_tenant
Fetch a domain scoped to a tenant.
get_route_for_tenant
Fetch a route scoped to a tenant.
get_tenant_usage
Aggregate usage statistics for a tenant.
get_upstream_for_tenant
Fetch an upstream (with its backends) scoped to a tenant.
is_tenant_active
Whether a tenant exists and is active.
list_api_keys
List API keys for a tenant.
list_domains
List all domains for a tenant.
list_routes_for_domain
List routes for a domain, highest priority first.
list_upstreams
List upstreams (with backends) for a tenant.
record_verification_attempt
Increment the verification attempt counter and stamp the attempt time.
update_last_used
Stamp an API key’s last-used time (best-effort).
update_route
Apply a partial update to a route (only supplied fields change).
update_ssl_status
Update a domain’s SSL status and optional expiry.
update_upstream
Apply a partial update to an upstream.
update_verification_status
Update a domain’s verification status (stamping verified_at on success).
validate_api_key_by_hash
Look up an API key by its hash, excluding expired keys.