feat(backup): persist automatic backup deferrals

go
codex 1 week ago
parent 5aba7b149d
commit 12be20151d

@ -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-v39-ui-copy-catalog';
private const SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral';
/** 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',
@ -340,7 +340,8 @@ final class CloudSetup
'id', 'instance_id', 'user_id', 'offer_id', 'enabled',
'renew_next_period', 'frequency', 'weekday', 'retention_count',
'timezone', 'price', 'currency', 'price_version',
'state_revision', 'next_run_at',
'state_revision', 'next_run_at', 'deferred_until',
'defer_reason', 'deferred_at', 'defer_count',
'last_scheduled_at', 'last_backup_id', 'created_at', 'updated_at',
],
'cloud_backup_period_entitlements' => [
@ -764,6 +765,7 @@ final class CloudSetup
'chk_cloud_backup_subscription_frequency',
'chk_cloud_backup_subscription_weekday',
'chk_cloud_backup_subscription_retention',
'chk_cloud_backup_subscription_deferral',
],
'cloud_backup_period_entitlements' => [
'chk_cloud_backup_entitlement_source',

@ -19,6 +19,9 @@ final class CloudBackupSubscription extends Model
'price_version' => 'int',
'state_revision' => 'int',
'next_run_at' => 'int',
'deferred_until' => 'int',
'deferred_at' => 'int',
'defer_count' => 'int',
'last_scheduled_at' => 'int',
'last_backup_id' => 'int',
'created_at' => 'int',

@ -221,6 +221,7 @@ final class CloudAutomaticBackupBillingService
(string) $subscription->frequency,
(int) $subscription->weekday
);
CloudAutomaticBackupService::clearDeferredState($subscription);
$subscription->updated_at = $now;
$subscription->save();
@ -354,6 +355,9 @@ final class CloudAutomaticBackupBillingService
|| (bool) $subscription->renew_next_period) {
$subscription->enabled = false;
$subscription->renew_next_period = false;
CloudAutomaticBackupService::clearDeferredState(
$subscription
);
self::advanceStateRevision($subscription);
$subscription->updated_at = $now;
$subscription->save();
@ -835,6 +839,7 @@ final class CloudAutomaticBackupBillingService
(string) $subscription->frequency,
(int) $subscription->weekday
);
CloudAutomaticBackupService::clearDeferredState($subscription);
$subscription->updated_at = $now;
$subscription->save();
}

@ -19,6 +19,16 @@ final class CloudAutomaticBackupService
CloudInvoiceService::PAYMENT_GRACE_SECONDS;
private const RETRY_SECONDS = 300;
private const MAX_DEFER_COUNT = 4294967295;
private const DEFER_REASONS = [
CloudBackupEligibilityDecision::MIGRATION_ACTIVE,
CloudBackupEligibilityDecision::INSTANCE_MUTATION_ACTIVE,
CloudBackupEligibilityDecision::BACKUP_RESCUE_ACTIVE,
CloudBackupEligibilityDecision::BACKUP_DISK_TRANSITION_ACTIVE,
CloudBackupEligibilityDecision::DOMAIN_JOB_ACTIVE,
CloudBackupEligibilityDecision::READINESS_UNAVAILABLE,
'scheduler_unavailable',
];
public static function activatePurchased(CloudInstance $instance): ?CloudBackupSubscription
{
@ -80,6 +90,7 @@ final class CloudAutomaticBackupService
$subscription->next_run_at = self::nextRunAt(
$now, 'daily', 0
);
self::clearDeferredState($subscription);
$subscription->last_scheduled_at = null;
$subscription->last_backup_id = null;
$subscription->created_at = $subscription->updated_at = $now;
@ -202,6 +213,7 @@ final class CloudAutomaticBackupService
$locked->next_run_at = self::nextRunAt(
$now, $frequency, (int) $weekday
);
self::clearDeferredState($locked);
}
$locked->updated_at = $now;
$locked->save();
@ -283,7 +295,8 @@ final class CloudAutomaticBackupService
$now ??= time();
$ids = CloudBackupSubscription::where('enabled', 1)
->where('next_run_at', '>', 0)
->where('next_run_at', '<=', $now)->orderBy('next_run_at')
->where('next_run_at', '<=', $now)
->where('deferred_until', '<=', $now)->orderBy('next_run_at')
->orderBy('id')->limit($limit)->pluck('id')->all();
$queued = 0;
foreach ($ids as $id) {
@ -295,9 +308,6 @@ final class CloudAutomaticBackupService
if (self::pauseIfInstanceExpired((int) $id, $now)) {
continue;
}
if (self::deferIfMigrationOpen((int) $id, $now)) {
continue;
}
// Creation owns a durable intent before object-storage
// preparation begins. Keep that exact scheduled slot stable
// while the preparation worker reconciles it; moving
@ -306,13 +316,11 @@ final class CloudAutomaticBackupService
if (self::hasPendingCreateIntent((int) $id, $now)) {
continue;
}
CloudBackupSubscription::where('id', (int) $id)
->where('enabled', 1)
->where('next_run_at', '<=', $now)
->update([
'next_run_at' => $now + self::RETRY_SECONDS,
'updated_at' => time(),
]);
self::deferCurrentSlot(
(int) $id,
$now,
'scheduler_unavailable'
);
error_log('cloud automatic backup schedule unavailable: '
. get_class($error));
}
@ -573,6 +581,7 @@ final class CloudAutomaticBackupService
(string) $subscription->frequency,
(int) $subscription->weekday
);
self::clearDeferredState($subscription);
}
$subscription->updated_at = time();
$subscription->save();
@ -582,7 +591,8 @@ final class CloudAutomaticBackupService
{
$subscription = CloudBackupSubscription::find($subscriptionId);
if ($subscription === null || !(bool) $subscription->enabled
|| (int) $subscription->next_run_at > $now) {
|| (int) $subscription->next_run_at > $now
|| (int) $subscription->deferred_until > $now) {
return false;
}
$instance = CloudInstance::find((int) $subscription->instance_id);
@ -596,9 +606,6 @@ final class CloudAutomaticBackupService
|| (int) $instance->user_id !== (int) $subscription->user_id) {
throw new CloudError('实例当前不可创建自动备份', 409);
}
if (self::deferIfMigrationOpen($subscriptionId, $now)) {
return false;
}
$scheduledFor = (int) $subscription->next_run_at;
if (!CloudBackupPeriodEntitlement::where(
'subscription_id', (int) $subscription->id
@ -606,7 +613,8 @@ final class CloudAutomaticBackupService
->where('user_id', (int) $instance->user_id)
->where('starts_at', '<=', $scheduledFor)
->where('ends_at', '>', $scheduledFor)->exists()) {
throw new CloudError('自动备份执行时间不在已付权益周期内', 409);
self::pauseWithoutEntitlement($subscriptionId, $scheduledFor, $now);
return false;
}
$actor = [
'user_id' => (int) $instance->user_id,
@ -617,6 +625,21 @@ final class CloudAutomaticBackupService
'request_idempotency_key' => 'automatic-backup-'
. (int) $subscription->id . '-' . $scheduledFor,
];
if (!self::hasPendingCreateIntent($subscriptionId, $now)) {
$eligibility = (new CloudBackupEligibility())->assess(
$instance,
$actor
);
if (!$eligibility->allowed()) {
self::deferCurrentSlot(
$subscriptionId,
$now,
$eligibility->reasonCode,
$scheduledFor
);
return false;
}
}
$queued = CloudBackupService::createAutomatic(
$instance, $subscription, $actor, $scheduledFor
);
@ -673,6 +696,7 @@ final class CloudAutomaticBackupService
|| (int) $subscription->next_run_at !== 0) {
$subscription->enabled = false;
$subscription->next_run_at = 0;
self::clearDeferredState($subscription);
self::advanceStateRevision($subscription);
$subscription->updated_at = $now;
$subscription->save();
@ -682,14 +706,21 @@ final class CloudAutomaticBackupService
}
/**
* An open maintenance migration is a temporary instance mutation fence,
* not an automatic-backup failure. Serialize with migration start through
* the instance row, then move only the due slot by the bounded retry delay.
* Record one bounded retry without changing the logical schedule slot.
* Locking the instance before the subscription keeps mutation admission
* ordering consistent while preserving the idempotency identity.
*/
private static function deferIfMigrationOpen(
private static function deferCurrentSlot(
int $subscriptionId,
int $now
int $now,
string $reason,
?int $expectedSlot = null
): bool {
if (!in_array($reason, self::DEFER_REASONS, true)) {
throw new \InvalidArgumentException(
'Invalid automatic backup defer reason'
);
}
$probe = CloudBackupSubscription::find($subscriptionId);
if ($probe === null) {
return false;
@ -697,7 +728,9 @@ final class CloudAutomaticBackupService
return $probe->getConnection()->transaction(function () use (
$subscriptionId,
$probe,
$now
$now,
$reason,
$expectedSlot
): bool {
$instance = CloudInstance::where(
'id', (int) $probe->instance_id
@ -710,18 +743,66 @@ final class CloudAutomaticBackupService
|| (int) $subscription->instance_id !== (int) $instance->id
|| (int) $subscription->next_run_at < 1
|| (int) $subscription->next_run_at > $now
|| !CloudInstanceMigrationService::hasOpenMigration(
(int) $instance->id
)) {
|| (int) $subscription->deferred_until > $now
|| ($expectedSlot !== null
&& (int) $subscription->next_run_at !== $expectedSlot)) {
return false;
}
$subscription->next_run_at = $now + self::RETRY_SECONDS;
$count = max(0, (int) $subscription->defer_count);
$subscription->deferred_until = $now + self::RETRY_SECONDS;
$subscription->defer_reason = $reason;
$subscription->deferred_at = $now;
$subscription->defer_count = min(
self::MAX_DEFER_COUNT,
$count + 1
);
$subscription->updated_at = $now;
$subscription->save();
return true;
}, 3);
}
/** A missing paid slot is a parked subscription, never an infinite retry. */
private static function pauseWithoutEntitlement(
int $subscriptionId,
int $scheduledFor,
int $now
): void {
$subscription = CloudBackupSubscription::find($subscriptionId);
if (!$subscription instanceof CloudBackupSubscription) {
return;
}
$subscription->getConnection()->transaction(function () use (
$subscriptionId,
$scheduledFor,
$now
): void {
$locked = CloudBackupSubscription::where(
'id', $subscriptionId
)->lockForUpdate()->first();
if (!$locked instanceof CloudBackupSubscription
|| !(bool) $locked->enabled
|| (int) $locked->next_run_at !== $scheduledFor) {
return;
}
$locked->enabled = false;
$locked->next_run_at = 0;
self::clearDeferredState($locked);
self::advanceStateRevision($locked);
$locked->updated_at = $now;
$locked->save();
}, 3);
}
public static function clearDeferredState(
CloudBackupSubscription $subscription
): void {
$subscription->deferred_until = 0;
$subscription->defer_reason = '';
$subscription->deferred_at = null;
$subscription->defer_count = 0;
}
private static function backupsForInstance(CloudInstance $instance): array
{
$items = [];
@ -815,6 +896,19 @@ final class CloudAutomaticBackupService
'timezone' => self::TIMEZONE,
'run_at' => self::RUN_AT,
'next_run_at' => max(0, (int) $subscription->next_run_at),
'deferred' => (int) $subscription->deferred_until > 0,
'deferred_until' => max(
0,
(int) $subscription->deferred_until
),
'defer_reason' => in_array(
(string) $subscription->defer_reason,
self::DEFER_REASONS,
true
) ? (string) $subscription->defer_reason : '',
'deferred_at' => $subscription->deferred_at === null
? null : max(0, (int) $subscription->deferred_at),
'defer_count' => max(0, (int) $subscription->defer_count),
'last_scheduled_at' => $subscription->last_scheduled_at === null
? null : max(0, (int) $subscription->last_scheduled_at),
'price' => (string) $subscription->price,

@ -1344,16 +1344,24 @@ CREATE TABLE cloud_backup_subscriptions (
price_version INT UNSIGNED NOT NULL,
state_revision INT UNSIGNED NOT NULL DEFAULT 1,
next_run_at BIGINT UNSIGNED NOT NULL,
deferred_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
defer_reason VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
deferred_at BIGINT UNSIGNED DEFAULT NULL,
defer_count INT UNSIGNED NOT NULL DEFAULT 0,
last_scheduled_at BIGINT UNSIGNED DEFAULT NULL,
last_backup_id BIGINT UNSIGNED DEFAULT NULL,
created_at BIGINT UNSIGNED NOT NULL,
updated_at BIGINT UNSIGNED NOT NULL,
UNIQUE KEY cloud_backup_subscription_instance (instance_id),
KEY cloud_backup_subscription_due (enabled, next_run_at, id),
KEY cloud_backup_subscription_due (enabled, next_run_at, deferred_until, id),
KEY cloud_backup_subscription_owner (user_id, id),
CONSTRAINT chk_cloud_backup_subscription_frequency CHECK (frequency IN ('daily','weekly')),
CONSTRAINT chk_cloud_backup_subscription_weekday CHECK (weekday <= 6),
CONSTRAINT chk_cloud_backup_subscription_retention CHECK (retention_count IN (1,2))
CONSTRAINT chk_cloud_backup_subscription_retention CHECK (retention_count IN (1,2)),
CONSTRAINT chk_cloud_backup_subscription_deferral CHECK (
(deferred_until = 0 AND defer_reason = '' AND deferred_at IS NULL AND defer_count = 0)
OR (deferred_until > 0 AND defer_reason <> '' AND deferred_at IS NOT NULL AND defer_count > 0)
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Proof that one service period includes paid automatic backup. Its paid
-- commercial fields are immutable; an audited service compensation may extend

@ -91,6 +91,10 @@ $schema->create('cloud_backup_subscriptions', static function (Blueprint $table)
$table->integer('price_version');
$table->integer('state_revision')->default(1);
$table->integer('next_run_at');
$table->integer('deferred_until')->default(0);
$table->string('defer_reason')->default('');
$table->integer('deferred_at')->nullable();
$table->integer('defer_count')->default(0);
$table->integer('last_scheduled_at')->nullable();
$table->integer('last_backup_id')->nullable();
$table->integer('created_at');

@ -52,6 +52,10 @@ $schema->create('cloud_backup_subscriptions',
$t->unsignedInteger('price_version');
$t->unsignedInteger('state_revision')->default(1);
$t->unsignedBigInteger('next_run_at');
$t->unsignedBigInteger('deferred_until')->default(0);
$t->string('defer_reason')->default('');
$t->unsignedBigInteger('deferred_at')->nullable();
$t->unsignedInteger('defer_count')->default(0);
$t->unsignedBigInteger('last_scheduled_at')->nullable();
$t->unsignedBigInteger('last_backup_id')->nullable();
$t->unsignedBigInteger('created_at');

@ -58,6 +58,10 @@ $schema->create('cloud_backup_subscriptions', static function (Blueprint $table)
$table->integer('retention_count');
$table->string('timezone');
$table->integer('next_run_at');
$table->integer('deferred_until')->default(0);
$table->string('defer_reason')->default('');
$table->integer('deferred_at')->nullable();
$table->integer('defer_count')->default(0);
$table->integer('last_scheduled_at')->nullable();
$table->integer('last_backup_id')->nullable();
$table->integer('created_at');

@ -45,11 +45,24 @@ $schema->create('cloud_backup_subscriptions',
$table->integer('price_version');
$table->integer('state_revision')->default(1);
$table->integer('next_run_at');
$table->integer('deferred_until')->default(0);
$table->string('defer_reason')->default('');
$table->integer('deferred_at')->nullable();
$table->integer('defer_count')->default(0);
$table->integer('last_scheduled_at')->nullable();
$table->integer('last_backup_id')->nullable();
$table->integer('created_at');
$table->integer('updated_at');
});
$schema->create('cloud_backup_period_entitlements',
static function (Blueprint $table): void {
$table->increments('id');
$table->integer('subscription_id');
$table->integer('instance_id');
$table->integer('user_id');
$table->integer('starts_at');
$table->integer('ends_at');
});
$now = time();
$newDue = static function (int $id, string $serviceStatus,
@ -82,11 +95,28 @@ $newDue = static function (int $id, string $serviceStatus,
return $subscription;
};
$deferred = $newDue(10, 'expired_grace', $now + 3600);
$deferred->deferred_until = $now + 300;
$deferred->defer_reason = 'migration_active';
$deferred->deferred_at = $now;
$deferred->defer_count = 1;
$deferred->save();
$grace = $newDue(11, 'expired_grace', $now + 3600);
$expiredBeforeLifecycleTick = $newDue(12, 'active', $now - 1);
$missingEntitlement = $newDue(13, 'active', $now + 3600);
$queued = CloudAutomaticBackupService::scheduleDue(1, $now);
$deferred->refresh();
$grace->refresh();
$assert($queued === 0 && (bool) $deferred->enabled
&& (int) $deferred->next_run_at === $now - 60
&& (int) $deferred->deferred_until === $now + 300
&& !(bool) $grace->enabled,
'A future deferred row starved the next runnable subscription.');
$queued = CloudAutomaticBackupService::scheduleDue(10, $now);
$grace->refresh();
$expiredBeforeLifecycleTick->refresh();
$missingEntitlement->refresh();
$assert($queued === 0
&& !(bool) $grace->enabled
@ -96,7 +126,10 @@ $assert($queued === 0
&& !(bool) $expiredBeforeLifecycleTick->enabled
&& (bool) $expiredBeforeLifecycleTick->renew_next_period
&& (int) $expiredBeforeLifecycleTick->next_run_at === 0
&& (int) $expiredBeforeLifecycleTick->state_revision === 2,
'Expired instances were not parked and would continue retrying every five minutes.');
&& (int) $expiredBeforeLifecycleTick->state_revision === 2
&& !(bool) $missingEntitlement->enabled
&& (int) $missingEntitlement->next_run_at === 0
&& (int) $missingEntitlement->deferred_until === 0,
'Expired or unentitled instances were not parked and would retry forever.');
echo "Automatic backup expiry pause lifecycle tests passed.\n";

@ -60,6 +60,10 @@ namespace {
$table->integer('price_version');
$table->integer('state_revision')->default(1);
$table->integer('next_run_at');
$table->integer('deferred_until')->default(0);
$table->string('defer_reason')->default('');
$table->integer('deferred_at')->nullable();
$table->integer('defer_count')->default(0);
$table->integer('last_scheduled_at')->nullable();
$table->integer('last_backup_id')->nullable();
$table->integer('created_at');

@ -49,6 +49,10 @@ $schema->create('cloud_backup_subscriptions',
$table->integer('price_version');
$table->integer('state_revision')->default(1);
$table->integer('next_run_at');
$table->integer('deferred_until')->default(0);
$table->string('defer_reason')->default('');
$table->integer('deferred_at')->nullable();
$table->integer('defer_count')->default(0);
$table->integer('last_scheduled_at')->nullable();
$table->integer('last_backup_id')->nullable();
$table->integer('created_at');

@ -96,11 +96,36 @@ $schema->create('cloud_backup_subscriptions',
$table->integer('price_version');
$table->integer('state_revision')->default(1);
$table->integer('next_run_at');
$table->integer('deferred_until')->default(0);
$table->string('defer_reason')->default('');
$table->integer('deferred_at')->nullable();
$table->integer('defer_count')->default(0);
$table->integer('last_scheduled_at')->nullable();
$table->integer('last_backup_id')->nullable();
$table->integer('created_at');
$table->integer('updated_at');
});
$schema->create('cloud_instance_backups',
static function (Blueprint $table): void {
$table->increments('id');
$table->integer('subscription_id')->nullable();
$table->integer('scheduled_for')->nullable();
$table->string('source');
$table->string('state');
$table->integer('storage_artifact_id')->nullable();
$table->integer('active_job_id')->nullable();
$table->integer('create_request_actor_id')->nullable();
$table->string('create_request_idempotency_key')->nullable();
});
$schema->create('cloud_backup_period_entitlements',
static function (Blueprint $table): void {
$table->increments('id');
$table->integer('subscription_id');
$table->integer('instance_id');
$table->integer('user_id');
$table->integer('starts_at');
$table->integer('ends_at');
});
$now = time();
$instance = new CloudInstance();
@ -175,6 +200,13 @@ $subscription->price_version = 1;
$subscription->next_run_at = $now - 60;
$subscription->created_at = $subscription->updated_at = $now - 3600;
$subscription->save();
$capsule->table('cloud_backup_period_entitlements')->insert([
'subscription_id' => (int) $subscription->id,
'instance_id' => (int) $instance->id,
'user_id' => (int) $instance->user_id,
'starts_at' => $now - 3600,
'ends_at' => $now + 3600,
]);
$logPath = tempnam(sys_get_temp_dir(), 'virt-backup-migration-fence-');
$previousLog = ini_set('error_log', $logPath);
@ -190,10 +222,16 @@ try {
}
$check($queued === 0
&& (bool) $subscription->enabled
&& (int) $subscription->next_run_at === $now + 300,
'Automatic backup was not silently deferred for the open migration.');
&& (int) $subscription->next_run_at === $now - 60
&& (int) $subscription->deferred_until === $now + 300
&& (string) $subscription->defer_reason === 'migration_active'
&& (int) $subscription->deferred_at === $now
&& (int) $subscription->defer_count === 1,
'Automatic backup was not silently deferred for the open migration: '
. json_encode($subscription->getAttributes()));
$check(!str_contains($log, 'cloud automatic backup schedule unavailable'),
'Expected migration deferral was recorded as an automatic-backup failure.');
'Expected migration deferral was recorded as an automatic-backup failure: '
. $log);
if ($failures !== []) {
throw new RuntimeException(implode("\n", $failures));

@ -52,7 +52,7 @@ foreach ([
'CloudSetup omits backup preparation contract: ' . $required);
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v39-ui-copy-catalog'")
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'")
&& str_contains($setup,
"'columns' => [\n 'create_request_actor_id',\n 'create_request_idempotency_key',")
&& str_contains($setup, "'non_unique' => 0"),

@ -231,6 +231,10 @@ namespace {
$t->string('price'); $t->string('currency'); $t->unsignedInteger('price_version');
$t->unsignedInteger('state_revision')->default(1);
$t->unsignedBigInteger('next_run_at');
$t->unsignedBigInteger('deferred_until')->default(0);
$t->string('defer_reason')->default('');
$t->unsignedBigInteger('deferred_at')->nullable();
$t->unsignedInteger('defer_count')->default(0);
$t->unsignedBigInteger('last_scheduled_at')->nullable();
$t->unsignedBigInteger('last_backup_id')->nullable();
$t->unsignedBigInteger('created_at'); $t->unsignedBigInteger('updated_at');

@ -213,6 +213,10 @@ namespace {
$table->integer('price_version')->default(1);
$table->integer('state_revision')->default(1);
$table->integer('next_run_at')->default(0);
$table->integer('deferred_until')->default(0);
$table->string('defer_reason')->default('');
$table->integer('deferred_at')->nullable();
$table->integer('defer_count')->default(0);
$table->integer('last_scheduled_at')->nullable();
$table->integer('last_backup_id')->nullable();
$table->integer('created_at')->default(0);

@ -394,7 +394,7 @@ namespace {
$schema->create('cloud_service_periods', function (Blueprint $t) { $t->increments('id'); foreach (['instance_id', 'user_id'] as $v) { $t->integer($v); } foreach (['plan_id', 'order_id', 'renewal_id', 'traffic_pool_group_id', 'download_base_bytes', 'upload_base_bytes', 'activated_at'] as $v) { $t->integer($v)->nullable(); } $t->string('traffic_quota_mode')->default('finite'); foreach (['starts_at', 'ends_at', 'traffic_quota_bytes', 'download_used_bytes', 'upload_used_bytes', 'created_at', 'updated_at'] as $v) { $t->integer($v)->default(0); } $t->string('status'); $t->unique('order_id'); $t->unique('renewal_id'); });
$schema->create('cloud_invoices', function (Blueprint $t) { $t->increments('id'); $t->string('invoice_no')->unique(); $t->string('purpose')->default('renewal'); $t->integer('instance_id')->nullable(); $t->integer('order_id')->nullable()->unique(); $t->integer('user_id'); $t->integer('plan_id')->nullable(); $t->integer('offer_id')->nullable(); $t->integer('renewal_id')->nullable(); $t->integer('renews_expires_at')->nullable(); $t->integer('due_at'); $t->string('amount'); $t->string('currency')->default('USD'); $t->integer('validity_days'); $t->integer('traffic_quota_bytes'); $t->string('status'); $t->string('paid_via')->nullable(); $t->string('payment_reference')->nullable(); $t->integer('paid_at')->nullable(); $t->integer('created_at'); $t->integer('updated_at'); });
$schema->create('cloud_invoice_items', function (Blueprint $t) { $t->increments('id'); $t->integer('invoice_id'); $t->integer('order_item_id')->nullable(); $t->string('code'); $t->string('label'); $t->string('amount'); $t->string('currency')->default('USD'); $t->text('snapshot_json'); $t->integer('created_at'); $t->unique(['invoice_id', 'code']); });
$schema->create('cloud_backup_subscriptions', function (Blueprint $t) { $t->increments('id'); $t->integer('instance_id')->unique(); $t->integer('user_id'); $t->integer('offer_id'); $t->boolean('enabled')->default(true); $t->boolean('renew_next_period')->default(true); $t->string('frequency')->default('daily'); $t->integer('weekday')->default(0); $t->integer('retention_count')->default(2); $t->string('timezone')->default('UTC'); $t->string('price'); $t->string('currency')->default('USD'); $t->integer('price_version'); $t->integer('state_revision')->default(1); $t->integer('next_run_at'); $t->integer('last_scheduled_at')->nullable(); $t->integer('last_backup_id')->nullable(); $t->integer('created_at'); $t->integer('updated_at'); });
$schema->create('cloud_backup_subscriptions', function (Blueprint $t) { $t->increments('id'); $t->integer('instance_id')->unique(); $t->integer('user_id'); $t->integer('offer_id'); $t->boolean('enabled')->default(true); $t->boolean('renew_next_period')->default(true); $t->string('frequency')->default('daily'); $t->integer('weekday')->default(0); $t->integer('retention_count')->default(2); $t->string('timezone')->default('UTC'); $t->string('price'); $t->string('currency')->default('USD'); $t->integer('price_version'); $t->integer('state_revision')->default(1); $t->integer('next_run_at'); $t->integer('deferred_until')->default(0); $t->string('defer_reason')->default(''); $t->integer('deferred_at')->nullable(); $t->integer('defer_count')->default(0); $t->integer('last_scheduled_at')->nullable(); $t->integer('last_backup_id')->nullable(); $t->integer('created_at'); $t->integer('updated_at'); });
$schema->create('cloud_backup_period_entitlements', function (Blueprint $t) { $t->increments('id'); $t->integer('subscription_id'); $t->integer('instance_id'); $t->integer('service_period_id')->unique(); $t->integer('user_id'); $t->integer('offer_id'); $t->integer('invoice_id'); $t->integer('starts_at'); $t->integer('ends_at'); $t->string('amount'); $t->string('full_period_price'); $t->string('currency')->default('USD'); $t->integer('price_version'); $t->string('source'); $t->integer('paid_at'); $t->integer('created_at'); $t->integer('updated_at'); });
$schema->create('cloud_invoice_payments', function (Blueprint $t) { $t->increments('id'); $t->integer('invoice_id'); $t->integer('user_id'); $t->string('provider'); $t->string('provider_order_no'); $t->string('idempotency_key'); $t->string('amount'); $t->string('status'); $t->integer('created_at'); $t->integer('updated_at'); $t->unique(['provider', 'provider_order_no']); $t->unique(['user_id', 'idempotency_key']); });
$schema->create('cloud_mail_outbox', function (Blueprint $t) { $t->increments('id'); $t->integer('invoice_id'); $t->string('kind'); $t->string('status'); $t->integer('attempts'); $t->integer('available_at'); $t->string('lease_token')->nullable(); $t->integer('lease_until'); $t->integer('sent_at')->nullable(); $t->string('last_error'); $t->integer('created_at'); $t->integer('updated_at'); $t->unique(['invoice_id', 'kind']); });

@ -22,14 +22,22 @@ $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-v39-ui-copy-catalog'")
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'")
&& !str_contains($setup, "SCHEMA_VERSION = 'go-v1'"),
'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'")
&& str_contains($schema,
'state_revision INT UNSIGNED NOT NULL DEFAULT 1')
&& str_contains($setup, "'state_revision', 'next_run_at'")
&& str_contains($schema,
'deferred_until BIGINT UNSIGNED NOT NULL DEFAULT 0')
&& str_contains($schema,
"defer_reason VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT ''")
&& str_contains($schema,
'KEY cloud_backup_subscription_due (enabled, next_run_at, deferred_until, id)')
&& str_contains($schema,
'CONSTRAINT chk_cloud_backup_subscription_deferral CHECK (')
&& str_contains($setup, "'state_revision', 'next_run_at', 'deferred_until'")
&& !str_contains($schema, 'America/Los_Angeles'),
'Fresh automatic-backup subscriptions must default to UTC with a state revision.');

@ -56,7 +56,7 @@ foreach ([
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v39-ui-copy-catalog'"),
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'"),
'CloudSetup schema version was not advanced for maintenance notices.');
echo "Maintenance notice schema contracts passed.\n";

@ -215,6 +215,10 @@ namespace {
$table->integer('price_version');
$table->integer('state_revision')->default(1);
$table->integer('next_run_at')->default(0);
$table->integer('deferred_until')->default(0);
$table->string('defer_reason')->default('');
$table->integer('deferred_at')->nullable();
$table->integer('defer_count')->default(0);
$table->integer('last_scheduled_at')->nullable();
$table->integer('last_backup_id')->nullable();
$table->integer('created_at');

@ -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-v39-ui-copy-catalog'")
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'")
&& 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-v39-ui-copy-catalog'")
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'")
&& 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-v39-ui-copy-catalog'")
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'")
&& 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-v39-ui-copy-catalog'")
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'")
&& str_contains($attemptModel,
"protected \$table = 'cloud_backup_restore_attempts';")
&& str_contains($attemptModel, "'active_attempt' => 'int'")

@ -429,6 +429,7 @@ try {
$table->increments('id');
$table->boolean('enabled')->default(false);
$table->integer('next_run_at')->default(0);
$table->integer('deferred_until')->default(0);
$table->integer('retention_count')->default(2);
});
$schema->create('cloud_backup_period_entitlements', static function (

@ -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-v39-ui-copy-catalog'"),
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'"),
'CloudSetup schema version was not advanced for service compensation.');
$appliedShape = preg_match(

@ -137,7 +137,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-v39-ui-copy-catalog'"),
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'"),
'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-v39-ui-copy-catalog'"),
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'"),
'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}'")

@ -71,7 +71,7 @@ $assert(str_contains($schema,
'Service-period traffic-pool identity is not frozen or indexed.');
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v39-ui-copy-catalog'")
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'")
&& str_contains($setup, "'chk_cloud_traffic_entitlement_balance'")
&& str_contains($setup, "'cloud_traffic_ledger_sequence'"),
'CloudSetup schema version or named-object validation is incomplete.');

@ -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-v39-ui-copy-catalog'")
"private const SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'")
&& str_contains($setup, "'name' => 'cloud_vpc_enabled'")
&& str_contains($setup, "'value' => 'false'")
&& str_contains($setup,

@ -104,7 +104,7 @@ foreach ($models as $class => $modelTable) {
}
$assert(str_contains($setup,
"SCHEMA_VERSION = 'go-agent-wss-v39-ui-copy-catalog'")
"SCHEMA_VERSION = 'go-agent-wss-v40-backup-deferral'")
&& str_contains($setup,
"self::schema('ss.sql') . \"\\0\" . self::schema('cloud.sql')")
&& str_contains($setup,

Loading…
Cancel
Save