diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index 16b54e82..1eccec44 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -160,7 +160,11 @@ libvirt 的持久 pool 定义就是 Agent 后续使用的映射,不另写存 公网网络接入在宿主机的“网络接入”中按资源池线路独立配置,可使用 `bridge:br0`、其他 Linux 网桥或 `network:default` 这样的 libvirt network。名称以字母或数字开头,后续只能包含字母、数字、点、下划线和短横线,bridge 名称为 1~15 字符,libvirt network 名称为 1~64 字符。宿主机上的公网网桥或 libvirt network 必须由运维预先准备。Agent 只发现、验证和使用现有公网网络,不创建公网网桥、不启动 libvirt network,也不修改公网地址、上游网关或挂载。`cloud_hosts.default_network` 仅保留为兼容展示值,不参与 Agent 就绪、调度、恢复、迁移或换 IP 决策;真正的运行时权威是资源池线路、当前 Agent 代次已验证的网络接入,以及绑定该接入的公网地址池。VPC 使用下述独立的 Agent 受管 bridge 和 L3 路由,不改变这一公网边界。 -当前完整 schema 版本为 `go-agent-wss-v55-traffic-checkpoint-tiers`。v48 将滥用监测拆分为 72 小时原始证据、短期终态投影、7 天去重凭据以及 5 分钟/小时趋势汇总;v49 为实例性能图表增加 5 分钟和小时汇总,并将一分钟原始点限制为 24 小时、小时趋势限制为 35 天;v50 保持分钟级 FEFO 扣减和游标更新不变,将同一小时、实例和额度的用量累积到持久结算桶,小时结束、额度耗尽、到期、债务结算或异常栅栏时再生成不可变账本事件。迟到采样使用新的桶修订,绝不改写已封存事件;v51 将性能历史改为逻辑实例主键,删除每行重复的宿主机 hash 和文本 UUID,将永久流量总数/检查点的 UUID 与 hash 改为二进制并删除未被读取路径使用的宽索引;v52 保持实时 FEFO 扣减不变,将新用量累积到 UTC 每日结算窗口,并通过 `bucket_seconds` 与 `seal_at` 继续识别和封存升级前的小时窗口;v53 增加紧凑结算凭据,冻结已经安全压缩的窗口身份、最大修订、账本事件和载荷哈希,让迟到采样无需依赖完整旧桶也能从下一修订继续;v54 启用7天安全窗后的完整桶压缩,只有账本身份、金额、载荷和哈希全部吻合时,才在同一主库事务中更新凭据并删除完整桶;v55 为每个逻辑实例写入一条 UTC 每日累计检查点,并在服务周期首次确定基准时按周期冻结精确边界锚点,维护迁移后仍沿用同一逻辑实例历史。部署既有数据库时必须先停止生命周期与滥用监测 worker,按当前 `cloud.sql`、`cloud_log.sql` 的新增表和字段制作一次性迁移并完成回填,再启动新代码;v51 涉及日志表主键与二进制身份重建,不能在采集 worker 运行时原地改列,也不能让 v50 代码与 v51 日志表混跑;v52 必须先为既有结算桶回填 `bucket_seconds = 3600` 与 `seal_at = bucket_start + 3600`,再替换唯一索引、到期索引和检查约束;v53 必须先创建 `cloud_traffic_settlement_receipts`;v54 必须增加 `cloud_traffic_settlement_retention` 索引后才能启动清理,验证失败的桶保持原样且不得人工跳过;v55 必须先给小时检查点回填可确认的逻辑 `instance_id`,再创建每日检查点和周期边界锚点表;无法唯一对应实例的旧检查点写入保留哨兵 `instance_id = 0`,不得伪造归属,自动清理也会忽略这些行。不得让缺少汇总表、结算桶窗口字段、紧凑凭据表、每日检查点、周期锚点或 `instance_id` 的旧数据库直接进入采集或流量结算。v47 为 `cloud_offers` 增加季度、年度及对应自动备份价格;既有方案升级时必须在恢复销售前显式回填 90/365 天价格,不能让数据库默认零价进入购买目录。从 v44 升级时,必须先停止滥用观测与投影 worker,为既有 finding 回填 `occurrence_generation = 1` 与 `transition_revision = 1`,再创建 `cloud_abuse_alert_events` 和 `cloud_abuse_alert_event_items`;从 v45 升级还必须停止通知 worker,创建 `cloud_abuse_alert_deliveries`、`administrator_telegram_delivery_gate` 并写入唯一 gate 行。历史 finding 不反向合成事件;事件只从升级后主库事务内真实发生的 `opened`、`escalated` 和 `evidence_clear` 解决转移产生。完成列、约束、索引、外键和 gate 核对后,先恢复滥用观测,再恢复通知 worker。 +当前完整 schema 版本为 `go-agent-wss-v56-daily-traffic-settlement`。v48~v55 已完成滥用证据分层、性能与流量日志压缩、UTC 每日结算、紧凑结算凭据、7 天安全窗压缩、每日累计检查点及服务周期边界锚点。v56 将结算窗口固定为 UTC 日,删除仅为旧小时结算桶保留的可变窗口字段和分支;`seal_at` 继续作为到期调度权威,分钟级 FEFO 扣减、游标、不可变账本、每日检查点和周期锚点均保持不变。 + +测试环境从 v55 升级 v56 时,必须先停止生命周期 worker,清空 `cloud_traffic_usage_settlement_buckets` 与 `cloud_traffic_settlement_receipts` 的旧结算细节,再删除旧窗口字段、重建两个身份唯一索引和日窗口检查约束,最后写入当前 schema marker 与真实 information_schema 指纹。旧结算细节可以丢弃,但不可变账本、池投影、实例游标、额度、每日检查点和周期锚点不得删除。完成 `php xcat cloudInit` 全量校验后才能恢复 worker;不得让 v55 代码与 v56 表结构混跑。全新部署只允许直接使用当前 `cloud.sql` 与 `cloud_log.sql`,不保留旧窗口兼容路径。 + +v47 为 `cloud_offers` 增加季度、年度及对应自动备份价格;既有方案升级时必须在恢复销售前显式回填 90/365 天价格,不能让数据库默认零价进入购买目录。从 v44 升级时,必须先停止滥用观测与投影 worker,为既有 finding 回填 `occurrence_generation = 1` 与 `transition_revision = 1`,再创建 `cloud_abuse_alert_events` 和 `cloud_abuse_alert_event_items`;从 v45 升级还必须停止通知 worker,创建 `cloud_abuse_alert_deliveries`、`administrator_telegram_delivery_gate` 并写入唯一 gate 行。历史 finding 不反向合成事件;事件只从升级后主库事务内真实发生的 `opened`、`escalated` 和 `evidence_clear` 解决转移产生。完成列、约束、索引、外键和 gate 核对后,先恢复滥用观测,再恢复通知 worker。 事件 header 与 projection receipt 在同一个主库事务中写入,且事件先于 receipt;同一实例同一采样桶的多规则、双协议族转移合并为一个 header 和多个 item。`continued` 不产生事件,`policy_replaced` 与 `owner_changed` 只关闭 finding,不能伪造“恢复”事件。item 已冻结当时的聚合 evidence、规则身份和 finding 代次,后续投递不得回读会变化的 finding。v46 为每个事件建立至多一条 Telegram 投递决策;远端调用开始后的中断或回执不确定统一进入 `unknown`,禁止自动重放。删除用户时按事件冻结的 `user_id` 显式删除 header,item 与投递账本按当前外键和账户清理规则收敛,避免实例转交后遗留原租户数据。 diff --git a/docs/SERVICE_COMPENSATION.md b/docs/SERVICE_COMPENSATION.md index 4d8a3d1a..3b4f6e7f 100644 --- a/docs/SERVICE_COMPENSATION.md +++ b/docs/SERVICE_COMPENSATION.md @@ -47,7 +47,7 @@ ## 部署 -全新数据库必须由当前 `CloudSetup` 创建并验证 `go-agent-wss-v55-traffic-checkpoint-tiers` 完整 schema;其中补偿模块包括: +全新数据库必须由当前 `CloudSetup` 创建并验证 `go-agent-wss-v56-daily-traffic-settlement` 完整 schema;其中补偿模块包括: - `cloud_service_compensations`; - `cloud_service_compensation_items`; diff --git a/docs/TRAFFIC_POOL.md b/docs/TRAFFIC_POOL.md index 0b50c0f3..08442a42 100644 --- a/docs/TRAFFIC_POOL.md +++ b/docs/TRAFFIC_POOL.md @@ -68,8 +68,8 @@ The accounting transaction advances the instance cursor, updates entitlement and pool projections, and accumulates the exact allocation in a durable UTC daily settlement bucket atomically. A completed UTC day, entitlement exhaustion, expiry, overage settlement or attention transition seals the -bucket into one immutable ledger event. Legacy hourly buckets remain sealable -during the clean upgrade. Late observations start a new revision instead of +bucket into one immutable ledger event. The window is fixed by the schema and +is not carried as mutable row data. Late observations start a new revision instead of rewriting an already sealed event. This reduces permanent ledger growth while preserving minute-level FEFO allocation and exact RX/TX attribution. It never locks instances, writes network restrictions, or calls an Agent. A diff --git a/web/app/Command/CloudSetup.php b/web/app/Command/CloudSetup.php index 28656d74..897edc4f 100644 --- a/web/app/Command/CloudSetup.php +++ b/web/app/Command/CloudSetup.php @@ -8,7 +8,7 @@ use App\Services\Config; /** Initializes only the clean-break PHP business and Agent log schemas. */ final class CloudSetup { - private const SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'; + private const SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'; /** Tables installed by ss.sql before cloudInit and owned by this schema. */ private const PREINSTALLED_MAIN_TABLES = [ 'ui_copy_locales', 'ui_copy_entries', 'ui_copy_drafts', @@ -583,7 +583,7 @@ final class CloudSetup 'cloud_traffic_usage_settlement_buckets' => [ 'id', 'pool_id', 'user_id', 'instance_id', 'service_period_id', 'entitlement_id', 'allocation_kind', 'allocation_target_id', - 'bucket_start', 'bucket_seconds', 'seal_at', 'bucket_revision', + 'bucket_start', 'seal_at', 'bucket_revision', 'amount_bytes', 'download_bytes', 'upload_bytes', 'sample_count', 'first_observed_at', 'last_observed_at', 'state', @@ -592,7 +592,7 @@ final class CloudSetup 'cloud_traffic_settlement_receipts' => [ 'id', 'pool_id', 'user_id', 'instance_id', 'service_period_id', 'entitlement_id', 'allocation_kind', 'allocation_target_id', - 'bucket_start', 'bucket_seconds', 'max_revision', + 'bucket_start', 'max_revision', 'last_event_id', 'compacted_amount_bytes', 'compacted_event_count', 'last_payload_hash', 'compacted_at', 'updated_at', @@ -1680,7 +1680,7 @@ final class CloudSetup 'columns' => [ 'pool_id', 'instance_id', 'service_period_id', 'allocation_kind', 'allocation_target_id', - 'bucket_start', 'bucket_seconds', 'bucket_revision', + 'bucket_start', 'bucket_revision', ], ], 'cloud_traffic_settlement_due' => [ @@ -1698,7 +1698,7 @@ final class CloudSetup 'columns' => [ 'pool_id', 'instance_id', 'service_period_id', 'allocation_kind', 'allocation_target_id', - 'bucket_start', 'bucket_seconds', + 'bucket_start', ], ], ], diff --git a/web/app/Models/CloudTrafficSettlementReceipt.php b/web/app/Models/CloudTrafficSettlementReceipt.php index 070c1de5..23b66914 100644 --- a/web/app/Models/CloudTrafficSettlementReceipt.php +++ b/web/app/Models/CloudTrafficSettlementReceipt.php @@ -16,7 +16,6 @@ final class CloudTrafficSettlementReceipt extends Model 'entitlement_id' => 'int', 'allocation_target_id' => 'int', 'bucket_start' => 'int', - 'bucket_seconds' => 'int', 'max_revision' => 'int', 'last_event_id' => 'int', 'compacted_amount_bytes' => 'int', diff --git a/web/app/Models/CloudTrafficUsageSettlementBucket.php b/web/app/Models/CloudTrafficUsageSettlementBucket.php index 39a1f3d6..8f7e8071 100644 --- a/web/app/Models/CloudTrafficUsageSettlementBucket.php +++ b/web/app/Models/CloudTrafficUsageSettlementBucket.php @@ -16,7 +16,6 @@ final class CloudTrafficUsageSettlementBucket extends Model 'entitlement_id' => 'int', 'allocation_target_id' => 'int', 'bucket_start' => 'int', - 'bucket_seconds' => 'int', 'seal_at' => 'int', 'bucket_revision' => 'int', 'amount_bytes' => 'int', diff --git a/web/app/Services/Cloud/CloudTrafficPoolAccounting.php b/web/app/Services/Cloud/CloudTrafficPoolAccounting.php index a4e1f1d0..fd6c25d7 100644 --- a/web/app/Services/Cloud/CloudTrafficPoolAccounting.php +++ b/web/app/Services/Cloud/CloudTrafficPoolAccounting.php @@ -1464,16 +1464,14 @@ final class CloudTrafficPoolAccounting ); } $targetId = $entitlementId ?? 0; - $bucketSeconds = self::SETTLEMENT_WINDOW_SECONDS; - $sealAt = $bucketStart + $bucketSeconds; + $sealAt = $bucketStart + self::SETTLEMENT_WINDOW_SECONDS; $identity = CloudTrafficUsageSettlementBucket::where( 'pool_id', (int) $pool->id )->where('instance_id', $instanceId) ->where('service_period_id', $servicePeriodId) ->where('allocation_kind', $kind) ->where('allocation_target_id', $targetId) - ->where('bucket_start', $bucketStart) - ->where('bucket_seconds', $bucketSeconds); + ->where('bucket_start', $bucketStart); $bucket = (clone $identity)->where('state', 'open') ->orderByDesc('bucket_revision')->lockForUpdate()->first(); if ($bucket === null) { @@ -1490,7 +1488,6 @@ final class CloudTrafficPoolAccounting ->where('allocation_kind', $kind) ->where('allocation_target_id', $targetId) ->where('bucket_start', $bucketStart) - ->where('bucket_seconds', $bucketSeconds) ->lockForUpdate()->value('max_revision'); $lastRevision = max($lastRevision, $receiptRevision); $bucket = new CloudTrafficUsageSettlementBucket(); @@ -1502,7 +1499,6 @@ final class CloudTrafficPoolAccounting $bucket->allocation_kind = $kind; $bucket->allocation_target_id = $targetId; $bucket->bucket_start = $bucketStart; - $bucket->bucket_seconds = $bucketSeconds; $bucket->seal_at = $sealAt; $bucket->bucket_revision = $lastRevision + 1; $bucket->amount_bytes = $amount; @@ -1646,7 +1642,6 @@ final class CloudTrafficPoolAccounting 'payload' => [ 'bucket_start' => (int) $bucket->bucket_start, 'bucket_revision' => (int) $bucket->bucket_revision, - 'bucket_seconds' => (int) $bucket->bucket_seconds, 'seal_at' => (int) $bucket->seal_at, 'download_bytes' => (int) $bucket->download_bytes, 'upload_bytes' => (int) $bucket->upload_bytes, diff --git a/web/app/Services/Cloud/CloudTrafficSettlementRetention.php b/web/app/Services/Cloud/CloudTrafficSettlementRetention.php index 00ac627c..230dca7b 100644 --- a/web/app/Services/Cloud/CloudTrafficSettlementRetention.php +++ b/web/app/Services/Cloud/CloudTrafficSettlementRetention.php @@ -123,8 +123,7 @@ final class CloudTrafficSettlementRetention ->where('allocation_kind', (string) $bucket->allocation_kind) ->where('allocation_target_id', (int) $bucket->allocation_target_id) - ->where('bucket_start', (int) $bucket->bucket_start) - ->where('bucket_seconds', (int) $bucket->bucket_seconds); + ->where('bucket_start', (int) $bucket->bucket_start); $receipt = (clone $receiptQuery)->lockForUpdate()->first(); if ($receipt === null) { $receipt = new CloudTrafficSettlementReceipt(); @@ -138,7 +137,6 @@ final class CloudTrafficSettlementRetention $receipt->allocation_target_id = (int) $bucket->allocation_target_id; $receipt->bucket_start = (int) $bucket->bucket_start; - $receipt->bucket_seconds = (int) $bucket->bucket_seconds; $receipt->max_revision = 0; $receipt->last_event_id = 0; $receipt->compacted_amount_bytes = 0; @@ -170,7 +168,7 @@ final class CloudTrafficSettlementRetention ): void { foreach ([ 'user_id', 'instance_id', 'service_period_id', - 'allocation_target_id', 'bucket_start', 'bucket_seconds', + 'allocation_target_id', 'bucket_start', ] as $field) { if ((int) $receipt->{$field} !== (int) $bucket->{$field}) { throw new \RuntimeException( @@ -253,7 +251,6 @@ final class CloudTrafficSettlementRetention $payload = [ 'bucket_start' => (int) $bucket->bucket_start, 'bucket_revision' => (int) $bucket->bucket_revision, - 'bucket_seconds' => (int) $bucket->bucket_seconds, 'seal_at' => (int) $bucket->seal_at, 'download_bytes' => (int) $bucket->download_bytes, 'upload_bytes' => (int) $bucket->upload_bytes, diff --git a/web/sql/cloud.sql b/web/sql/cloud.sql index d83ff558..31ea5463 100644 --- a/web/sql/cloud.sql +++ b/web/sql/cloud.sql @@ -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 ( diff --git a/web/tests/CloudAbuseMonitoringSchemaContractTest.php b/web/tests/CloudAbuseMonitoringSchemaContractTest.php index 0f8688bb..45b3279a 100644 --- a/web/tests/CloudAbuseMonitoringSchemaContractTest.php +++ b/web/tests/CloudAbuseMonitoringSchemaContractTest.php @@ -415,7 +415,7 @@ $assert(str_contains( $assert(str_contains( $setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'" + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'" ), 'CloudSetup schema version was not advanced for abuse observation.'); foreach (array_keys($mainTables + $logTables) as $table) { diff --git a/web/tests/CloudAbusePolicySchemaContractTest.php b/web/tests/CloudAbusePolicySchemaContractTest.php index e6d9e729..b632377b 100644 --- a/web/tests/CloudAbusePolicySchemaContractTest.php +++ b/web/tests/CloudAbusePolicySchemaContractTest.php @@ -96,7 +96,7 @@ foreach ($defaults->rules() as $code => $rule) { 'The fresh schema rule seed drifted from PHP: ' . $code); } $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && str_contains($service, "->where('active_slot', 1)->lockForUpdate()") && str_contains($service, "->where('active_slot', 1)->update") && str_contains($service, 'insertGetId'), diff --git a/web/tests/CloudAbuseProjectionLedgerContractTest.php b/web/tests/CloudAbuseProjectionLedgerContractTest.php index b3059b4d..42c31561 100644 --- a/web/tests/CloudAbuseProjectionLedgerContractTest.php +++ b/web/tests/CloudAbuseProjectionLedgerContractTest.php @@ -260,7 +260,7 @@ $assert(str_contains($projection, '->snapshotByIdentity($revision, $hash)') && !str_contains($projection, '->activeSnapshot()'), 'Projection can drift from the outbox identity to the current policy.'); $assert(str_contains($deployment, - '`go-agent-wss-v55-traffic-checkpoint-tiers`') + '`go-agent-wss-v56-daily-traffic-settlement`') && str_contains($deployment, '`occurrence_generation = 1` 与 `transition_revision = 1`') && str_contains($deployment, diff --git a/web/tests/CloudAdminTrafficPoolServiceTest.php b/web/tests/CloudAdminTrafficPoolServiceTest.php index e7f55c17..0b9afde5 100644 --- a/web/tests/CloudAdminTrafficPoolServiceTest.php +++ b/web/tests/CloudAdminTrafficPoolServiceTest.php @@ -146,7 +146,6 @@ $schema->create('cloud_traffic_usage_settlement_buckets', static function (Bluep $t->string('allocation_kind'); $t->integer('allocation_target_id'); $t->integer('bucket_start'); - $t->integer('bucket_seconds'); $t->integer('seal_at'); $t->integer('bucket_revision'); $t->integer('amount_bytes'); @@ -161,8 +160,7 @@ $schema->create('cloud_traffic_usage_settlement_buckets', static function (Bluep $t->integer('updated_at'); $t->unique([ 'pool_id', 'instance_id', 'service_period_id', 'allocation_kind', - 'allocation_target_id', 'bucket_start', 'bucket_seconds', - 'bucket_revision', + 'allocation_target_id', 'bucket_start', 'bucket_revision', ], 'traffic_settlement_identity'); }); $schema->create('cloud_traffic_settlement_receipts', static function (Blueprint $t): void { @@ -175,7 +173,6 @@ $schema->create('cloud_traffic_settlement_receipts', static function (Blueprint $t->string('allocation_kind'); $t->integer('allocation_target_id'); $t->integer('bucket_start'); - $t->integer('bucket_seconds'); $t->integer('max_revision'); $t->integer('last_event_id'); $t->integer('compacted_amount_bytes'); diff --git a/web/tests/CloudBackupPublicationPreparationSchemaContractTest.php b/web/tests/CloudBackupPublicationPreparationSchemaContractTest.php index 60d7f57c..a9a2a029 100644 --- a/web/tests/CloudBackupPublicationPreparationSchemaContractTest.php +++ b/web/tests/CloudBackupPublicationPreparationSchemaContractTest.php @@ -64,7 +64,7 @@ foreach ([ 'CloudSetup omits backup preparation contract: ' . $required); } $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && str_contains($setup, "'columns' => [\n 'create_request_actor_id',\n 'create_request_idempotency_key',") && str_contains($setup, "'non_unique' => 0"), diff --git a/web/tests/CloudFreshSchemaContractTest.php b/web/tests/CloudFreshSchemaContractTest.php index 92e5e4aa..e9d1a018 100644 --- a/web/tests/CloudFreshSchemaContractTest.php +++ b/web/tests/CloudFreshSchemaContractTest.php @@ -27,10 +27,10 @@ $assert(stripos($schema, 'compatibility import') === false $assert(!preg_match('/\bengine_[A-Za-z0-9_]*\b/', $schema), 'cloud.sql retained an engine-prefixed identifier.'); $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && !str_contains($setup, "SCHEMA_VERSION = 'go-v1'") - && str_contains($deployment, '`go-agent-wss-v55-traffic-checkpoint-tiers`') - && str_contains($compensation, '`go-agent-wss-v55-traffic-checkpoint-tiers`'), + && str_contains($deployment, '`go-agent-wss-v56-daily-traffic-settlement`') + && str_contains($compensation, '`go-agent-wss-v56-daily-traffic-settlement`'), 'Outbound Agent schema must reject the incompatible earlier Go database.'); $assert(str_contains($schema, "timezone VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'UTC'") diff --git a/web/tests/CloudMaintenanceNoticeSchemaContractTest.php b/web/tests/CloudMaintenanceNoticeSchemaContractTest.php index 82e6c103..b243f73f 100644 --- a/web/tests/CloudMaintenanceNoticeSchemaContractTest.php +++ b/web/tests/CloudMaintenanceNoticeSchemaContractTest.php @@ -56,7 +56,7 @@ foreach ([ } $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'"), + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'"), 'CloudSetup schema version was not advanced for maintenance notices.'); echo "Maintenance notice schema contracts passed.\n"; diff --git a/web/tests/CloudPublicIpPoolReplacementSchemaContractTest.php b/web/tests/CloudPublicIpPoolReplacementSchemaContractTest.php index 4023c155..3b668583 100644 --- a/web/tests/CloudPublicIpPoolReplacementSchemaContractTest.php +++ b/web/tests/CloudPublicIpPoolReplacementSchemaContractTest.php @@ -53,7 +53,7 @@ $assert(is_string($schema) 'Public-pool replacement lacks durable batch, child, or claim schema.'); $assert(is_string($setup) && str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && str_contains($setup, "'cloud_public_ip_pool_replacement_batches'") && str_contains($setup, diff --git a/web/tests/CloudPublicNetworkTransitionSchemaContractTest.php b/web/tests/CloudPublicNetworkTransitionSchemaContractTest.php index e82bb181..0f1499c5 100644 --- a/web/tests/CloudPublicNetworkTransitionSchemaContractTest.php +++ b/web/tests/CloudPublicNetworkTransitionSchemaContractTest.php @@ -170,7 +170,7 @@ $assert(str_contains($setup, 'CloudSetup does not verify index uniqueness and ordered columns.'); $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && str_contains($setup, "'cloud_public_network_transitions'") && str_contains($setup, "'cloud_public_network_transition_ips'") && str_contains($setup, "'reservation_ip_claim_id'") diff --git a/web/tests/CloudRescueCatalogSchemaContractTest.php b/web/tests/CloudRescueCatalogSchemaContractTest.php index 4476a73f..d20278ed 100644 --- a/web/tests/CloudRescueCatalogSchemaContractTest.php +++ b/web/tests/CloudRescueCatalogSchemaContractTest.php @@ -57,7 +57,7 @@ $assert($replica !== '' && str_contains($replica, 'cleanup_resolved_at BIGINT UNSIGNED'), 'Rescue replica cannot prove exact identity or retain cleanup debt.'); $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && str_contains($setup, "'cloud_rescue_artifact_delete_due'") && str_contains($setup, "'cloud_rescue_replica_cleanup'"), 'CloudSetup version or rescue catalog indexes are incomplete.'); diff --git a/web/tests/CloudRestoreMigrationLedgerContractTest.php b/web/tests/CloudRestoreMigrationLedgerContractTest.php index d556740b..b8145eac 100644 --- a/web/tests/CloudRestoreMigrationLedgerContractTest.php +++ b/web/tests/CloudRestoreMigrationLedgerContractTest.php @@ -218,7 +218,7 @@ foreach ([ 'CloudSetup omits restore/migration ledger contract: ' . $required); } $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && str_contains($attemptModel, "protected \$table = 'cloud_backup_restore_attempts';") && str_contains($attemptModel, "'active_attempt' => 'int'") diff --git a/web/tests/CloudServiceCompensationSchemaContractTest.php b/web/tests/CloudServiceCompensationSchemaContractTest.php index f8b31261..c9bccc32 100644 --- a/web/tests/CloudServiceCompensationSchemaContractTest.php +++ b/web/tests/CloudServiceCompensationSchemaContractTest.php @@ -105,7 +105,7 @@ $assert(str_contains($setup, 'CloudSetup lost the open-compensation fence index contract.'); $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'"), + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'"), 'CloudSetup schema version was not advanced for service compensation.'); $appliedShape = preg_match( diff --git a/web/tests/CloudStoragePublicationSchemaContractTest.php b/web/tests/CloudStoragePublicationSchemaContractTest.php index afa06a3a..ec1e2ac8 100644 --- a/web/tests/CloudStoragePublicationSchemaContractTest.php +++ b/web/tests/CloudStoragePublicationSchemaContractTest.php @@ -138,7 +138,7 @@ $assert(is_string($publicationModel) && str_contains($artifactModel, "'maximum_size_bytes' => 'int'"), 'Storage publication/artifact model contracts are incomplete.'); $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'"), + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'"), 'CloudSetup schema version was not advanced for durable publications.'); echo "Storage publication schema contracts passed.\n"; diff --git a/web/tests/CloudTemplateImportIntentContractTest.php b/web/tests/CloudTemplateImportIntentContractTest.php index 0b8b16e2..eb5dc996 100644 --- a/web/tests/CloudTemplateImportIntentContractTest.php +++ b/web/tests/CloudTemplateImportIntentContractTest.php @@ -63,7 +63,7 @@ $assert(str_contains($schema, && str_contains($schema, 'CONSTRAINT chk_cloud_template_import_completion CHECK (') && str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'"), + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'"), 'Template imports are missing durable identity or terminal-state constraints.'); $assert(str_contains($routes, "'/admin/cloud-template-imports'") && str_contains($routes, "'/admin/cloud-template-imports/{id}'") diff --git a/web/tests/CloudTrafficPoolAccountingTest.php b/web/tests/CloudTrafficPoolAccountingTest.php index 506fae1f..a873b382 100644 --- a/web/tests/CloudTrafficPoolAccountingTest.php +++ b/web/tests/CloudTrafficPoolAccountingTest.php @@ -135,7 +135,6 @@ $schema->create('cloud_traffic_usage_settlement_buckets', static function (Bluep $table->string('allocation_kind'); $table->integer('allocation_target_id'); $table->integer('bucket_start'); - $table->integer('bucket_seconds')->default(86400); $table->integer('seal_at'); $table->integer('bucket_revision'); $table->integer('amount_bytes'); @@ -150,8 +149,7 @@ $schema->create('cloud_traffic_usage_settlement_buckets', static function (Bluep $table->integer('updated_at'); $table->unique([ 'pool_id', 'instance_id', 'service_period_id', 'allocation_kind', - 'allocation_target_id', 'bucket_start', 'bucket_seconds', - 'bucket_revision', + 'allocation_target_id', 'bucket_start', 'bucket_revision', ], 'traffic_settlement_identity'); }); $schema->create('cloud_traffic_settlement_receipts', static function (Blueprint $table): void { @@ -164,7 +162,6 @@ $schema->create('cloud_traffic_settlement_receipts', static function (Blueprint $table->string('allocation_kind'); $table->integer('allocation_target_id'); $table->integer('bucket_start'); - $table->integer('bucket_seconds'); $table->integer('max_revision'); $table->integer('last_event_id'); $table->integer('compacted_amount_bytes'); @@ -174,7 +171,7 @@ $schema->create('cloud_traffic_settlement_receipts', static function (Blueprint $table->integer('updated_at'); $table->unique([ 'pool_id', 'instance_id', 'service_period_id', 'allocation_kind', - 'allocation_target_id', 'bucket_start', 'bucket_seconds', + 'allocation_target_id', 'bucket_start', ], 'traffic_settlement_receipt_identity'); }); $schema->create('cloud_traffic_instance_cursors', static function (Blueprint $table): void { @@ -791,7 +788,6 @@ $openBucket = Capsule::table('cloud_traffic_usage_settlement_buckets') ->where('instance_id', 72)->where('state', 'open')->first(); $assert($openBucket !== null && (int) $openBucket->bucket_start === $settlementDay - && (int) $openBucket->bucket_seconds === 86_400 && (int) $openBucket->seal_at === $settlementDay + 86_400 && (int) $openBucket->amount_bytes === 33 && (int) $openBucket->download_bytes === 25 diff --git a/web/tests/CloudTrafficPoolAttentionIntegrationTest.php b/web/tests/CloudTrafficPoolAttentionIntegrationTest.php index ee459cf8..040638a0 100644 --- a/web/tests/CloudTrafficPoolAttentionIntegrationTest.php +++ b/web/tests/CloudTrafficPoolAttentionIntegrationTest.php @@ -130,7 +130,6 @@ $schema->create('cloud_traffic_usage_settlement_buckets', static function (Bluep $table->string('allocation_kind'); $table->integer('allocation_target_id'); $table->integer('bucket_start'); - $table->integer('bucket_seconds'); $table->integer('seal_at'); $table->integer('bucket_revision'); $table->integer('amount_bytes'); @@ -145,8 +144,7 @@ $schema->create('cloud_traffic_usage_settlement_buckets', static function (Bluep $table->integer('updated_at'); $table->unique([ 'pool_id', 'instance_id', 'service_period_id', 'allocation_kind', - 'allocation_target_id', 'bucket_start', 'bucket_seconds', - 'bucket_revision', + 'allocation_target_id', 'bucket_start', 'bucket_revision', ], 'traffic_settlement_identity'); }); $schema->create('cloud_traffic_settlement_receipts', static function (Blueprint $table): void { @@ -159,7 +157,6 @@ $schema->create('cloud_traffic_settlement_receipts', static function (Blueprint $table->string('allocation_kind'); $table->integer('allocation_target_id'); $table->integer('bucket_start'); - $table->integer('bucket_seconds'); $table->integer('max_revision'); $table->integer('last_event_id'); $table->integer('compacted_amount_bytes'); diff --git a/web/tests/CloudTrafficPoolSchemaContractTest.php b/web/tests/CloudTrafficPoolSchemaContractTest.php index 48eb4fdc..18fe2855 100644 --- a/web/tests/CloudTrafficPoolSchemaContractTest.php +++ b/web/tests/CloudTrafficPoolSchemaContractTest.php @@ -49,7 +49,10 @@ $assert(str_contains($schema, && str_contains($schema, 'UNIQUE KEY cloud_traffic_settlement_identity (') && str_contains($schema, - 'allocation_kind, allocation_target_id, bucket_start, bucket_seconds,') + 'allocation_kind, allocation_target_id, bucket_start, bucket_revision') + && !str_contains($schema, 'bucket_seconds INT UNSIGNED NOT NULL') + && str_contains($schema, 'bucket_start % 86400 = 0') + && str_contains($schema, 'seal_at = bucket_start + 86400') && str_contains($schema, 'KEY cloud_traffic_settlement_due (state, seal_at, id)') && str_contains($schema, @@ -83,7 +86,7 @@ $assert(str_contains($schema, 'Service-period traffic-pool identity is not frozen or indexed.'); $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && str_contains($setup, "'chk_cloud_traffic_entitlement_balance'") && str_contains($setup, "'cloud_traffic_ledger_sequence'") && str_contains($setup, "'chk_cloud_traffic_settlement_state'") diff --git a/web/tests/CloudVpcSchemaContractTest.php b/web/tests/CloudVpcSchemaContractTest.php index 047a8307..b997b71b 100644 --- a/web/tests/CloudVpcSchemaContractTest.php +++ b/web/tests/CloudVpcSchemaContractTest.php @@ -101,7 +101,7 @@ $assert(str_contains($jobs, 'vpc_id BIGINT UNSIGNED DEFAULT NULL') 'Cloud jobs cannot be correlated to VPC or VPC-port work.'); $assert(str_contains($setup, - "private const SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "private const SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && str_contains($setup, "'name' => 'cloud_vpc_enabled'") && str_contains($setup, "'value' => 'false'") && str_contains($setup, diff --git a/web/tests/UiCopyCatalogSchemaContractTest.php b/web/tests/UiCopyCatalogSchemaContractTest.php index 01b0d92f..09496c3b 100644 --- a/web/tests/UiCopyCatalogSchemaContractTest.php +++ b/web/tests/UiCopyCatalogSchemaContractTest.php @@ -104,7 +104,7 @@ foreach ($models as $class => $modelTable) { } $assert(str_contains($setup, - "SCHEMA_VERSION = 'go-agent-wss-v55-traffic-checkpoint-tiers'") + "SCHEMA_VERSION = 'go-agent-wss-v56-daily-traffic-settlement'") && str_contains($setup, "self::schema('ss.sql') . \"\\0\" . self::schema('cloud.sql')") && str_contains($setup,