|
|
|
|
@ -2311,9 +2311,8 @@ CREATE TABLE cloud_traffic_ledger_events (
|
|
|
|
|
KEY cloud_traffic_ledger_pool_time (pool_id, effective_at, id)
|
|
|
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
|
|
|
|
|
|
-- Durable settlement accumulator. Mutable prepaid projections are updated on
|
|
|
|
|
-- every observation; new buckets use UTC-day windows while legacy hourly
|
|
|
|
|
-- windows remain readable and sealable during the clean upgrade.
|
|
|
|
|
-- Durable UTC-day settlement accumulator. Mutable prepaid projections are
|
|
|
|
|
-- updated on every observation; the window length is a schema invariant.
|
|
|
|
|
CREATE TABLE cloud_traffic_usage_settlement_buckets (
|
|
|
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
|
pool_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
@ -2324,7 +2323,6 @@ CREATE TABLE cloud_traffic_usage_settlement_buckets (
|
|
|
|
|
allocation_kind VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
allocation_target_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
bucket_start BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
bucket_seconds INT UNSIGNED NOT NULL,
|
|
|
|
|
seal_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
bucket_revision INT UNSIGNED NOT NULL,
|
|
|
|
|
amount_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
@ -2339,8 +2337,7 @@ CREATE TABLE cloud_traffic_usage_settlement_buckets (
|
|
|
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
UNIQUE KEY cloud_traffic_settlement_identity (
|
|
|
|
|
pool_id, instance_id, service_period_id,
|
|
|
|
|
allocation_kind, allocation_target_id, bucket_start, bucket_seconds,
|
|
|
|
|
bucket_revision
|
|
|
|
|
allocation_kind, allocation_target_id, bucket_start, bucket_revision
|
|
|
|
|
),
|
|
|
|
|
KEY cloud_traffic_settlement_due (state, seal_at, id),
|
|
|
|
|
KEY cloud_traffic_settlement_retention (state, updated_at, id),
|
|
|
|
|
@ -2357,9 +2354,8 @@ CREATE TABLE cloud_traffic_usage_settlement_buckets (
|
|
|
|
|
AND entitlement_id IS NULL AND allocation_target_id = 0)
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_traffic_settlement_bucket CHECK (
|
|
|
|
|
bucket_seconds IN (3600, 86400)
|
|
|
|
|
AND bucket_start % bucket_seconds = 0
|
|
|
|
|
AND seal_at = bucket_start + bucket_seconds
|
|
|
|
|
bucket_start % 86400 = 0
|
|
|
|
|
AND seal_at = bucket_start + 86400
|
|
|
|
|
AND bucket_revision > 0
|
|
|
|
|
AND first_observed_at >= bucket_start
|
|
|
|
|
AND last_observed_at >= first_observed_at
|
|
|
|
|
@ -2388,7 +2384,6 @@ CREATE TABLE cloud_traffic_settlement_receipts (
|
|
|
|
|
allocation_kind VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
|
|
|
allocation_target_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
bucket_start BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
bucket_seconds INT UNSIGNED NOT NULL,
|
|
|
|
|
max_revision INT UNSIGNED NOT NULL,
|
|
|
|
|
last_event_id BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
compacted_amount_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
|
|
|
@ -2398,7 +2393,7 @@ CREATE TABLE cloud_traffic_settlement_receipts (
|
|
|
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
|
|
|
UNIQUE KEY cloud_traffic_settlement_receipt_identity (
|
|
|
|
|
pool_id, instance_id, service_period_id,
|
|
|
|
|
allocation_kind, allocation_target_id, bucket_start, bucket_seconds
|
|
|
|
|
allocation_kind, allocation_target_id, bucket_start
|
|
|
|
|
),
|
|
|
|
|
KEY cloud_traffic_settlement_receipt_owner (user_id, instance_id, id),
|
|
|
|
|
KEY cloud_traffic_settlement_receipt_event (last_event_id),
|
|
|
|
|
@ -2411,8 +2406,7 @@ CREATE TABLE cloud_traffic_settlement_receipts (
|
|
|
|
|
AND entitlement_id IS NULL AND allocation_target_id = 0)
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_traffic_settlement_receipt_window CHECK (
|
|
|
|
|
bucket_seconds IN (3600, 86400)
|
|
|
|
|
AND bucket_start % bucket_seconds = 0
|
|
|
|
|
bucket_start % 86400 = 0
|
|
|
|
|
AND max_revision > 0
|
|
|
|
|
),
|
|
|
|
|
CONSTRAINT chk_cloud_traffic_settlement_receipt_totals CHECK (
|
|
|
|
|
|