chore(cloud): remove completed v6 upgrade command
parent
2a864e6df8
commit
5d2a8cc063
File diff suppressed because it is too large
Load Diff
@ -1,261 +0,0 @@
|
||||
<?php
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
$command = file_get_contents($root . '/app/Command/CloudMigrateV6.php');
|
||||
$setup = file_get_contents($root . '/app/Command/CloudSetup.php');
|
||||
$xcat = file_get_contents($root . '/app/Command/XCat.php');
|
||||
if (!is_string($command) || !is_string($setup) || !is_string($xcat)) {
|
||||
throw new RuntimeException('Cannot read temporary v6 migration sources.');
|
||||
}
|
||||
|
||||
$assert = static function ($condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$assert(str_contains($xcat, "'cloudMigrateV6' => CloudMigrateV6::run()")
|
||||
&& str_contains($xcat, 'php xcat cloudMigrateV6'),
|
||||
'The one-shot migration is not exposed through xcat.');
|
||||
$assert(str_contains($command,
|
||||
'go-agent-wss-v6-migration-bundles:')
|
||||
&& str_contains($command,
|
||||
'663c6c6da5f8cf4585e00e8764890bb3fee79d917cc9848b27fe1f981612a5ed')
|
||||
&& str_contains($command,
|
||||
'go-agent-wss-v7-automatic-backups:')
|
||||
&& str_contains($command,
|
||||
'2d2c888c7bdce71fb189d75c4fe9fd8b7c7938ffdd2a922325c7e205f2a80dca'),
|
||||
'The migration does not fence the exact v6 and v7 source schemas.');
|
||||
$assert(str_contains($command, "self::oldFingerprint(")
|
||||
&& str_contains($command, 'cloud_schema_migration_v6_fingerprint')
|
||||
&& str_contains($command, 'go-agent-wss-v6-to-v7-in-progress')
|
||||
&& str_contains($command, "->where('value', self::OLD_MARKER)")
|
||||
&& !str_contains($command,
|
||||
"->updateOrInsert(\n ['name' => self::MIGRATION_FINGERPRINT]"),
|
||||
'The migration can run without preserving or checking the v6 fingerprint.');
|
||||
$assert(str_contains($command, 'CloudSetup::v6MigrationSchemaMarker()')
|
||||
&& str_contains($setup,
|
||||
'public static function v6MigrationSchemaMarker(): string')
|
||||
&& str_contains($command,
|
||||
'if (!hash_equals(self::NEW_MARKER, $sourceMarker))'),
|
||||
'The migration can publish a source schema other than the reviewed v7.');
|
||||
$newMarkerAt = strpos($command,
|
||||
'if (hash_equals(self::NEW_MARKER, $marker))');
|
||||
$prepareAt = strpos($command, 'self::prepareMigrationMarker(',
|
||||
$newMarkerAt === false ? 0 : $newMarkerAt);
|
||||
$newMarkerBranch = $newMarkerAt === false || $prepareAt === false
|
||||
? '' : substr($command, $newMarkerAt, $prepareAt - $newMarkerAt);
|
||||
$assert(str_contains($newMarkerBranch,
|
||||
'CloudSetup::assertPublishedV7Migration(')
|
||||
&& !str_contains($newMarkerBranch,
|
||||
'CloudSetup::publishV6Migration(')
|
||||
&& str_contains($setup,
|
||||
'public static function assertPublishedV7Migration(')
|
||||
&& str_contains($setup,
|
||||
'!hash_equals($stored->value, $actual)'),
|
||||
'Re-running the migration can re-publish and bless a drifted v7 schema.');
|
||||
foreach ([
|
||||
'cloud_backup_subscriptions', 'cloud_backup_recoveries',
|
||||
'cloud_order_items', 'cloud_invoice_items',
|
||||
] as $table) {
|
||||
$assert(str_contains($command,
|
||||
"self::createCurrentTable(\$connection, '" . $table . "')"),
|
||||
'The migration is missing the v7 table: ' . $table);
|
||||
}
|
||||
foreach ([
|
||||
'backup_price', 'subscription_id', 'scheduled_for',
|
||||
'cloud_instance_backup_schedule', 'backup_recovery_id',
|
||||
'cloud_job_backup_recovery',
|
||||
] as $object) {
|
||||
$assert(str_contains($command, $object),
|
||||
'The migration is missing the v7 schema object: ' . $object);
|
||||
}
|
||||
$assert(str_contains($command, 'self::assertV7ObjectsAbsent($connection)')
|
||||
&& str_contains($command, 'private const V7_ONLY_TABLES')
|
||||
&& str_contains($command, 'private const V7_ONLY_COLUMNS')
|
||||
&& str_contains($command, 'private const V7_ONLY_INDEXES')
|
||||
&& str_contains($command, '$schema->hasTable($table)')
|
||||
&& str_contains($command, '$schema->hasColumn($table, $column)')
|
||||
&& str_contains($command,
|
||||
'self::indexExists($connection, $table, $index)'),
|
||||
'A clean v6 marker can absorb pre-existing partial v7 objects.');
|
||||
$assert(str_contains($command, 'private const V7_TABLE_SHAPES')
|
||||
&& str_contains($command, 'private const V7_ADDED_COLUMN_SHAPES')
|
||||
&& str_contains($command, 'private const V7_ADDED_INDEX_SHAPES')
|
||||
&& str_contains($command, 'self::assertV7SchemaShape($connection)')
|
||||
&& str_contains($command, 'information_schema.COLUMNS')
|
||||
&& str_contains($command, 'information_schema.STATISTICS')
|
||||
&& str_contains($command, 'information_schema.CHECK_CONSTRAINTS')
|
||||
&& str_contains($command, 'TABLE_COLLATION AS table_collation')
|
||||
&& str_contains($command, "strcasecmp((string) \$row->index_type, 'BTREE')")
|
||||
&& str_contains($command, 'array_keys($shape[\'columns\'])')
|
||||
&& str_contains($command, '$indexes !== $expectedIndexes')
|
||||
&& str_contains($command, '$checks !== $expectedChecks'),
|
||||
'An in-progress migration can publish name-only or malformed v7 objects.');
|
||||
$assert(str_contains($command, "->table('cloud_orders')")
|
||||
&& str_contains($command, "->table('cloud_invoices as invoice')")
|
||||
&& str_contains($command, "'code' => 'instance'")
|
||||
&& str_contains($command, 'assertBillingBackfill($connection)'),
|
||||
'Historical orders and invoices are not backfilled and verified.');
|
||||
$assert(str_contains($command, 'MAX(order_item.id) IS NULL')
|
||||
&& str_contains($command,
|
||||
'MAX(item.order_item_id) <> MAX(order_item.id)')
|
||||
&& !str_contains($command,
|
||||
'invoice.purpose, order_item.id HAVING'),
|
||||
'Invoice validation references an unprojected grouped join column.');
|
||||
$assert(str_contains($command, 'self::backfillOrderSpecs($connection)')
|
||||
&& str_contains($command, "\$spec['instance_price'] = \$amount")
|
||||
&& str_contains($command, "\$spec['automatic_backup'] = false")
|
||||
&& str_contains($command, "\$spec['backup_price'] = '0.00'")
|
||||
&& str_contains($command, "->where('spec_json', \$original)")
|
||||
&& str_contains($command, 'self::assertOrderSpecs($connection)')
|
||||
&& str_contains($command, 'JSON_THROW_ON_ERROR'),
|
||||
'Migrated v6 orders can reach the v7 finalizer without its price split.');
|
||||
$assert(str_contains($command,
|
||||
'CloudSetup::v6MigrationSchemaObjects(')
|
||||
&& str_contains($setup,
|
||||
'public static function v6MigrationSchemaObjects(')
|
||||
&& !str_contains($command,
|
||||
'private static function schemaObjects('),
|
||||
'The migration duplicates the production schema fingerprint query.');
|
||||
$assert(substr_count($command,
|
||||
"`safe_to_resubmit` IS NULL AND `status` IN ('queued','running')")
|
||||
=== 1
|
||||
&& substr_count($command,
|
||||
'`effect_may_have_applied` IS NOT NULL') === 1
|
||||
&& str_contains($command,
|
||||
'COLLATE utf8mb4_unicode_ci')
|
||||
&& str_contains($command,
|
||||
"statusin('queued','running')")
|
||||
&& str_contains($command,
|
||||
"effect_resolution='not_applicable'")
|
||||
&& str_contains($command, 'substr_count($clause, $fragment) !== 1'),
|
||||
'The replacement terminal-shape constraint is duplicated or uncollated.');
|
||||
$publisherStart = strpos($command,
|
||||
'private static function publishMigration(');
|
||||
$publisherEnd = strpos($command,
|
||||
'private static function upgradeSchema(',
|
||||
$publisherStart === false ? 0 : $publisherStart);
|
||||
$publisher = $publisherStart === false || $publisherEnd === false
|
||||
? '' : substr($command, $publisherStart, $publisherEnd - $publisherStart);
|
||||
$fingerprintAt = strpos($publisher,
|
||||
"->where('name', 'cloud_schema_fingerprint')");
|
||||
$versionAt = strpos($publisher,
|
||||
"->where('name', 'cloud_schema_version')",
|
||||
$fingerprintAt === false ? 0 : $fingerprintAt);
|
||||
$assert(!str_contains($setup,
|
||||
'public static function publishV6Migration(')
|
||||
&& str_contains($command,
|
||||
'private static function publishMigration(')
|
||||
&& str_contains($command,
|
||||
"self::configuration(\$connection, 'cloud_schema_version')")
|
||||
&& str_contains($command, 'self::IN_PROGRESS_MARKER')
|
||||
&& str_contains($command, 'self::assertV7SchemaShape($connection);')
|
||||
&& str_contains($command, 'self::assertBillingBackfill($connection);')
|
||||
&& str_contains($command,
|
||||
'CloudSetup::v6MigrationInstalledFingerprint(')
|
||||
&& str_contains($setup,
|
||||
'public static function v6MigrationInstalledFingerprint(')
|
||||
&& str_contains($setup,
|
||||
'self::assertInstalledSchema($connection, $logConnection);')
|
||||
&& str_contains($command, "->where('value', \$original)")
|
||||
&& str_contains($command,
|
||||
"->where('value', self::IN_PROGRESS_MARKER)")
|
||||
&& $fingerprintAt !== false && $versionAt !== false
|
||||
&& $fingerprintAt < $versionAt,
|
||||
'The v7 marker can be published outside the guarded migration state.');
|
||||
|
||||
require_once $root . '/app/Command/CloudMigrateV6.php';
|
||||
$migrationClass = new ReflectionClass(\App\Command\CloudMigrateV6::class);
|
||||
$actualMarker = $migrationClass->getReflectionConstant(
|
||||
'NEW_MARKER'
|
||||
)->getValue();
|
||||
$expectedMarker = 'go-agent-wss-v7-automatic-backups:' . hash(
|
||||
'sha256',
|
||||
file_get_contents($root . '/sql/cloud.sql') . "\0"
|
||||
. file_get_contents($root . '/sql/cloud_log.sql')
|
||||
);
|
||||
$assert(hash_equals($expectedMarker, $actualMarker),
|
||||
'The reviewed v7 marker has drifted from the source schema files.');
|
||||
$tableShapes = $migrationClass->getReflectionConstant(
|
||||
'V7_TABLE_SHAPES'
|
||||
)->getValue();
|
||||
$columnShapes = $migrationClass->getReflectionConstant(
|
||||
'V7_ADDED_COLUMN_SHAPES'
|
||||
)->getValue();
|
||||
$indexShapes = $migrationClass->getReflectionConstant(
|
||||
'V7_ADDED_INDEX_SHAPES'
|
||||
)->getValue();
|
||||
$assert(array_keys($tableShapes) === [
|
||||
'cloud_backup_subscriptions', 'cloud_backup_recoveries',
|
||||
'cloud_order_items', 'cloud_invoice_items',
|
||||
]
|
||||
&& array_keys($columnShapes) === [
|
||||
'cloud_offers', 'cloud_instance_backups', 'cloud_jobs',
|
||||
]
|
||||
&& array_keys($columnShapes['cloud_instance_backups']) === [
|
||||
'source', 'subscription_id', 'scheduled_for',
|
||||
]
|
||||
&& array_keys($indexShapes) === [
|
||||
'cloud_instance_backups', 'cloud_jobs',
|
||||
],
|
||||
'Strict shape validation does not cover every v7 migration object.');
|
||||
$migrateSpec = new ReflectionMethod(
|
||||
\App\Command\CloudMigrateV6::class,
|
||||
'migrateOrderSpec'
|
||||
);
|
||||
$legacySpec = json_encode([
|
||||
'renewal_price' => '8.25',
|
||||
'validity_days' => 30,
|
||||
'traffic_quota_bytes' => 1073741824,
|
||||
'custom_snapshot' => ['keep' => true],
|
||||
], JSON_THROW_ON_ERROR);
|
||||
$migratedRaw = $migrateSpec->invoke(null, $legacySpec, '9.99', 73);
|
||||
$migrated = json_decode($migratedRaw, true, flags: JSON_THROW_ON_ERROR);
|
||||
$assert(($migrated['renewal_price'] ?? null) === '8.25'
|
||||
&& ($migrated['validity_days'] ?? null) === 30
|
||||
&& ($migrated['traffic_quota_bytes'] ?? null) === 1073741824
|
||||
&& ($migrated['custom_snapshot']['keep'] ?? null) === true
|
||||
&& ($migrated['instance_price'] ?? null) === '9.99'
|
||||
&& ($migrated['automatic_backup'] ?? null) === false
|
||||
&& ($migrated['backup_price'] ?? null) === '0.00',
|
||||
'The v6 order snapshot migration loses old fields or has wrong prices.');
|
||||
$assert($migrateSpec->invoke(null, $migratedRaw, '9.99', 73)
|
||||
=== $migratedRaw,
|
||||
'The v6 order snapshot migration is not idempotent.');
|
||||
$invalidRejected = false;
|
||||
try {
|
||||
$migrateSpec->invoke(null, '{invalid-json', '9.99', 74);
|
||||
} catch (RuntimeException $exception) {
|
||||
$invalidRejected = str_contains($exception->getMessage(), '#74');
|
||||
}
|
||||
$assert($invalidRejected,
|
||||
'The migration accepts an invalid historical order snapshot.');
|
||||
|
||||
foreach ([
|
||||
75 => '[]',
|
||||
76 => '[{"renewal_price":"8.25","validity_days":30,'
|
||||
. '"traffic_quota_bytes":1073741824}]',
|
||||
77 => '{"renewal_price":"8.25","validity_days":30}',
|
||||
78 => '{"renewal_price":"invalid","validity_days":30,'
|
||||
. '"traffic_quota_bytes":1073741824}',
|
||||
79 => '{"renewal_price":"8.25","validity_days":"30",'
|
||||
. '"traffic_quota_bytes":1073741824}',
|
||||
80 => '{"renewal_price":"8.25","validity_days":30,'
|
||||
. '"traffic_quota_bytes":-1}',
|
||||
81 => '{"renewal_price":"8.25","validity_days":30,'
|
||||
. '"traffic_quota_bytes":1125899906842625}',
|
||||
82 => '{"renewal_price":"8.25","validity_days":30,'
|
||||
. '"traffic_quota_bytes":1073741825}',
|
||||
] as $orderId => $invalidSpec) {
|
||||
$rejected = false;
|
||||
try {
|
||||
$migrateSpec->invoke(null, $invalidSpec, '9.99', $orderId);
|
||||
} catch (RuntimeException $exception) {
|
||||
$rejected = str_contains($exception->getMessage(), '#' . $orderId);
|
||||
}
|
||||
$assert($rejected,
|
||||
'The migration accepts malformed billing snapshot #' . $orderId . '.');
|
||||
}
|
||||
|
||||
echo "Temporary v6 -> v7 migration contract passed.\n";
|
||||
Loading…
Reference in New Issue