refactor(traffic): compact usage settlement ledger

go
codex 4 days ago
parent 2128a6b630
commit 067370adc1

@ -160,7 +160,7 @@ 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-v49-metric-history-rollups`。v48 将滥用监测拆分为 72 小时原始证据、短期终态投影、7 天去重凭据以及 5 分钟/小时趋势汇总;v49 为实例性能图表增加 5 分钟和小时汇总,并将一分钟原始点限制为 24 小时。部署既有数据库时必须先停止生命周期与滥用监测 worker,按当前 `cloud.sql`、`cloud_log.sql` 的新增表和字段制作一次性迁移并完成回填,再启动新代码;不得让缺少汇总表或 `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-v50-traffic-settlement-buckets`。v48 将滥用监测拆分为 72 小时原始证据、短期终态投影、7 天去重凭据以及 5 分钟/小时趋势汇总;v49 为实例性能图表增加 5 分钟和小时汇总,并将一分钟原始点限制为 24 小时;v50 保持分钟级 FEFO 扣减和游标更新不变,将同一小时、实例和额度的用量累积到持久结算桶,小时结束、额度耗尽、到期、债务结算或异常栅栏时再生成不可变账本事件。迟到采样使用新的桶修订,绝不改写已封存事件。部署既有数据库时必须先停止生命周期与滥用监测 worker,按当前 `cloud.sql`、`cloud_log.sql` 的新增表和字段制作一次性迁移并完成回填,再启动新代码;不得让缺少汇总表、结算桶或 `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。
事件 header 与 projection receipt 在同一个主库事务中写入,且事件先于 receipt;同一实例同一采样桶的多规则、双协议族转移合并为一个 header 和多个 item。`continued` 不产生事件,`policy_replaced` 与 `owner_changed` 只关闭 finding,不能伪造“恢复”事件。item 已冻结当时的聚合 evidence、规则身份和 finding 代次,后续投递不得回读会变化的 finding。v46 为每个事件建立至多一条 Telegram 投递决策;远端调用开始后的中断或回执不确定统一进入 `unknown`,禁止自动重放。删除用户时按事件冻结的 `user_id` 显式删除 header,item 与投递账本按当前外键和账户清理规则收敛,避免实例转交后遗留原租户数据。

@ -47,7 +47,7 @@
## 部署
全新数据库必须由当前 `CloudSetup` 创建并验证 `go-agent-wss-v49-metric-history-rollups` 完整 schema;其中补偿模块包括:
全新数据库必须由当前 `CloudSetup` 创建并验证 `go-agent-wss-v50-traffic-settlement-buckets` 完整 schema;其中补偿模块包括:
- `cloud_service_compensations`;
- `cloud_service_compensation_items`;

@ -64,9 +64,14 @@ order is always:
pool -> instance cursor -> entitlements
```
The accounting transaction advances the instance cursor, appends immutable
ledger events, and updates entitlement and pool projections atomically. It
never locks instances, writes network restrictions, or calls an Agent. A
The accounting transaction advances the instance cursor, updates entitlement
and pool projections, and accumulates the exact allocation in a durable hourly
settlement bucket atomically. A completed hour, entitlement exhaustion,
expiry, overage settlement or attention transition seals the bucket into one
immutable ledger event. 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
later per-instance policy transaction reads the pool projection and owns the
separate lock order:
@ -150,10 +155,11 @@ For accepted traffic observations:
observed_delta = allocated_consumption + overage_delta
```
No projection may become negative. Immutable ledger events are the audit
source; pool, entitlement and cursor projections must be verifiable from them.
Projection mismatch fences automatic network restoration for that pool but
does not delete the ledger or issue another remote mutation.
No projection may become negative. Sealed immutable ledger events plus any
still-open durable settlement buckets are the accounting audit source; pool,
entitlement and cursor projections must be verifiable from that combined
state. Projection mismatch fences automatic network restoration for that pool
but does not delete the ledger or issue another remote mutation.
Before enforcement, the feature may run in shadow mode. After traffic has
been shared across instances, rolling back to per-instance balances is not

@ -131,10 +131,13 @@ Advance the group to `shadow`. The lifecycle process then performs, in order:
3. activation, expiry and closing of entitlements;
4. ordinary runtime and per-instance lifecycle reconciliation.
Shadow mode creates the real pool, entitlement, cursor and immutable ledger
records, but it does not add or remove the `traffic_pool_exhausted` network
restriction. Once a service period or pool is durably linked to the group,
shadow mode cannot be returned to disabled; failures must be repaired forward.
Shadow mode creates the real pool, entitlement, cursor, durable hourly
settlement buckets and immutable sealed ledger records, but it does not add or
remove the `traffic_pool_exhausted` network restriction. Open buckets are part
of projection verification until sealed; they are not permission to replay a
counter observation. Once a service period or pool is durably linked to the
group, shadow mode cannot be returned to disabled; failures must be repaired
forward.
Keep the group in shadow for a representative usage and renewal window. At a
minimum, observe several collection intervals, a multi-instance allocation,

@ -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-v49-metric-history-rollups';
private const SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets';
/** 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',
@ -53,7 +53,9 @@ final class CloudSetup
'cloud_public_network_transition_ips',
'cloud_service_periods',
'cloud_traffic_pools', 'cloud_traffic_entitlements',
'cloud_traffic_ledger_events', 'cloud_traffic_instance_cursors',
'cloud_traffic_ledger_events',
'cloud_traffic_usage_settlement_buckets',
'cloud_traffic_instance_cursors',
'cloud_traffic_scan_failures',
'cloud_instance_network_restrictions',
'cloud_instance_network_policy_states',
@ -575,6 +577,14 @@ final class CloudSetup
'entitlement_id', 'amount_bytes', 'effective_at',
'observed_at', 'payload_json', 'created_at',
],
'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_revision', 'amount_bytes',
'download_bytes', 'upload_bytes',
'sample_count', 'first_observed_at', 'last_observed_at', 'state',
'sealed_event_id', 'created_at', 'updated_at',
],
'cloud_traffic_instance_cursors' => [
'instance_id', 'user_id', 'pool_id',
'accounted_download_bytes', 'accounted_upload_bytes',
@ -823,6 +833,12 @@ final class CloudSetup
'chk_cloud_traffic_entitlement_balance',
'chk_cloud_traffic_entitlement_state',
],
'cloud_traffic_usage_settlement_buckets' => [
'chk_cloud_traffic_settlement_identity',
'chk_cloud_traffic_settlement_bucket',
'chk_cloud_traffic_settlement_amount',
'chk_cloud_traffic_settlement_state',
],
'cloud_traffic_instance_cursors' => [
'chk_cloud_traffic_cursor_state',
],
@ -1168,6 +1184,13 @@ final class CloudSetup
'cloud_traffic_ledger_owner', 'cloud_traffic_ledger_instance',
'cloud_traffic_ledger_period', 'cloud_traffic_ledger_pool_time',
],
'cloud_traffic_usage_settlement_buckets' => [
'PRIMARY', 'cloud_traffic_settlement_identity',
'cloud_traffic_settlement_due',
'cloud_traffic_settlement_entitlement',
'cloud_traffic_settlement_owner',
'cloud_traffic_settlement_event',
],
'cloud_traffic_instance_cursors' => [
'PRIMARY', 'cloud_traffic_cursor_pool',
'cloud_traffic_cursor_owner',
@ -1594,6 +1617,20 @@ final class CloudSetup
'columns' => ['publication_id', 'copy_key'],
],
],
'cloud_traffic_usage_settlement_buckets' => [
'cloud_traffic_settlement_identity' => [
'non_unique' => 0,
'columns' => [
'pool_id', 'instance_id', 'service_period_id',
'allocation_kind', 'allocation_target_id',
'bucket_start', 'bucket_revision',
],
],
'cloud_traffic_settlement_due' => [
'non_unique' => 1,
'columns' => ['state', 'bucket_start', 'id'],
],
],
'cloud_instance_backups' => [
'cloud_instance_backup_create_request' => [
'non_unique' => 0,

@ -0,0 +1,30 @@
<?php
namespace App\Models;
final class CloudTrafficUsageSettlementBucket extends Model
{
protected $connection = 'default';
protected $table = 'cloud_traffic_usage_settlement_buckets';
protected $casts = [
'id' => 'int',
'pool_id' => 'int',
'user_id' => 'int',
'instance_id' => 'int',
'service_period_id' => 'int',
'entitlement_id' => 'int',
'allocation_target_id' => 'int',
'bucket_start' => 'int',
'bucket_revision' => 'int',
'amount_bytes' => 'int',
'download_bytes' => 'int',
'upload_bytes' => 'int',
'sample_count' => 'int',
'first_observed_at' => 'int',
'last_observed_at' => 'int',
'sealed_event_id' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
}

@ -10,6 +10,7 @@ use App\Models\CloudTrafficLedgerEvent;
use App\Models\CloudTrafficPool;
use App\Models\CloudTrafficPoolGroup;
use App\Models\CloudTrafficScanFailure;
use App\Models\CloudTrafficUsageSettlementBucket;
/**
* Shared prepaid traffic accounting.
@ -833,6 +834,9 @@ final class CloudTrafficPoolAccounting
$forfeited += $amount;
}
}
$consumed += (int) CloudTrafficUsageSettlementBucket::where(
'entitlement_id', (int) $entitlement->id
)->where('state', 'open')->sum('amount_bytes');
if ($granted !== (int) $entitlement->granted_bytes
|| $consumed !== (int) $entitlement->consumed_bytes
|| $forfeited !== (int) $entitlement->forfeited_bytes) {
@ -842,6 +846,10 @@ final class CloudTrafficPoolAccounting
$ledgerOverage = (int) CloudTrafficLedgerEvent::where(
'pool_id', $poolId
)->where('event_type', 'overage_recorded')->sum('amount_bytes')
+ (int) CloudTrafficUsageSettlementBucket::where(
'pool_id', $poolId
)->where('allocation_kind', 'overage')
->where('state', 'open')->sum('amount_bytes')
- (int) CloudTrafficLedgerEvent::where('pool_id', $poolId)
->where('event_type', 'overage_settled')->sum('amount_bytes');
if ($ledgerOverage !== (int) $pool->overage_bytes) {
@ -1009,6 +1017,7 @@ final class CloudTrafficPoolAccounting
): array
{
$now = time();
self::sealDueUsageBuckets(200, $now);
$limit = max(1, $limit);
$afterInstanceId = max(0, $afterInstanceId);
$rows = CloudInstance::query()
@ -1251,11 +1260,16 @@ final class CloudTrafficPoolAccounting
}
$instanceId = (int) $instance->id;
$sourceId = 'instance:' . $instanceId . ':rx:' . $download
. ':tx:' . $upload;
$lastEventId = null;
$bucketStart = intdiv($observedAt, 3600) * 3600;
$lastEventId = self::sealOpenUsageBucketsLocked(
$pool,
$instanceId,
$bucketStart
);
if ((string) $period->traffic_quota_mode !== 'unlimited') {
$remaining = $delta;
$remainingDownload = $downloadDelta;
$remainingUpload = $uploadDelta;
$entitlements = CloudTrafficEntitlement::where(
'pool_id', (int) $pool->id
)->where('quota_mode', 'finite')
@ -1281,7 +1295,6 @@ final class CloudTrafficPoolAccounting
});
})->orderBy('ends_at')->orderBy('id')
->lockForUpdate()->get();
$ordinal = 0;
foreach ($entitlements as $entitlement) {
if ($remaining <= 0) {
break;
@ -1300,51 +1313,55 @@ final class CloudTrafficPoolAccounting
$entitlement->version = (int) $entitlement->version + 1;
$entitlement->updated_at = $applyAt;
$entitlement->save();
$event = self::appendEventLocked($pool, [
'event_key' => $sourceId . ':allocation:'
. (int) $entitlement->id,
'event_type' => 'usage_allocated',
'source_type' => 'traffic_observation',
'source_id' => $sourceId,
'source_revision' => 1,
'instance_id' => $instanceId,
'service_period_id' =>
(int) $entitlement->service_period_id,
'entitlement_id' => (int) $entitlement->id,
'amount_bytes' => $take,
'effective_at' => $observedAt,
'observed_at' => $observedAt,
'payload' => [
'download_delta_bytes' => $downloadDelta,
'upload_delta_bytes' => $uploadDelta,
'ordinal' => $ordinal,
'entitlement_id' => (int) $entitlement->id,
],
]);
$lastEventId = (int) $event->id;
$takeDownload = min($remainingDownload, $take);
$takeUpload = $take - $takeDownload;
$remainingDownload -= $takeDownload;
$remainingUpload -= $takeUpload;
$bucket = self::recordUsageBucketLocked(
$pool,
$instanceId,
(int) $entitlement->service_period_id,
(int) $entitlement->id,
'entitlement',
$bucketStart,
$take,
$takeDownload,
$takeUpload,
$observedAt,
$applyAt
);
if ((string) $entitlement->state === 'exhausted') {
$lastEventId = self::sealUsageBucketLocked(
$pool,
$bucket
);
}
$remaining -= $take;
$ordinal++;
}
if ($remaining > 0) {
$pool->overage_bytes = (int) $pool->overage_bytes + $remaining;
$event = self::appendEventLocked($pool, [
'event_key' => $sourceId . ':overage',
'event_type' => 'overage_recorded',
'source_type' => 'traffic_observation',
'source_id' => $sourceId,
'source_revision' => 1,
'instance_id' => $instanceId,
'service_period_id' => (int) $period->id,
'entitlement_id' => null,
'amount_bytes' => $remaining,
'effective_at' => $observedAt,
'observed_at' => $observedAt,
'payload' => [
'download_delta_bytes' => $downloadDelta,
'upload_delta_bytes' => $uploadDelta,
],
]);
$lastEventId = (int) $event->id;
$takeDownload = min($remainingDownload, $remaining);
$takeUpload = $remaining - $takeDownload;
$remainingDownload -= $takeDownload;
$remainingUpload -= $takeUpload;
self::recordUsageBucketLocked(
$pool,
$instanceId,
(int) $period->id,
null,
'overage',
$bucketStart,
$remaining,
$takeDownload,
$takeUpload,
$observedAt,
$applyAt
);
}
if ($remainingDownload !== 0 || $remainingUpload !== 0) {
throw new \RuntimeException(
'traffic_settlement_direction_allocation_incomplete'
);
}
}
@ -1364,6 +1381,266 @@ final class CloudTrafficPoolAccounting
return self::resultLocked($pool, true, null);
}
/** Seal a bounded set of completed hourly usage accumulators. */
public static function sealDueUsageBuckets(
int $limit = 200,
?int $now = null
): int {
$now ??= time();
$limit = max(1, min(2000, $limit));
$currentHour = intdiv($now, 3600) * 3600;
$ids = CloudTrafficUsageSettlementBucket::where('state', 'open')
->where('bucket_start', '<', $currentHour)
->orderBy('bucket_start')->orderBy('id')
->limit($limit)->pluck('id')
->map(static fn ($id): int => (int) $id)->all();
$sealed = 0;
foreach ($ids as $id) {
$hint = CloudTrafficUsageSettlementBucket::find($id);
if ($hint === null) {
continue;
}
$connection = $hint->getConnection();
$sealed += $connection->transaction(
static function () use ($id, $currentHour): int {
$hint = CloudTrafficUsageSettlementBucket::find($id);
if ($hint === null || (string) $hint->state !== 'open'
|| (int) $hint->bucket_start >= $currentHour) {
return 0;
}
$pool = CloudTrafficPool::where(
'id', (int) $hint->pool_id
)->lockForUpdate()->first();
if ($pool === null) {
throw new \RuntimeException(
'traffic_settlement_pool_missing'
);
}
$eventId = self::sealOpenUsageBucketsLocked(
$pool,
(int) $hint->instance_id,
$currentHour,
$hint->entitlement_id === null
? null : (int) $hint->entitlement_id,
(string) $hint->allocation_kind,
$id
);
return $eventId === null ? 0 : 1;
},
3
);
}
return $sealed;
}
private static function recordUsageBucketLocked(
CloudTrafficPool $pool,
int $instanceId,
int $servicePeriodId,
?int $entitlementId,
string $kind,
int $bucketStart,
int $amount,
int $download,
int $upload,
int $observedAt,
int $now
): CloudTrafficUsageSettlementBucket {
if (!in_array($kind, ['entitlement', 'overage'], true)
|| $amount < 1 || $download < 0 || $upload < 0
|| $download + $upload !== $amount
|| $bucketStart % 3600 !== 0
|| $observedAt < $bucketStart
|| $observedAt >= $bucketStart + 3600
|| ($kind === 'entitlement' && ($entitlementId ?? 0) < 1)
|| ($kind === 'overage' && $entitlementId !== null)) {
throw new \RuntimeException(
'traffic_settlement_bucket_input_invalid'
);
}
$targetId = $entitlementId ?? 0;
$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);
$bucket = (clone $identity)->where('state', 'open')
->orderByDesc('bucket_revision')->lockForUpdate()->first();
if ($bucket === null) {
// A late counter sample may arrive after the hour was sealed, or
// an attention/overage transition may have sealed the current
// hour early. Preserve the immutable event and start a new
// revision for the remaining delta.
$lastRevision = (int) (clone $identity)
->lockForUpdate()->max('bucket_revision');
$bucket = new CloudTrafficUsageSettlementBucket();
$bucket->pool_id = (int) $pool->id;
$bucket->user_id = (int) $pool->user_id;
$bucket->instance_id = $instanceId;
$bucket->service_period_id = $servicePeriodId;
$bucket->entitlement_id = $entitlementId;
$bucket->allocation_kind = $kind;
$bucket->allocation_target_id = $targetId;
$bucket->bucket_start = $bucketStart;
$bucket->bucket_revision = $lastRevision + 1;
$bucket->amount_bytes = $amount;
$bucket->download_bytes = $download;
$bucket->upload_bytes = $upload;
$bucket->sample_count = 1;
$bucket->first_observed_at = $observedAt;
$bucket->last_observed_at = $observedAt;
$bucket->state = 'open';
$bucket->sealed_event_id = null;
$bucket->created_at = $now;
$bucket->updated_at = $now;
$bucket->save();
return $bucket;
}
if ((string) $bucket->state !== 'open'
|| (int) $bucket->user_id !== (int) $pool->user_id
|| (int) $bucket->service_period_id !== $servicePeriodId
|| (int) ($bucket->entitlement_id ?? 0) !== $targetId) {
throw new \RuntimeException(
'traffic_settlement_bucket_identity_conflict'
);
}
foreach ([
'amount_bytes' => $amount,
'download_bytes' => $download,
'upload_bytes' => $upload,
] as $field => $increment) {
if ($increment > PHP_INT_MAX - (int) $bucket->{$field}) {
throw new \OverflowException(
'traffic_settlement_bucket_overflow'
);
}
$bucket->{$field} = (int) $bucket->{$field} + $increment;
}
$bucket->sample_count = (int) $bucket->sample_count + 1;
$bucket->first_observed_at = min(
(int) $bucket->first_observed_at,
$observedAt
);
$bucket->last_observed_at = max(
(int) $bucket->last_observed_at,
$observedAt
);
$bucket->updated_at = $now;
$bucket->save();
return $bucket;
}
/**
* Seal matching buckets in deterministic lock order.
*
* @return null|int last immutable event ID
*/
private static function sealOpenUsageBucketsLocked(
CloudTrafficPool $pool,
?int $instanceId = null,
?int $beforeBucket = null,
?int $entitlementId = null,
?string $kind = null,
?int $onlyBucketId = null
): ?int {
$query = CloudTrafficUsageSettlementBucket::where(
'pool_id', (int) $pool->id
)->where('state', 'open');
if ($instanceId !== null) {
$query->where('instance_id', $instanceId);
}
if ($beforeBucket !== null) {
$query->where('bucket_start', '<', $beforeBucket);
}
if ($entitlementId !== null) {
$query->where('entitlement_id', $entitlementId);
}
if ($kind !== null) {
$query->where('allocation_kind', $kind);
}
if ($onlyBucketId !== null) {
$query->where('id', $onlyBucketId);
}
$candidateIds = (clone $query)->orderBy('bucket_start')
->orderBy('id')->pluck('id')
->map(static fn ($id): int => (int) $id)->all();
if ($candidateIds === []) {
return null;
}
$entitlementIds = CloudTrafficUsageSettlementBucket::whereIn(
'id', $candidateIds
)->whereNotNull('entitlement_id')->orderBy('entitlement_id')
->pluck('entitlement_id')->map(
static fn ($id): int => (int) $id
)->unique()->values()->all();
if ($entitlementIds !== []) {
CloudTrafficEntitlement::whereIn('id', $entitlementIds)
->orderBy('id')->lockForUpdate()->get();
}
$buckets = CloudTrafficUsageSettlementBucket::whereIn(
'id', $candidateIds
)->where('state', 'open')->orderBy('bucket_start')->orderBy('id')
->lockForUpdate()->get();
$lastEventId = null;
foreach ($buckets as $bucket) {
$lastEventId = self::sealUsageBucketLocked($pool, $bucket);
}
return $lastEventId;
}
private static function sealUsageBucketLocked(
CloudTrafficPool $pool,
CloudTrafficUsageSettlementBucket $bucket
): int {
if ((int) $bucket->pool_id !== (int) $pool->id) {
throw new \RuntimeException(
'traffic_settlement_bucket_pool_conflict'
);
}
if ((string) $bucket->state === 'sealed') {
$eventId = (int) ($bucket->sealed_event_id ?? 0);
if ($eventId < 1) {
throw new \RuntimeException(
'traffic_settlement_sealed_event_missing'
);
}
return $eventId;
}
$eventType = (string) $bucket->allocation_kind === 'entitlement'
? 'usage_allocated' : 'overage_recorded';
$event = self::appendEventLocked($pool, [
'event_key' => 'traffic-settlement-bucket:' . (int) $bucket->id,
'event_type' => $eventType,
'source_type' => 'traffic_settlement',
'source_id' => (string) $bucket->id,
'source_revision' => 1,
'instance_id' => (int) $bucket->instance_id,
'service_period_id' => (int) $bucket->service_period_id,
'entitlement_id' => $bucket->entitlement_id === null
? null : (int) $bucket->entitlement_id,
'amount_bytes' => (int) $bucket->amount_bytes,
'effective_at' => (int) $bucket->bucket_start,
'observed_at' => (int) $bucket->last_observed_at,
'payload' => [
'bucket_start' => (int) $bucket->bucket_start,
'bucket_revision' => (int) $bucket->bucket_revision,
'bucket_seconds' => 3600,
'download_bytes' => (int) $bucket->download_bytes,
'upload_bytes' => (int) $bucket->upload_bytes,
'sample_count' => (int) $bucket->sample_count,
'first_observed_at' => (int) $bucket->first_observed_at,
'last_observed_at' => (int) $bucket->last_observed_at,
],
]);
$bucket->state = 'sealed';
$bucket->sealed_event_id = (int) $event->id;
$bucket->updated_at = time();
$bucket->save();
return (int) $event->id;
}
private static function insertPoolIfMissing(
$connection,
int $userId,
@ -1494,6 +1771,13 @@ final class CloudTrafficPoolAccounting
if ((string) $entitlement->state === 'expired') {
return false;
}
self::sealOpenUsageBucketsLocked(
$pool,
(int) $entitlement->instance_id,
null,
(int) $entitlement->id,
'entitlement'
);
$remaining = self::entitlementRemaining($entitlement);
if ($remaining > 0) {
$entitlement->forfeited_bytes =
@ -1531,6 +1815,13 @@ final class CloudTrafficPoolAccounting
if ($remainingDebt <= 0) {
return false;
}
self::sealOpenUsageBucketsLocked(
$pool,
null,
null,
null,
'overage'
);
$entitlements = CloudTrafficEntitlement::where(
'pool_id', (int) $pool->id
)->where('quota_mode', 'finite')->where('state', 'active')
@ -1741,6 +2032,10 @@ final class CloudTrafficPoolAccounting
string $code,
int $observedAt
): void {
self::sealOpenUsageBucketsLocked(
$pool,
(int) $cursor->instance_id
);
if ((string) $cursor->state === 'attention'
&& (string) $cursor->attention_code === $code) {
if ((string) $pool->state !== 'attention') {

@ -40,6 +40,7 @@ class UserDataDeletionService
['cloud_abuse_alert_events', 'user_id'],
['cloud_abuse_findings', 'user_id'],
['cloud_abuse_instance_states', 'user_id'],
['cloud_traffic_usage_settlement_buckets', 'user_id'],
['cloud_traffic_instance_cursors', 'user_id'],
['cloud_traffic_ledger_events', 'user_id'],
['cloud_traffic_entitlements', 'user_id'],

@ -2311,6 +2311,64 @@ 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 hourly settlement accumulator. Mutable prepaid projections are
-- updated on every observation; only sealed buckets become immutable ledger
-- events, reducing permanent event volume without weakening FEFO accounting.
CREATE TABLE cloud_traffic_usage_settlement_buckets (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
pool_id BIGINT UNSIGNED NOT NULL,
user_id BIGINT UNSIGNED NOT NULL,
instance_id BIGINT UNSIGNED NOT NULL,
service_period_id BIGINT UNSIGNED NOT NULL,
entitlement_id BIGINT UNSIGNED DEFAULT NULL,
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_revision INT UNSIGNED NOT NULL,
amount_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
download_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
upload_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
sample_count INT UNSIGNED NOT NULL DEFAULT 0,
first_observed_at BIGINT UNSIGNED NOT NULL,
last_observed_at BIGINT UNSIGNED NOT NULL,
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
sealed_event_id BIGINT UNSIGNED DEFAULT NULL,
created_at BIGINT UNSIGNED NOT NULL,
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_revision
),
KEY cloud_traffic_settlement_due (state, bucket_start, id),
KEY cloud_traffic_settlement_entitlement (
entitlement_id, state, bucket_start, id
),
KEY cloud_traffic_settlement_owner (user_id, instance_id, id),
KEY cloud_traffic_settlement_event (sealed_event_id),
CONSTRAINT chk_cloud_traffic_settlement_identity CHECK (
(allocation_kind = 'entitlement'
AND entitlement_id IS NOT NULL
AND allocation_target_id = entitlement_id)
OR (allocation_kind = 'overage'
AND entitlement_id IS NULL AND allocation_target_id = 0)
),
CONSTRAINT chk_cloud_traffic_settlement_bucket CHECK (
bucket_start % 3600 = 0
AND bucket_revision > 0
AND first_observed_at >= bucket_start
AND last_observed_at >= first_observed_at
AND last_observed_at < bucket_start + 3600
),
CONSTRAINT chk_cloud_traffic_settlement_amount CHECK (
amount_bytes = download_bytes + upload_bytes
AND amount_bytes > 0 AND sample_count > 0
),
CONSTRAINT chk_cloud_traffic_settlement_state CHECK (
(state = 'open' AND sealed_event_id IS NULL)
OR (state = 'sealed' AND sealed_event_id IS NOT NULL)
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE cloud_traffic_instance_cursors (
instance_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
user_id BIGINT UNSIGNED NOT NULL,

@ -409,7 +409,7 @@ $assert(str_contains(
$assert(str_contains(
$setup,
"SCHEMA_VERSION = 'go-agent-wss-v49-metric-history-rollups'"
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'"
), 'CloudSetup schema version was not advanced for abuse observation.');
foreach (array_keys($mainTables + $logTables) as $table) {

@ -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-v49-metric-history-rollups'")
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& str_contains($service, "->where('active_slot', 1)->lockForUpdate()")
&& str_contains($service, "->where('active_slot', 1)->update")
&& str_contains($service, 'insertGetId'),

@ -258,7 +258,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-v49-metric-history-rollups`')
'`go-agent-wss-v50-traffic-settlement-buckets`')
&& str_contains($deployment,
'`occurrence_generation = 1` 与 `transition_revision = 1`')
&& str_contains($deployment,

@ -64,7 +64,7 @@ foreach ([
'CloudSetup omits backup preparation contract: ' . $required);
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v49-metric-history-rollups'")
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& str_contains($setup,
"'columns' => [\n 'create_request_actor_id',\n 'create_request_idempotency_key',")
&& str_contains($setup, "'non_unique' => 0"),

@ -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-v49-metric-history-rollups'")
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& !str_contains($setup, "SCHEMA_VERSION = 'go-v1'")
&& str_contains($deployment, '`go-agent-wss-v49-metric-history-rollups`')
&& str_contains($compensation, '`go-agent-wss-v49-metric-history-rollups`'),
&& str_contains($deployment, '`go-agent-wss-v50-traffic-settlement-buckets`')
&& str_contains($compensation, '`go-agent-wss-v50-traffic-settlement-buckets`'),
'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'")

@ -56,7 +56,7 @@ foreach ([
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v49-metric-history-rollups'"),
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'"),
'CloudSetup schema version was not advanced for maintenance notices.');
echo "Maintenance notice schema contracts passed.\n";

@ -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-v49-metric-history-rollups'")
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& str_contains($setup,
"'cloud_public_ip_pool_replacement_batches'")
&& str_contains($setup,

@ -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-v49-metric-history-rollups'")
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& str_contains($setup, "'cloud_public_network_transitions'")
&& str_contains($setup, "'cloud_public_network_transition_ips'")
&& str_contains($setup, "'reservation_ip_claim_id'")

@ -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-v49-metric-history-rollups'")
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& str_contains($setup, "'cloud_rescue_artifact_delete_due'")
&& str_contains($setup, "'cloud_rescue_replica_cleanup'"),
'CloudSetup version or rescue catalog indexes are incomplete.');

@ -218,7 +218,7 @@ foreach ([
'CloudSetup omits restore/migration ledger contract: ' . $required);
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v49-metric-history-rollups'")
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& str_contains($attemptModel,
"protected \$table = 'cloud_backup_restore_attempts';")
&& str_contains($attemptModel, "'active_attempt' => 'int'")

@ -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-v49-metric-history-rollups'"),
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'"),
'CloudSetup schema version was not advanced for service compensation.');
$appliedShape = preg_match(

@ -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-v49-metric-history-rollups'"),
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'"),
'CloudSetup schema version was not advanced for durable publications.');
echo "Storage publication schema contracts passed.\n";

@ -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-v49-metric-history-rollups'"),
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'"),
'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}'")

@ -124,6 +124,32 @@ $schema->create('cloud_traffic_ledger_events', static function (Blueprint $table
$table->integer('created_at');
$table->unique(['pool_id', 'pool_sequence']);
});
$schema->create('cloud_traffic_usage_settlement_buckets', static function (Blueprint $table): void {
$table->increments('id');
$table->integer('pool_id');
$table->integer('user_id');
$table->integer('instance_id');
$table->integer('service_period_id');
$table->integer('entitlement_id')->nullable();
$table->string('allocation_kind');
$table->integer('allocation_target_id');
$table->integer('bucket_start');
$table->integer('bucket_revision');
$table->integer('amount_bytes');
$table->integer('download_bytes');
$table->integer('upload_bytes');
$table->integer('sample_count');
$table->integer('first_observed_at');
$table->integer('last_observed_at');
$table->string('state');
$table->integer('sealed_event_id')->nullable();
$table->integer('created_at');
$table->integer('updated_at');
$table->unique([
'pool_id', 'instance_id', 'service_period_id', 'allocation_kind',
'allocation_target_id', 'bucket_start', 'bucket_revision',
], 'traffic_settlement_identity');
});
$schema->create('cloud_traffic_instance_cursors', static function (Blueprint $table): void {
$table->integer('instance_id')->primary();
$table->integer('user_id');
@ -681,12 +707,77 @@ $snapshotInstance->lifetime_download_bytes = 20;
$snapshotInstance->traffic_synced_at = $base + 10;
$snapshotInstance->save();
CloudTrafficPoolAccounting::settleInstanceUsage(56, $base + 5);
$snapshotEvent = CloudTrafficLedgerEvent::where('instance_id', 56)
->where('event_type', 'usage_allocated')->first();
$assert($snapshotEvent !== null
&& (int) $snapshotEvent->observed_at === $base + 10,
$snapshotBucket = Capsule::table('cloud_traffic_usage_settlement_buckets')
->where('instance_id', 56)->where('state', 'open')->first();
$assert($snapshotBucket !== null
&& (int) $snapshotBucket->last_observed_at === $base + 10,
'Counters were paired with a stale observation timestamp.');
$settlementHour = intdiv($base, 3600) * 3600;
$bucketedInstance = $newInstance(72, 22);
$bucketedPeriod = $newPeriod(
$bucketedInstance,
800,
1,
1_000,
$settlementHour,
$base + 7_200
);
CloudTrafficPoolAccounting::reconcileServicePeriod(
800, 'test-bucketed-settlement:initial', $base
);
$bucketedInstance->lifetime_download_bytes = 10;
$bucketedInstance->lifetime_upload_bytes = 5;
$bucketedInstance->traffic_synced_at = $settlementHour + 10;
$bucketedInstance->save();
CloudTrafficPoolAccounting::settleInstanceUsage(72, $base);
$bucketedInstance->lifetime_download_bytes = 25;
$bucketedInstance->lifetime_upload_bytes = 8;
$bucketedInstance->traffic_synced_at = $settlementHour + 20;
$bucketedInstance->save();
CloudTrafficPoolAccounting::settleInstanceUsage(72, $base);
$bucketedPool = CloudTrafficPool::where('user_id', 22)
->where('traffic_pool_group_id', 1)->first();
$openBucket = Capsule::table('cloud_traffic_usage_settlement_buckets')
->where('instance_id', 72)->where('state', 'open')->first();
$assert($openBucket !== null
&& (int) $openBucket->amount_bytes === 33
&& (int) $openBucket->download_bytes === 25
&& (int) $openBucket->upload_bytes === 8
&& (int) $openBucket->sample_count === 2
&& CloudTrafficLedgerEvent::where('instance_id', 72)
->where('event_type', 'usage_allocated')->count() === 0
&& CloudTrafficPoolAccounting::verifyProjection(
(int) $bucketedPool->id
)['valid'] === true,
'Within-hour traffic did not remain a verifiable durable accumulator.');
$sealedBucketCount = CloudTrafficPoolAccounting::sealDueUsageBuckets(
200, $settlementHour + 3600
);
$assert($sealedBucketCount >= 1
&& CloudTrafficPoolAccounting::sealDueUsageBuckets(
200, $settlementHour + 3600
) === 0
&& Capsule::table('cloud_traffic_usage_settlement_buckets')
->where('instance_id', 72)->where('state', 'sealed')->count() === 1
&& CloudTrafficLedgerEvent::where('instance_id', 72)
->where('event_type', 'usage_allocated')->count() === 1,
'Completed settlement buckets were not sealed exactly once.');
$bucketedInstance->lifetime_download_bytes = 30;
$bucketedInstance->lifetime_upload_bytes = 10;
$bucketedInstance->traffic_synced_at = $settlementHour + 30;
$bucketedInstance->save();
CloudTrafficPoolAccounting::settleInstanceUsage(72, $base);
$lateBucket = Capsule::table('cloud_traffic_usage_settlement_buckets')
->where('instance_id', 72)->where('state', 'open')->first();
$assert($lateBucket !== null
&& (int) $lateBucket->bucket_revision === 2
&& (int) $lateBucket->amount_bytes === 7
&& CloudTrafficPoolAccounting::verifyProjection(
(int) $bucketedPool->id
)['valid'] === true,
'A late observation could not create a new immutable bucket revision.');
$scanInstanceA = $newInstance(57, 15);
$scanPeriodA = $newPeriod(
$scanInstanceA, 507, 1, 100, $base, $base + 500

@ -120,6 +120,32 @@ $schema->create('cloud_traffic_ledger_events', static function (Blueprint $table
$table->integer('created_at');
$table->unique(['pool_id', 'pool_sequence']);
});
$schema->create('cloud_traffic_usage_settlement_buckets', static function (Blueprint $table): void {
$table->increments('id');
$table->integer('pool_id');
$table->integer('user_id');
$table->integer('instance_id');
$table->integer('service_period_id');
$table->integer('entitlement_id')->nullable();
$table->string('allocation_kind');
$table->integer('allocation_target_id');
$table->integer('bucket_start');
$table->integer('bucket_revision');
$table->integer('amount_bytes');
$table->integer('download_bytes');
$table->integer('upload_bytes');
$table->integer('sample_count');
$table->integer('first_observed_at');
$table->integer('last_observed_at');
$table->string('state');
$table->integer('sealed_event_id')->nullable();
$table->integer('created_at');
$table->integer('updated_at');
$table->unique([
'pool_id', 'instance_id', 'service_period_id', 'allocation_kind',
'allocation_target_id', 'bucket_start', 'bucket_revision',
], 'traffic_settlement_identity');
});
$schema->create('cloud_traffic_instance_cursors', static function (Blueprint $table): void {
$table->integer('instance_id')->primary();
$table->integer('user_id');

@ -23,6 +23,7 @@ foreach ([
'cloud_traffic_pools',
'cloud_traffic_entitlements',
'cloud_traffic_ledger_events',
'cloud_traffic_usage_settlement_buckets',
'cloud_traffic_instance_cursors',
'cloud_traffic_scan_failures',
'cloud_instance_network_restrictions',
@ -44,6 +45,10 @@ $assert(str_contains($schema,
'UNIQUE KEY cloud_traffic_ledger_event_key (event_key)')
&& str_contains($schema,
'UNIQUE KEY cloud_traffic_ledger_sequence (pool_id, pool_sequence)')
&& str_contains($schema,
'UNIQUE KEY cloud_traffic_settlement_identity (')
&& str_contains($schema,
'allocation_kind, allocation_target_id, bucket_start, bucket_revision')
&& str_contains($schema,
'UNIQUE KEY cloud_traffic_scan_failure_subject (scan_kind, subject_id)'),
'Traffic-pool identity, FEFO or immutable ledger indexes are incomplete.');
@ -71,14 +76,17 @@ $assert(str_contains($schema,
'Service-period traffic-pool identity is not frozen or indexed.');
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v49-metric-history-rollups'")
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& str_contains($setup, "'chk_cloud_traffic_entitlement_balance'")
&& str_contains($setup, "'cloud_traffic_ledger_sequence'"),
&& str_contains($setup, "'cloud_traffic_ledger_sequence'")
&& str_contains($setup, "'chk_cloud_traffic_settlement_state'")
&& str_contains($setup, "'cloud_traffic_settlement_identity'"),
'CloudSetup schema version or named-object validation is incomplete.');
$expectedDeletionOrder = [
"['cloud_instance_network_policy_states', 'user_id']",
"['cloud_instance_network_restrictions', 'user_id']",
"['cloud_traffic_usage_settlement_buckets', 'user_id']",
"['cloud_traffic_instance_cursors', 'user_id']",
"['cloud_traffic_ledger_events', 'user_id']",
"['cloud_traffic_entitlements', 'user_id']",
@ -104,6 +112,7 @@ $assert($deleteParents !== false && $deleteFailures !== false
foreach ([
'CloudTrafficPoolGroup', 'CloudTrafficPool', 'CloudTrafficEntitlement',
'CloudTrafficLedgerEvent', 'CloudTrafficInstanceCursor',
'CloudTrafficUsageSettlementBucket',
'CloudTrafficScanFailure',
'CloudInstanceNetworkRestriction',
'CloudInstanceNetworkPolicyState',

@ -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-v49-metric-history-rollups'")
"private const SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& str_contains($setup, "'name' => 'cloud_vpc_enabled'")
&& str_contains($setup, "'value' => 'false'")
&& str_contains($setup,

@ -195,6 +195,7 @@ $schema->create('cloud_backup_period_entitlements', static function (Blueprint $
$table->increments('id'); $table->integer('user_id');
});
foreach (['cloud_instance_network_restrictions',
'cloud_traffic_usage_settlement_buckets',
'cloud_traffic_instance_cursors', 'cloud_traffic_ledger_events',
'cloud_traffic_entitlements', 'cloud_traffic_pools'] as $tableName) {
$schema->create($tableName, static function (Blueprint $table) {
@ -356,6 +357,7 @@ Capsule::table('cloud_backup_period_entitlements')->insert([
['user_id' => 1], ['user_id' => 3],
]);
foreach (['cloud_instance_network_restrictions',
'cloud_traffic_usage_settlement_buckets',
'cloud_traffic_instance_cursors', 'cloud_traffic_ledger_events',
'cloud_traffic_entitlements', 'cloud_traffic_pools'] as $tableName) {
Capsule::table($tableName)->insert([
@ -454,6 +456,7 @@ foreach (['cloud_instances', 'cloud_orders', 'cloud_instance_snapshots',
'cloud_instance_firewalls', 'cloud_service_periods', 'cloud_renewals',
'cloud_backup_period_entitlements', 'cloud_invoices',
'cloud_invoice_payments', 'cloud_instance_network_restrictions',
'cloud_traffic_usage_settlement_buckets',
'cloud_traffic_instance_cursors', 'cloud_traffic_ledger_events',
'cloud_traffic_entitlements', 'cloud_traffic_pools'] as $tableName) {
$assert(Capsule::table($tableName)->pluck('user_id')->all() === [3],

@ -104,7 +104,7 @@ foreach ($models as $class => $modelTable) {
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v49-metric-history-rollups'")
"SCHEMA_VERSION = 'go-agent-wss-v50-traffic-settlement-buckets'")
&& str_contains($setup,
"self::schema('ss.sql') . \"\\0\" . self::schema('cloud.sql')")
&& str_contains($setup,

Loading…
Cancel
Save