You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3053 lines
156 KiB
SQL
3053 lines
156 KiB
SQL
-- Fresh-install cloud business tables. PHP is the sole writer of these records.
|
|
|
|
-- Public sales geography is independent from the host Agent profile. A
|
|
-- stable region code is used in URLs and snapshots; the display name may be
|
|
-- changed without changing an existing order's identity.
|
|
CREATE TABLE cloud_regions (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
code VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
country_code CHAR(2) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
status VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'active',
|
|
sort INT NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_region_code (code),
|
|
KEY cloud_region_catalog (status, sort, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A traffic-pool group is the stable commercial identity used to keep quota
|
|
-- isolated even when a line moves between resource pools or physical hosts.
|
|
-- Lines are mapped before pool accounting is enabled; NULL is retained only
|
|
-- as an explicit not-yet-configured state for a clean rollout.
|
|
CREATE TABLE cloud_traffic_pool_groups (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
mode VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'disabled',
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_traffic_pool_group_code (code),
|
|
KEY cloud_traffic_pool_group_mode (mode, id),
|
|
CONSTRAINT chk_cloud_traffic_pool_group_mode CHECK (
|
|
mode IN ('disabled','shadow','enforced')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Lines always exist in the data model. When the feature switch is off, the
|
|
-- panel uses the one default line created for each region and hides the line
|
|
-- choice from ordinary users. This avoids a production schema migration when
|
|
-- differentiated network products are enabled later.
|
|
CREATE TABLE cloud_network_lines (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
region_id BIGINT UNSIGNED NOT NULL,
|
|
traffic_pool_group_id BIGINT UNSIGNED DEFAULT NULL,
|
|
code VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
is_default TINYINT(1) NOT NULL DEFAULT 0,
|
|
status VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'active',
|
|
sort INT NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_network_line_code (region_id, code),
|
|
KEY cloud_network_line_catalog (region_id, status, sort, id),
|
|
KEY cloud_network_line_default (region_id, is_default, id),
|
|
KEY cloud_network_line_traffic_pool_group (traffic_pool_group_id, status, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_resource_pools (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
line_id BIGINT UNSIGNED NOT NULL,
|
|
code VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
status VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'active',
|
|
scheduling_policy VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'balanced',
|
|
sort INT NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_resource_pool_code (line_id, code),
|
|
KEY cloud_resource_pool_catalog (line_id, status, sort, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_hosts (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(80) NOT NULL,
|
|
region VARCHAR(64) NOT NULL DEFAULT '',
|
|
country_code CHAR(2) NOT NULL DEFAULT '',
|
|
enabled TINYINT(1) NOT NULL DEFAULT 0,
|
|
default_network VARCHAR(128) NOT NULL DEFAULT 'bridge:br0',
|
|
created_at BIGINT NOT NULL,
|
|
updated_at BIGINT NOT NULL,
|
|
KEY cloud_host_name (name)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- The panel owns one purpose-bound sealed HMAC secret per physical host. The
|
|
-- numeric host_id is also the Agent identity used by the outbound gateway;
|
|
-- no host Agent address is stored because Agents initiate every connection.
|
|
CREATE TABLE cloud_host_agents (
|
|
host_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
sealed_api_secret LONGTEXT NOT NULL,
|
|
enabled TINYINT(1) NOT NULL DEFAULT 0,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
tested_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_test_status VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_agent_version VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
network_selectors_json LONGTEXT NOT NULL,
|
|
public_network_capabilities_json LONGTEXT NOT NULL,
|
|
portable_restore_contract_json LONGTEXT NOT NULL,
|
|
portable_restore_contract_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_tested_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
KEY cloud_host_agent_enabled (enabled, last_test_status, tested_revision, revision, host_id),
|
|
KEY cloud_host_agent_test (last_test_status, last_tested_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- The panel stores only the requested host-local directories; the Agent owns
|
|
-- validation and registration of the five fixed libvirt pools. This row
|
|
-- points at the latest requested generation; superseded failed generations
|
|
-- remain immutable in cloud_jobs under their original operation IDs.
|
|
CREATE TABLE cloud_host_storage_configurations (
|
|
host_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
managed_directory TEXT NOT NULL,
|
|
template_directory TEXT NOT NULL,
|
|
seed_directory TEXT NOT NULL,
|
|
user_iso_directory TEXT NOT NULL,
|
|
rescue_directory TEXT NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'applying',
|
|
operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
KEY cloud_host_storage_state (state, updated_at, host_id),
|
|
UNIQUE KEY cloud_host_storage_operation (operation_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A physical host may participate in several commercial resource pools in one
|
|
-- physical region. Compute capacity remains host-global; each independently
|
|
-- revisioned relation controls only whether and how its exact pool may place
|
|
-- work onto the host.
|
|
CREATE TABLE cloud_host_resource_pool_memberships (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
resource_pool_id BIGINT UNSIGNED NOT NULL,
|
|
scheduler_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'disabled',
|
|
priority INT NOT NULL DEFAULT 0,
|
|
weight SMALLINT UNSIGNED NOT NULL DEFAULT 100,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_host_pool_membership (host_id, resource_pool_id),
|
|
KEY cloud_pool_membership_scheduler (resource_pool_id, scheduler_state, priority, host_id),
|
|
KEY cloud_host_membership_scheduler (host_id, scheduler_state, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- One attachment references a panel-selected existing host network, such as
|
|
-- bridge:br0 or network:default. The Agent validates the actual host resource.
|
|
-- Several CIDR blocks may share the same attachment. Binding the attachment
|
|
-- to a network line keeps physical egress separate from compute capacity.
|
|
CREATE TABLE cloud_host_network_attachments (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
attachment_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
line_id BIGINT UNSIGNED NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
network_mode VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'selector',
|
|
network_selector VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
vlan_id SMALLINT UNSIGNED DEFAULT NULL,
|
|
routing_table INT UNSIGNED DEFAULT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'active',
|
|
priority INT NOT NULL DEFAULT 0,
|
|
config_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
verified_agent_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
verification_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
|
|
last_verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
verification_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sync_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_host_network_attachment_key (host_id, attachment_key),
|
|
UNIQUE KEY cloud_host_network_selector (host_id, network_selector),
|
|
KEY cloud_host_network_attachment_line (host_id, line_id, state, priority, id),
|
|
KEY cloud_network_attachment_sync (sync_state, updated_at, id),
|
|
KEY cloud_network_attachment_verification (verification_state, host_id, line_id, id),
|
|
CONSTRAINT chk_cloud_network_attachment_state CHECK (
|
|
state IN ('active','draining','disabled')
|
|
),
|
|
CONSTRAINT chk_cloud_network_attachment_verification CHECK (
|
|
verification_state IN ('never','verified','failed','stale')
|
|
),
|
|
CONSTRAINT chk_cloud_network_attachment_config_revision CHECK (
|
|
config_revision >= 1
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A host's existing private underlay remains operator-owned. The panel stores
|
|
-- only the selected address/interface and desired generation; the Agent
|
|
-- verifies the binding and applies tenant VPC routes without configuring the
|
|
-- physical address, bridge or upstream gateway itself.
|
|
CREATE TABLE cloud_host_vpc_transports (
|
|
host_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
transport_address VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
transport_prefix_length TINYINT UNSIGNED NOT NULL,
|
|
transport_interface VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
transport_mode VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'direct_l3',
|
|
mtu SMALLINT UNSIGNED NOT NULL DEFAULT 1500,
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sync_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
|
|
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_host_vpc_transport_operation (last_operation_id),
|
|
KEY cloud_host_vpc_transport_state (sync_state, updated_at, host_id),
|
|
CONSTRAINT chk_cloud_host_vpc_transport_prefix CHECK (
|
|
transport_prefix_length BETWEEN 1 AND 32
|
|
),
|
|
CONSTRAINT chk_cloud_host_vpc_transport_mode CHECK (
|
|
transport_mode = 'direct_l3'
|
|
),
|
|
CONSTRAINT chk_cloud_host_vpc_transport_mtu CHECK (
|
|
mtu BETWEEN 576 AND 9216
|
|
),
|
|
CONSTRAINT chk_cloud_host_vpc_transport_state CHECK (
|
|
sync_state IN ('never','pending','applying','ready','failed','unknown')
|
|
),
|
|
CONSTRAINT chk_cloud_host_vpc_transport_revision CHECK (
|
|
observed_revision <= desired_revision
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Region-scoped IPv4 supernets are the only source of tenant VPC CIDRs. The
|
|
-- application locks one pool row while selecting a free child prefix, so
|
|
-- concurrent VPC creation cannot allocate overlapping networks.
|
|
CREATE TABLE cloud_vpc_cidr_pools (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
pool_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
region_id BIGINT UNSIGNED NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
prefix_length TINYINT UNSIGNED NOT NULL,
|
|
allocation_prefix TINYINT UNSIGNED NOT NULL DEFAULT 24,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'active',
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_vpc_cidr_pool_key (pool_key),
|
|
UNIQUE KEY cloud_vpc_cidr_pool_region (region_id, cidr),
|
|
KEY cloud_vpc_cidr_pool_catalog (region_id, state, id),
|
|
CONSTRAINT chk_cloud_vpc_cidr_pool_prefix CHECK (
|
|
prefix_length BETWEEN 8 AND 28
|
|
AND allocation_prefix BETWEEN prefix_length AND 28
|
|
AND allocation_prefix BETWEEN 16 AND 28
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_cidr_pool_state CHECK (
|
|
state IN ('active','disabled')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Pool CIDRs are globally unique across hosts. Every administrator pool
|
|
-- mutation locks this singleton before host, attachment, pool and address
|
|
-- rows so concurrent cross-host overlap checks cannot both commit.
|
|
CREATE TABLE cloud_public_ip_pool_catalog_mutex (
|
|
id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
updated_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
CONSTRAINT chk_cloud_public_ip_pool_catalog_mutex CHECK (id = 1)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
INSERT IGNORE INTO cloud_public_ip_pool_catalog_mutex
|
|
(id, updated_at) VALUES (1, 0);
|
|
|
|
-- A public pool is an allocation boundary, not a compute resource pool. The
|
|
-- child cloud_public_ips rows remain the authoritative concrete-address
|
|
-- ledger used by payment-time placement and reconciliation.
|
|
CREATE TABLE cloud_public_ip_pools (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
pool_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
network_attachment_id BIGINT UNSIGNED NOT NULL,
|
|
address_family TINYINT UNSIGNED NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
cidr VARCHAR(49) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
gateway VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
gateway_on_link TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
|
guest_prefix_length TINYINT UNSIGNED NOT NULL,
|
|
dns_servers_json TEXT NOT NULL,
|
|
reserved_ips_json TEXT NOT NULL,
|
|
allocation_start VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
allocation_end VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
allocation_cursor VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
max_allocations INT UNSIGNED NOT NULL DEFAULT 0,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'active',
|
|
priority INT NOT NULL DEFAULT 0,
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sync_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_public_ip_pool_key (host_id, pool_key),
|
|
UNIQUE KEY cloud_public_ip_pool_cidr (host_id, address_family, cidr),
|
|
KEY cloud_public_ip_pool_attachment (network_attachment_id, address_family, state, priority, id),
|
|
KEY cloud_public_ip_pool_sync (host_id, sync_state, updated_at, id),
|
|
CONSTRAINT chk_cloud_public_ip_pool_family CHECK (
|
|
address_family IN (4,6)
|
|
),
|
|
CONSTRAINT chk_cloud_public_ip_pool_prefix CHECK (
|
|
(address_family = 4 AND guest_prefix_length BETWEEN 1 AND 30)
|
|
OR (address_family = 6 AND guest_prefix_length BETWEEN 1 AND 120)
|
|
),
|
|
CONSTRAINT chk_cloud_public_ip_pool_gateway CHECK (
|
|
gateway_on_link IN (0,1)
|
|
),
|
|
CONSTRAINT chk_cloud_public_ip_pool_allocation CHECK (
|
|
(address_family = 4
|
|
AND allocation_start IS NULL
|
|
AND allocation_end IS NULL
|
|
AND allocation_cursor IS NULL
|
|
AND max_allocations = 0)
|
|
OR (address_family = 6
|
|
AND allocation_start IS NOT NULL
|
|
AND allocation_end IS NOT NULL
|
|
AND max_allocations >= 1)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Operator limits and safety reserves are authoritative scheduling policy.
|
|
-- Zero configured capacity keeps a new host unschedulable until explicitly
|
|
-- configured; it never means unlimited capacity.
|
|
CREATE TABLE cloud_host_capacity_policies (
|
|
host_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
configured_cpu_cores SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
|
configured_memory_mib BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
configured_disk_gib BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
safety_cpu_cores SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
|
safety_memory_mib BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
safety_disk_gib BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
max_instances INT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- PHP reserves one concrete address before a paid provisioning job is queued.
|
|
-- The host Agent validates the claim on the selected host. An
|
|
-- uncertain operation keeps the address unavailable until reconciliation.
|
|
CREATE TABLE cloud_public_ips (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
public_ip_pool_id BIGINT UNSIGNED DEFAULT NULL,
|
|
address_family TINYINT UNSIGNED NOT NULL,
|
|
address VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
address_binary VARBINARY(16) NOT NULL,
|
|
prefix_length TINYINT UNSIGNED NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'available',
|
|
reservation_id BIGINT UNSIGNED DEFAULT NULL,
|
|
reservation_ip_claim_id BIGINT UNSIGNED DEFAULT NULL,
|
|
instance_id BIGINT UNSIGNED DEFAULT NULL,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_public_ip_address (address_family, address_binary),
|
|
KEY cloud_public_ip_available (host_id, address_family, state, id),
|
|
KEY cloud_public_ip_pool_available (public_ip_pool_id, state, id),
|
|
KEY cloud_public_ip_reservation (reservation_id, address_family, state, id),
|
|
UNIQUE KEY cloud_public_ip_claim (reservation_ip_claim_id),
|
|
KEY cloud_public_ip_instance (instance_id),
|
|
UNIQUE KEY cloud_public_ip_operation (operation_id, address_family),
|
|
CONSTRAINT chk_cloud_public_ip_family CHECK (
|
|
address_family IN (4,6)
|
|
),
|
|
CONSTRAINT chk_cloud_public_ip_prefix CHECK (
|
|
(address_family = 4 AND prefix_length BETWEEN 1 AND 30)
|
|
OR (address_family = 6 AND prefix_length BETWEEN 1 AND 120)
|
|
),
|
|
CONSTRAINT chk_cloud_public_ip_state CHECK (
|
|
state IN (
|
|
'available','disabled','reserved','assigned','changing','uncertain'
|
|
)
|
|
),
|
|
CONSTRAINT chk_cloud_public_ip_owner_shape CHECK (
|
|
(
|
|
state IN ('available','disabled')
|
|
AND reservation_id IS NULL
|
|
AND reservation_ip_claim_id IS NULL
|
|
AND instance_id IS NULL
|
|
AND operation_id IS NULL
|
|
)
|
|
OR (
|
|
state = 'reserved'
|
|
AND reservation_id IS NOT NULL
|
|
AND reservation_ip_claim_id IS NOT NULL
|
|
AND instance_id IS NULL
|
|
AND operation_id IS NOT NULL
|
|
)
|
|
OR (
|
|
state IN ('changing','uncertain')
|
|
AND reservation_id IS NOT NULL
|
|
AND reservation_ip_claim_id IS NOT NULL
|
|
AND operation_id IS NOT NULL
|
|
)
|
|
OR (
|
|
state = 'assigned'
|
|
AND reservation_id IS NOT NULL
|
|
AND reservation_ip_claim_id IS NOT NULL
|
|
AND instance_id IS NOT NULL
|
|
AND operation_id IS NOT NULL
|
|
)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- An administrator public-pool replacement is one durable orchestration
|
|
-- boundary. The source pool remains draining while child network-change
|
|
-- operations run; an unknown child keeps the batch claimed until the
|
|
-- original operation is reconciled. No batch path replays an Agent mutation.
|
|
CREATE TABLE cloud_public_ip_pool_replacement_batches (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
batch_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
source_public_ip_pool_id BIGINT UNSIGNED NOT NULL,
|
|
target_public_ip_pool_id BIGINT UNSIGNED NOT NULL,
|
|
source_initial_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
parent_job_id BIGINT UNSIGNED NOT NULL,
|
|
requested_by_user_id INT NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
active_claim TINYINT UNSIGNED DEFAULT 1,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_public_pool_replacement_key (batch_key),
|
|
UNIQUE KEY cloud_public_pool_replacement_job (parent_job_id),
|
|
UNIQUE KEY cloud_public_pool_replacement_active (
|
|
source_public_ip_pool_id, active_claim
|
|
),
|
|
KEY cloud_public_pool_replacement_host (host_id, state, id),
|
|
KEY cloud_public_pool_replacement_target (
|
|
target_public_ip_pool_id, active_claim, id
|
|
),
|
|
CONSTRAINT chk_cloud_public_pool_replacement_distinct CHECK (
|
|
source_public_ip_pool_id <> target_public_ip_pool_id
|
|
),
|
|
CONSTRAINT chk_cloud_public_pool_replacement_source_initial CHECK (
|
|
source_initial_state IN ('active','draining')
|
|
),
|
|
CONSTRAINT chk_cloud_public_pool_replacement_state CHECK (
|
|
state IN ('running','blocked','succeeded','failed')
|
|
),
|
|
CONSTRAINT chk_cloud_public_pool_replacement_claim CHECK (
|
|
(state IN ('succeeded','failed') AND active_claim IS NULL
|
|
AND terminal_at IS NOT NULL)
|
|
OR (state IN ('running','blocked') AND active_claim = 1
|
|
AND terminal_at IS NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_public_ip_pool_replacement_batch_items (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
batch_id BIGINT UNSIGNED NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
address_family TINYINT UNSIGNED NOT NULL,
|
|
source_reservation_id BIGINT UNSIGNED NOT NULL,
|
|
source_public_ip_id BIGINT UNSIGNED NOT NULL,
|
|
target_public_ip_id BIGINT UNSIGNED NOT NULL,
|
|
source_network_attachment_id BIGINT UNSIGNED NOT NULL,
|
|
target_network_attachment_id BIGINT UNSIGNED NOT NULL,
|
|
child_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_public_pool_replacement_instance (batch_id, instance_id),
|
|
UNIQUE KEY cloud_public_pool_replacement_child (child_job_id),
|
|
UNIQUE KEY cloud_public_pool_replacement_target_ip (
|
|
batch_id, target_public_ip_id
|
|
),
|
|
KEY cloud_public_pool_replacement_item_state (batch_id, state, id),
|
|
CONSTRAINT chk_cloud_public_pool_replacement_item_ip CHECK (
|
|
source_public_ip_id <> target_public_ip_id
|
|
),
|
|
CONSTRAINT chk_cloud_public_pool_replacement_item_family CHECK (
|
|
address_family IN (4,6)
|
|
),
|
|
CONSTRAINT chk_cloud_public_pool_replacement_item_state CHECK (
|
|
(state = 'preparing' AND child_job_id IS NULL)
|
|
OR (state IN ('queued','succeeded','failed','unknown')
|
|
AND child_job_id IS NOT NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A base plan describes resources. An offer places and prices that plan in
|
|
-- one resource pool. Region and line are therefore reached through the pool
|
|
-- without duplicating mutable labels on this row.
|
|
CREATE TABLE cloud_offers (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
plan_id BIGINT UNSIGNED NOT NULL,
|
|
resource_pool_id BIGINT UNSIGNED NOT NULL,
|
|
code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
name VARCHAR(128) NOT NULL,
|
|
price DECIMAL(12,2) NOT NULL DEFAULT 0.00,
|
|
backup_price DECIMAL(12,2) NOT NULL DEFAULT 0.00,
|
|
currency CHAR(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'USD',
|
|
price_version INT UNSIGNED NOT NULL DEFAULT 1,
|
|
revision INT UNSIGNED NOT NULL DEFAULT 1,
|
|
status TINYINT(1) NOT NULL DEFAULT 1,
|
|
stock INT NOT NULL DEFAULT -1,
|
|
sort INT NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_offer_code (code),
|
|
UNIQUE KEY cloud_offer_plan_pool (plan_id, resource_pool_id),
|
|
KEY cloud_offer_catalog (resource_pool_id, status, sort, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Object storage is a panel-owned durability fabric. Backends keep mutable
|
|
-- credentials, while their endpoint/bucket identity is immutable once an
|
|
-- artifact replica exists. Health only influences new placements and reads;
|
|
-- an in-flight multipart operation remains pinned to its original backend.
|
|
CREATE TABLE cloud_storage_backend_catalog_mutex (
|
|
id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
updated_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
CONSTRAINT chk_cloud_storage_backend_catalog_mutex CHECK (id = 1)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_storage_backends (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
backend_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
identity_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
driver VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 's3',
|
|
endpoint VARCHAR(512) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
region VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
bucket VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
prefix VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
path_style TINYINT(1) NOT NULL DEFAULT 0,
|
|
failure_domain VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
sealed_credentials LONGTEXT NOT NULL,
|
|
config_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
tested_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
admin_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'draft',
|
|
health_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'unknown',
|
|
write_priority INT UNSIGNED NOT NULL DEFAULT 100,
|
|
consecutive_failures INT UNSIGNED NOT NULL DEFAULT 0,
|
|
consecutive_successes INT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_error_code VARCHAR(96) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_tested_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_healthy_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
next_probe_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_storage_backend_key (backend_key),
|
|
UNIQUE KEY cloud_storage_backend_identity (identity_sha256),
|
|
KEY cloud_storage_backend_route (admin_state, health_state, write_priority, id),
|
|
KEY cloud_storage_backend_probe (admin_state, next_probe_at, id),
|
|
CONSTRAINT chk_cloud_storage_backend_driver CHECK (driver = 's3'),
|
|
CONSTRAINT chk_cloud_storage_backend_admin_state CHECK (
|
|
admin_state IN ('draft','active','draining','read_only','disabled','retired')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_backend_health_state CHECK (
|
|
health_state IN ('unknown','healthy','degraded','unreachable')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_backend_revision CHECK (
|
|
config_revision > 0 AND tested_revision <= config_revision
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- One logical artifact owns one or two immutable provider objects. The
|
|
-- durability policy is frozen when publishing starts, so later administrator
|
|
-- changes cannot silently weaken an existing template, rescue ISO or backup.
|
|
CREATE TABLE cloud_storage_artifacts (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
artifact_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
kind VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
maximum_size_bytes BIGINT UNSIGNED NOT NULL,
|
|
size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
durability_policy VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
desired_copies TINYINT UNSIGNED NOT NULL DEFAULT 2,
|
|
required_copies TINYINT UNSIGNED NOT NULL DEFAULT 1,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'publishing',
|
|
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_storage_artifact_key (artifact_key),
|
|
KEY cloud_storage_artifact_coverage (state, required_copies, id),
|
|
KEY cloud_storage_artifact_operation (last_operation_id),
|
|
CONSTRAINT chk_cloud_storage_artifact_kind CHECK (
|
|
kind IN ('backup','template','rescue')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_artifact_policy CHECK (
|
|
durability_policy IN ('mirror_async_2','mirror_required_2')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_artifact_copies CHECK (
|
|
desired_copies BETWEEN 1 AND 2
|
|
AND required_copies BETWEEN 1 AND desired_copies
|
|
),
|
|
CONSTRAINT chk_cloud_storage_artifact_identity CHECK (
|
|
maximum_size_bytes > 0
|
|
AND (
|
|
(state = 'publishing' AND size_bytes = 0 AND sha256 = '')
|
|
OR (
|
|
size_bytes BETWEEN 1 AND maximum_size_bytes
|
|
AND sha256 REGEXP '^[a-f0-9]{64}$'
|
|
)
|
|
)
|
|
),
|
|
CONSTRAINT chk_cloud_storage_artifact_state CHECK (
|
|
state IN ('publishing','available','protected','degraded','retiring',
|
|
'delete_attention','deleted')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Provider identity and exact delete evidence live per replica. A replica is
|
|
-- readable only in ready state with a verified size/hash; unknown destructive
|
|
-- outcomes remain visible for reconciliation and are never blindly replayed.
|
|
CREATE TABLE cloud_storage_replicas (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
replica_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
artifact_id BIGINT UNSIGNED NOT NULL,
|
|
backend_id BIGINT UNSIGNED NOT NULL,
|
|
role VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
object_key VARCHAR(512) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
object_version_id VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
object_etag VARCHAR(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'reserved',
|
|
publish_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
delete_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
delete_generation INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_cycle_attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_presence_confirmations INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_last_checked_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_next_check_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_attention_at BIGINT UNSIGNED DEFAULT NULL,
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
error_code VARCHAR(96) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_storage_replica_key (replica_key),
|
|
UNIQUE KEY cloud_storage_replica_backend (artifact_id, backend_id),
|
|
UNIQUE KEY cloud_storage_replica_object (backend_id, object_key),
|
|
KEY cloud_storage_replica_due (state, delete_next_check_at, id),
|
|
KEY cloud_storage_replica_lease (state, lease_until, id),
|
|
KEY cloud_storage_replica_read (artifact_id, state, verified_at, id),
|
|
CONSTRAINT chk_cloud_storage_replica_role CHECK (
|
|
role IN ('primary','secondary')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_replica_state CHECK (
|
|
state IN ('reserved','publishing','copying','ready','degraded',
|
|
'delete_pending','delete_uncertain','delete_attention','deleted')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_replica_ready CHECK (
|
|
state <> 'ready' OR (size_bytes > 0 AND sha256 <> '' AND verified_at > 0)
|
|
),
|
|
CONSTRAINT fk_cloud_storage_replica_artifact FOREIGN KEY (artifact_id)
|
|
REFERENCES cloud_storage_artifacts (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT,
|
|
CONSTRAINT fk_cloud_storage_replica_backend FOREIGN KEY (backend_id)
|
|
REFERENCES cloud_storage_backends (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Storage mutations have their own durable intent. Timeouts, malformed
|
|
-- receipts and unknown provider effects enter reconciliation instead of being
|
|
-- resubmitted under a new operation identifier.
|
|
CREATE TABLE cloud_storage_operations (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
request_idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
request_fingerprint CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
artifact_id BIGINT UNSIGNED NOT NULL,
|
|
replica_id BIGINT UNSIGNED DEFAULT NULL,
|
|
source_backend_id BIGINT UNSIGNED DEFAULT NULL,
|
|
target_backend_id BIGINT UNSIGNED DEFAULT NULL,
|
|
kind VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
phase VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'accepted',
|
|
outcome VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
effect_resolution VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'not_applicable',
|
|
effect_may_have_applied TINYINT(1) DEFAULT NULL,
|
|
safe_to_resubmit TINYINT(1) DEFAULT NULL,
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
available_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
next_check_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
error_code VARCHAR(96) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
result_json LONGTEXT DEFAULT NULL,
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_storage_operation_id (operation_id),
|
|
UNIQUE KEY cloud_storage_operation_request (request_idempotency_key),
|
|
KEY cloud_storage_operation_poll (phase, available_at, id),
|
|
KEY cloud_storage_operation_evidence (phase, next_check_at, id),
|
|
KEY cloud_storage_operation_artifact (artifact_id, id),
|
|
CONSTRAINT chk_cloud_storage_operation_kind CHECK (
|
|
kind IN ('publish','copy','inspect','delete','repair')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_operation_phase CHECK (
|
|
phase IN ('accepted','dispatching','awaiting_receipt','reconciling','terminal')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_operation_outcome CHECK (
|
|
outcome IS NULL OR outcome IN ('succeeded','failed')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_operation_effect CHECK (
|
|
effect_resolution IN ('not_applicable','unknown','applied','not_applied')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_operation_terminal CHECK (
|
|
(phase = 'terminal' AND outcome IS NOT NULL AND terminal_at IS NOT NULL
|
|
AND effect_may_have_applied IS NOT NULL AND safe_to_resubmit IS NOT NULL)
|
|
OR (phase <> 'terminal' AND outcome IS NULL AND terminal_at IS NULL)
|
|
),
|
|
CONSTRAINT fk_cloud_storage_operation_artifact FOREIGN KEY (artifact_id)
|
|
REFERENCES cloud_storage_artifacts (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT,
|
|
CONSTRAINT fk_cloud_storage_operation_replica FOREIGN KEY (replica_id)
|
|
REFERENCES cloud_storage_replicas (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT,
|
|
CONSTRAINT fk_cloud_storage_operation_source_backend FOREIGN KEY (source_backend_id)
|
|
REFERENCES cloud_storage_backends (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT,
|
|
CONSTRAINT fk_cloud_storage_operation_target_backend FOREIGN KEY (target_backend_id)
|
|
REFERENCES cloud_storage_backends (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- PHP owns the global image catalog. generation_token is assigned once and
|
|
-- never changes; revision advances for every mutable metadata/script update.
|
|
CREATE TABLE cloud_templates (
|
|
id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
|
catalog_key VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
version_label VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
is_default TINYINT(1) NOT NULL DEFAULT 0,
|
|
name VARCHAR(64) NOT NULL,
|
|
os_family VARCHAR(32) NOT NULL,
|
|
os_version VARCHAR(32) NOT NULL,
|
|
image_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
startup_script MEDIUMTEXT NOT NULL,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'importing',
|
|
active_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_template_generation (generation_token),
|
|
UNIQUE KEY cloud_template_catalog_version (catalog_key, version_label),
|
|
KEY cloud_template_default (catalog_key, is_default, state),
|
|
KEY cloud_template_catalog (state, os_family, os_version, name)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Every cloud-template import starts with one durable authority record before
|
|
-- object storage or host distribution is contacted. Reusing the same public
|
|
-- idempotency key can only resume this exact intent; it can never allocate a
|
|
-- second template generation or object key.
|
|
CREATE TABLE cloud_template_import_intents (
|
|
id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
|
user_id INT NOT NULL,
|
|
request_idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
request_fingerprint CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_kind VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
name VARCHAR(64) NOT NULL,
|
|
os_family VARCHAR(32) NOT NULL,
|
|
os_version VARCHAR(32) NOT NULL,
|
|
source_filename VARCHAR(255) NOT NULL DEFAULT '',
|
|
source_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
source_last_modified BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
source_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
sealed_source LONGTEXT NOT NULL,
|
|
template_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
catalog_key VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
version_label VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
storage_revision BIGINT UNSIGNED NOT NULL,
|
|
sealed_storage_runtime LONGTEXT NOT NULL,
|
|
object_key VARCHAR(512) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
multipart_upload_id VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
multipart_part_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
multipart_part_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
object_version_id VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
object_etag VARCHAR(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'prepared',
|
|
active_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
error_code VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
expires_at BIGINT UNSIGNED NOT NULL,
|
|
completed_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_template_import_request (user_id, request_idempotency_key),
|
|
UNIQUE KEY cloud_template_import_template (template_id),
|
|
UNIQUE KEY cloud_template_import_generation (generation_token),
|
|
UNIQUE KEY cloud_template_import_object (object_key),
|
|
KEY cloud_template_import_state (state, expires_at, id),
|
|
KEY cloud_template_import_job (active_job_id, id),
|
|
CONSTRAINT chk_cloud_template_import_source CHECK (
|
|
source_kind IN ('upload','remote')
|
|
),
|
|
CONSTRAINT chk_cloud_template_import_state CHECK (
|
|
state IN ('prepared','uploading','fetching','source_verifying',
|
|
'source_ready','distributing','ready','upload_failed','source_failed',
|
|
'source_unknown','distribution_failed','cancel_pending','cancelled')
|
|
),
|
|
CONSTRAINT chk_cloud_template_import_completion CHECK (
|
|
(state IN ('ready','cancelled') AND completed_at IS NOT NULL)
|
|
OR (state NOT IN ('ready','cancelled') AND completed_at IS NULL)
|
|
),
|
|
CONSTRAINT fk_cloud_template_import_user FOREIGN KEY (user_id)
|
|
REFERENCES `user` (id) ON DELETE RESTRICT ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Browser multipart progress is durable server-side evidence. The browser
|
|
-- may report an ETag, but completion will still verify the provider's exact
|
|
-- part ledger before the immutable object is accepted.
|
|
CREATE TABLE cloud_template_import_parts (
|
|
intent_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
part_number INT UNSIGNED NOT NULL,
|
|
size_bytes BIGINT UNSIGNED NOT NULL,
|
|
etag VARCHAR(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
PRIMARY KEY (intent_id, part_number),
|
|
KEY cloud_template_import_part_order (intent_id, part_number, size_bytes),
|
|
CONSTRAINT chk_cloud_template_import_part CHECK (
|
|
part_number > 0 AND size_bytes > 0
|
|
),
|
|
CONSTRAINT fk_cloud_template_import_part_intent FOREIGN KEY (intent_id)
|
|
REFERENCES cloud_template_import_intents (id)
|
|
ON DELETE CASCADE ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Every immutable template generation owns one canonical object-storage
|
|
-- artifact. Host replicas are disposable caches; this frozen runtime keeps
|
|
-- an old generation readable even after the administrator changes the global
|
|
-- object-storage application settings.
|
|
CREATE TABLE cloud_template_artifacts (
|
|
template_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
|
storage_artifact_id BIGINT UNSIGNED DEFAULT NULL,
|
|
storage_revision BIGINT UNSIGNED NOT NULL,
|
|
sealed_storage_runtime LONGTEXT NOT NULL,
|
|
object_key VARCHAR(512) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
object_version_id VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
object_etag VARCHAR(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
size_bytes BIGINT UNSIGNED NOT NULL,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'ready',
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
delete_operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
delete_generation INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_cycle_attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_presence_confirmations INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_last_checked_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_next_check_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_attention_at BIGINT UNSIGNED DEFAULT NULL,
|
|
verified_at BIGINT UNSIGNED NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_template_artifact_object (object_key),
|
|
UNIQUE KEY cloud_template_artifact_storage (storage_artifact_id),
|
|
KEY cloud_template_artifact_state (state, verified_at, template_id),
|
|
KEY cloud_template_artifact_delete_due (state, delete_next_check_at, template_id),
|
|
CONSTRAINT fk_cloud_template_artifact_storage FOREIGN KEY (storage_artifact_id)
|
|
REFERENCES cloud_storage_artifacts (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A PHP catalog entry is usable on a host only after that Agent confirms the
|
|
-- same immutable generation and current revision. Placement joins this ledger
|
|
-- so a host missing the selected image can never receive the create request.
|
|
CREATE TABLE cloud_template_replicas (
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
template_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
revision BIGINT UNSIGNED NOT NULL,
|
|
generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
image_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
observed_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
observed_generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
observed_image_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
observed_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
PRIMARY KEY (host_id, template_id),
|
|
KEY cloud_template_replica_ready (template_id, state, revision, host_id),
|
|
KEY cloud_template_replica_observed (observed_state, last_verified_at, host_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Personal ISO identity and quotas are global PHP policy. Each enabled host
|
|
-- receives the same opaque ID; host-local progress lives in the replica table.
|
|
CREATE TABLE cloud_user_isos (
|
|
id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
name VARCHAR(64) NOT NULL,
|
|
sealed_source_url LONGTEXT NOT NULL,
|
|
size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'importing',
|
|
import_operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
active_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_user_iso_operation (import_operation_id),
|
|
KEY cloud_user_iso_owner (user_id, state, created_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_user_iso_replicas (
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
user_iso_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
PRIMARY KEY (host_id, user_iso_id),
|
|
KEY cloud_user_iso_replica_owner (user_id, state, host_id),
|
|
KEY cloud_user_iso_replica_operation (operation_id, state)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- PHP owns one global immutable rescue ISO generation. The retired row is a
|
|
-- durable tombstone: it prevents the same generation from becoming usable
|
|
-- again while object-storage or offline-host cleanup debt is still present.
|
|
CREATE TABLE cloud_rescue_templates (
|
|
id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
|
name VARCHAR(64) NOT NULL,
|
|
size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'preparing',
|
|
active_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_rescue_template_generation (generation_token),
|
|
KEY cloud_rescue_template_catalog (state, name, created_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- The canonical object is frozen to the object-storage runtime used when it
|
|
-- was published. Deletion state remains after logical retirement so a lost
|
|
-- provider response can be reconciled without reviving the catalog entry.
|
|
CREATE TABLE cloud_rescue_template_artifacts (
|
|
template_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
|
storage_artifact_id BIGINT UNSIGNED DEFAULT NULL,
|
|
storage_revision BIGINT UNSIGNED NOT NULL,
|
|
sealed_storage_runtime LONGTEXT NOT NULL,
|
|
object_key VARCHAR(512) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
object_version_id VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
object_etag VARCHAR(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
size_bytes BIGINT UNSIGNED NOT NULL,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'reserved',
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
delete_operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
delete_generation INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_cycle_attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_presence_confirmations INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_last_checked_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_next_check_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_attention_at BIGINT UNSIGNED DEFAULT NULL,
|
|
verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_rescue_artifact_object (object_key),
|
|
UNIQUE KEY cloud_rescue_artifact_storage (storage_artifact_id),
|
|
KEY cloud_rescue_artifact_state (state, verified_at, template_id),
|
|
KEY cloud_rescue_artifact_delete_due (state, delete_next_check_at, template_id),
|
|
CONSTRAINT fk_cloud_rescue_artifact_storage FOREIGN KEY (storage_artifact_id)
|
|
REFERENCES cloud_storage_artifacts (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Host copies are disposable, but their cleanup rows survive retirement.
|
|
-- Only an active row matching revision, generation, size and SHA is usable.
|
|
CREATE TABLE cloud_rescue_template_replicas (
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
template_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
revision BIGINT UNSIGNED NOT NULL,
|
|
generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
operation_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
observed_state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
observed_generation_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
observed_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
observed_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_verified_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
cleanup_resolved_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
PRIMARY KEY (host_id, template_id),
|
|
KEY cloud_rescue_replica_ready (template_id, state, revision, host_id),
|
|
KEY cloud_rescue_replica_observed (observed_state, last_verified_at, host_id),
|
|
KEY cloud_rescue_replica_cleanup (state, cleanup_resolved_at, host_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_instances (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
uuid CHAR(36) NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
order_id BIGINT UNSIGNED DEFAULT NULL,
|
|
plan_id BIGINT UNSIGNED DEFAULT NULL,
|
|
offer_id BIGINT UNSIGNED DEFAULT NULL,
|
|
resource_pool_id BIGINT UNSIGNED DEFAULT NULL,
|
|
reservation_id BIGINT UNSIGNED DEFAULT NULL,
|
|
current_period_id BIGINT UNSIGNED DEFAULT NULL,
|
|
name VARCHAR(63) NOT NULL,
|
|
status VARCHAR(32) NOT NULL DEFAULT 'active',
|
|
service_status VARCHAR(32) NOT NULL DEFAULT 'exempt',
|
|
network_status VARCHAR(32) NOT NULL DEFAULT 'active',
|
|
expires_at BIGINT UNSIGNED DEFAULT NULL,
|
|
renewal_price DECIMAL(12,2) DEFAULT NULL,
|
|
renewal_days INT UNSIGNED NOT NULL DEFAULT 0,
|
|
renewal_traffic_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
traffic_quota_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
traffic_download_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
traffic_upload_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
lifetime_download_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
lifetime_upload_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
traffic_synced_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
suspended_at BIGINT UNSIGNED DEFAULT NULL,
|
|
network_suspended_at BIGINT UNSIGNED DEFAULT NULL,
|
|
spec_json LONGTEXT NOT NULL,
|
|
sealed_credential LONGTEXT DEFAULT NULL,
|
|
created_at BIGINT NOT NULL,
|
|
updated_at BIGINT NOT NULL,
|
|
UNIQUE KEY uniq_cloud_host_vm (host_id, uuid),
|
|
UNIQUE KEY uniq_cloud_instance_order (order_id),
|
|
UNIQUE KEY uniq_cloud_instance_reservation (reservation_id),
|
|
KEY cloud_instance_owner (user_id, status),
|
|
KEY cloud_instance_placement (resource_pool_id, host_id, status),
|
|
KEY cloud_instance_lifecycle (service_status, expires_at, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- One user-owned L3 VPC belongs to exactly one commercial region. V1 assigns
|
|
-- non-overlapping IPv4 prefixes from a region pool and exposes no cross-region
|
|
-- peering, NAT or L2 broadcast contract.
|
|
CREATE TABLE cloud_vpcs (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
vpc_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
region_id BIGINT UNSIGNED NOT NULL,
|
|
cidr_pool_id BIGINT UNSIGNED NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
prefix_length TINYINT UNSIGNED NOT NULL,
|
|
gateway VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
active_claim TINYINT UNSIGNED DEFAULT 1,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'provisioning',
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
deleted_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_vpc_key (vpc_key),
|
|
UNIQUE KEY cloud_vpc_region_cidr (region_id, cidr, active_claim),
|
|
KEY cloud_vpc_owner (user_id, state, id),
|
|
KEY cloud_vpc_region_state (region_id, state, id),
|
|
KEY cloud_vpc_pool_state (cidr_pool_id, state, id),
|
|
CONSTRAINT chk_cloud_vpc_prefix CHECK (
|
|
prefix_length BETWEEN 16 AND 28
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_active_claim CHECK (
|
|
active_claim IS NULL OR active_claim = 1
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_state CHECK (
|
|
state IN ('provisioning','active','degraded','deleting','deleted')
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_deleted_at CHECK (
|
|
(state = 'deleted' AND active_claim IS NULL AND deleted_at IS NOT NULL)
|
|
OR (state <> 'deleted' AND active_claim = 1 AND deleted_at IS NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- VPC ports retain an immutable allocation audit. active_claim is set to NULL
|
|
-- only after every affected Agent has confirmed removal; MySQL then permits a
|
|
-- later port to reuse the released instance/IP while keeping the old row.
|
|
CREATE TABLE cloud_vpc_ports (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
port_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
migration_host_id BIGINT UNSIGNED DEFAULT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
private_ip VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
mac_address CHAR(17) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
active_claim TINYINT UNSIGNED DEFAULT 1,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'reserved',
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
applied_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
attached_at BIGINT UNSIGNED DEFAULT NULL,
|
|
released_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_vpc_port_key (port_key),
|
|
UNIQUE KEY cloud_vpc_port_ip_claim (vpc_id, private_ip, active_claim),
|
|
UNIQUE KEY cloud_vpc_port_instance_claim (instance_id, active_claim),
|
|
UNIQUE KEY cloud_vpc_port_mac (mac_address),
|
|
UNIQUE KEY cloud_vpc_port_operation (last_operation_id),
|
|
KEY cloud_vpc_port_owner (user_id, state, id),
|
|
KEY cloud_vpc_port_vpc_state (vpc_id, state, id),
|
|
CONSTRAINT chk_cloud_vpc_port_active_claim CHECK (
|
|
active_claim IS NULL OR active_claim = 1
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_port_state CHECK (
|
|
state IN ('reserved','preparing','attached','detaching','migrating',
|
|
'release_pending','released')
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_port_migration CHECK (
|
|
(state = 'migrating' AND migration_host_id IS NOT NULL)
|
|
OR (state <> 'migrating' AND migration_host_id IS NULL)
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_port_release CHECK (
|
|
(state = 'released' AND active_claim IS NULL AND released_at IS NOT NULL)
|
|
OR (state <> 'released' AND active_claim IS NOT NULL
|
|
AND active_claim = 1 AND released_at IS NULL)
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_port_revision CHECK (
|
|
applied_revision <= desired_revision
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Per-host desired/applied generations make one VPC reconciliation observable
|
|
-- without turning individual route commands into panel state. Unknown Agent
|
|
-- effects retain the original operation ID until an inspection converges.
|
|
CREATE TABLE cloud_vpc_host_states (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
applied_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
applied_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
sync_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_success_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_failure_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_vpc_host_identity (vpc_id, host_id),
|
|
UNIQUE KEY cloud_vpc_host_operation (last_operation_id),
|
|
KEY cloud_vpc_host_sync (host_id, sync_state, updated_at, vpc_id),
|
|
CONSTRAINT chk_cloud_vpc_host_state CHECK (
|
|
sync_state IN ('pending','applying','ready','failed','unknown')
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_host_revision CHECK (
|
|
applied_revision <= desired_revision
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A user-visible batch is one durable orchestration boundary. It reserves all
|
|
-- selected ports under one VPC revision, then releases every per-instance
|
|
-- mutation together after the route projection has converged. active_claim
|
|
-- serializes batches per VPC without deleting their audit history.
|
|
CREATE TABLE cloud_vpc_membership_batches (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
batch_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
user_id INT NOT NULL,
|
|
parent_job_id BIGINT UNSIGNED NOT NULL,
|
|
kind VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
desired_revision BIGINT UNSIGNED NOT NULL,
|
|
active_claim TINYINT UNSIGNED DEFAULT 1,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_vpc_membership_batch_key (batch_key),
|
|
UNIQUE KEY cloud_vpc_membership_batch_job (parent_job_id),
|
|
UNIQUE KEY cloud_vpc_membership_batch_active (vpc_id, active_claim),
|
|
KEY cloud_vpc_membership_batch_owner (user_id, id),
|
|
CONSTRAINT chk_cloud_vpc_membership_batch_kind CHECK (
|
|
kind IN ('attach','detach')
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_membership_batch_state CHECK (
|
|
state IN ('routing','ports','cleanup','blocked','succeeded','failed')
|
|
),
|
|
CONSTRAINT chk_cloud_vpc_membership_batch_claim CHECK (
|
|
(state IN ('succeeded','failed') AND active_claim IS NULL
|
|
AND terminal_at IS NOT NULL)
|
|
OR (state NOT IN ('succeeded','failed') AND active_claim = 1
|
|
AND terminal_at IS NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_vpc_membership_batch_items (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
batch_id BIGINT UNSIGNED NOT NULL,
|
|
user_id INT NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
vpc_port_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
child_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_vpc_membership_batch_instance (batch_id, instance_id),
|
|
UNIQUE KEY cloud_vpc_membership_batch_port (batch_id, vpc_port_id),
|
|
UNIQUE KEY cloud_vpc_membership_batch_child (child_job_id),
|
|
KEY cloud_vpc_membership_batch_item_owner (user_id, id),
|
|
KEY cloud_vpc_membership_batch_item_state (batch_id, state, id),
|
|
CONSTRAINT chk_cloud_vpc_membership_batch_item_state CHECK (
|
|
state IN ('waiting_route','queued','succeeded','failed','unknown')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- Desired/applied host-enforced firewall state. The policy row is the current
|
|
-- tenant view, immutable versions retain idempotency/audit evidence, and rules
|
|
-- contain only the typed public DTO (never hypervisor XML or host commands).
|
|
CREATE TABLE cloud_instance_firewalls (
|
|
instance_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
enabled TINYINT(1) NOT NULL DEFAULT 0,
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
applied_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
applied_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
sync_state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'disabled',
|
|
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
last_success_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_failure_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
KEY cloud_instance_firewall_owner (user_id, instance_id),
|
|
KEY cloud_instance_firewall_host (host_id, sync_state, instance_id),
|
|
KEY cloud_instance_firewall_operation (last_operation_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_instance_firewall_versions (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
revision BIGINT UNSIGNED NOT NULL,
|
|
enabled TINYINT(1) NOT NULL DEFAULT 0,
|
|
policy_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
request_hash CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
applied_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_instance_firewall_revision (instance_id, revision),
|
|
UNIQUE KEY cloud_instance_firewall_idempotency (instance_id, idempotency_key),
|
|
KEY cloud_instance_firewall_version_job (job_id),
|
|
KEY cloud_instance_firewall_version_operation (operation_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_instance_firewall_rules (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
version_id BIGINT UNSIGNED NOT NULL,
|
|
sequence SMALLINT UNSIGNED NOT NULL,
|
|
direction VARCHAR(8) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'ingress',
|
|
protocol VARCHAR(8) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_cidr VARCHAR(43) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
port_from SMALLINT UNSIGNED DEFAULT NULL,
|
|
port_to SMALLINT UNSIGNED DEFAULT NULL,
|
|
description VARCHAR(100) NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_instance_firewall_rule_sequence (version_id, sequence),
|
|
KEY cloud_instance_firewall_rule_version (version_id, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- Administrator-owned deny-only test catalog. The single state row provides
|
|
-- optimistic concurrency and a stable revision for provisioning snapshots.
|
|
-- Rules are soft-deleted for audit, but deployed instances never read this
|
|
-- catalog again: their effective policy is sealed into the create job.
|
|
CREATE TABLE cloud_platform_test_policy_state (
|
|
id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
updated_by BIGINT UNSIGNED DEFAULT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL DEFAULT 0
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
INSERT IGNORE INTO cloud_platform_test_policy_state
|
|
(id, revision, updated_by, updated_at) VALUES (1, 0, NULL, 0);
|
|
CREATE TABLE cloud_platform_test_policy_rules (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
rule_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
service VARCHAR(120) NOT NULL,
|
|
protocol VARCHAR(8) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
port_from SMALLINT UNSIGNED NOT NULL,
|
|
port_to SMALLINT UNSIGNED NOT NULL,
|
|
direction VARCHAR(8) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
reason VARCHAR(500) NOT NULL,
|
|
created_by BIGINT UNSIGNED NOT NULL,
|
|
updated_by BIGINT UNSIGNED NOT NULL,
|
|
deleted_by BIGINT UNSIGNED DEFAULT NULL,
|
|
deleted_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_platform_test_policy_rule_key (rule_key),
|
|
KEY cloud_platform_test_policy_active (deleted_at, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- PHP-owned catalog for same-host local recovery points. Only opaque keys and
|
|
-- bounded metadata are stored here; Agent volume names and host paths never
|
|
-- cross into the business database or tenant API.
|
|
CREATE TABLE cloud_instance_snapshots (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
snapshot_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
name VARCHAR(64) NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'creating',
|
|
consistency VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
size_bytes BIGINT UNSIGNED DEFAULT NULL,
|
|
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
ready_at BIGINT UNSIGNED DEFAULT NULL,
|
|
last_restored_at BIGINT UNSIGNED DEFAULT NULL,
|
|
deleted_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_instance_snapshot_key (snapshot_key),
|
|
KEY cloud_instance_snapshot_slots (instance_id, state, id),
|
|
KEY cloud_instance_snapshot_owner (user_id, instance_id, id),
|
|
KEY cloud_instance_snapshot_operation (last_operation_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- One paid automatic-backup entitlement belongs to one billed instance. The
|
|
-- sales offer freezes only the price; scheduling preferences live here so a
|
|
-- user can change them without mutating the commercial plan snapshot.
|
|
CREATE TABLE cloud_backup_subscriptions (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
offer_id BIGINT UNSIGNED NOT NULL,
|
|
enabled TINYINT(1) NOT NULL DEFAULT 1,
|
|
renew_next_period TINYINT(1) NOT NULL DEFAULT 1,
|
|
frequency VARCHAR(8) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'daily',
|
|
weekday TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
|
retention_count TINYINT UNSIGNED NOT NULL DEFAULT 2,
|
|
timezone VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'UTC',
|
|
price DECIMAL(12,2) NOT NULL DEFAULT 0.00,
|
|
currency CHAR(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'USD',
|
|
price_version INT UNSIGNED NOT NULL,
|
|
state_revision INT UNSIGNED NOT NULL DEFAULT 1,
|
|
next_run_at BIGINT UNSIGNED NOT NULL,
|
|
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_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))
|
|
) 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
|
|
-- ends_at together with the parent period. Pausing future backups never
|
|
-- deletes or rewrites the entitlement.
|
|
CREATE TABLE cloud_backup_period_entitlements (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
subscription_id BIGINT UNSIGNED NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
service_period_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
offer_id BIGINT UNSIGNED NOT NULL,
|
|
invoice_id BIGINT UNSIGNED NOT NULL,
|
|
starts_at BIGINT UNSIGNED NOT NULL,
|
|
ends_at BIGINT UNSIGNED NOT NULL,
|
|
amount DECIMAL(12,2) NOT NULL,
|
|
full_period_price DECIMAL(12,2) NOT NULL,
|
|
currency CHAR(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'USD',
|
|
price_version INT UNSIGNED NOT NULL,
|
|
source VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
paid_at BIGINT UNSIGNED NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_backup_entitlement_period (service_period_id),
|
|
KEY cloud_backup_entitlement_subscription (subscription_id, starts_at, ends_at),
|
|
KEY cloud_backup_entitlement_instance (instance_id, starts_at, ends_at),
|
|
KEY cloud_backup_entitlement_owner (user_id, id),
|
|
KEY cloud_backup_entitlement_invoice (invoice_id, id),
|
|
CONSTRAINT chk_cloud_backup_entitlement_source CHECK (
|
|
source IN ('provision','renewal','addon')
|
|
),
|
|
CONSTRAINT chk_cloud_backup_entitlement_window CHECK (starts_at < ends_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- Portable, object-storage-backed VM system-disk backups. The immutable
|
|
-- source/spec and sealed storage target snapshots keep old backups restorable
|
|
-- after the global object-storage configuration changes. Object URLs and
|
|
-- provider credentials never appear in browser responses.
|
|
CREATE TABLE cloud_instance_backups (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
backup_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
storage_artifact_id BIGINT UNSIGNED DEFAULT NULL,
|
|
source_instance_id BIGINT UNSIGNED NOT NULL,
|
|
source_host_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
source_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
purpose VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'portable',
|
|
source VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'manual',
|
|
subscription_id BIGINT UNSIGNED DEFAULT NULL,
|
|
scheduled_for BIGINT UNSIGNED DEFAULT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'creating',
|
|
consistency VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
object_key VARCHAR(512) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
object_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
virtual_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
object_etag VARCHAR(256) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
object_version_id VARCHAR(1024) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
source_portable_restore_contract_json LONGTEXT NOT NULL,
|
|
source_portable_restore_contract_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
spec_json LONGTEXT NOT NULL,
|
|
sealed_storage_runtime LONGTEXT NOT NULL,
|
|
sealed_credential LONGTEXT DEFAULT NULL,
|
|
storage_revision BIGINT UNSIGNED NOT NULL,
|
|
active_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
delete_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
delete_generation INT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_cycle_attempts TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_presence_confirmations TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_requested_at BIGINT UNSIGNED DEFAULT NULL,
|
|
delete_last_checked_at BIGINT UNSIGNED DEFAULT NULL,
|
|
delete_next_check_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
delete_attention_at BIGINT UNSIGNED DEFAULT NULL,
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
ready_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_instance_backup_key (backup_key),
|
|
UNIQUE KEY cloud_instance_backup_storage (storage_artifact_id),
|
|
UNIQUE KEY cloud_instance_backup_object (object_key),
|
|
UNIQUE KEY cloud_instance_backup_schedule (subscription_id, scheduled_for),
|
|
KEY cloud_instance_backup_source (source_instance_id, state, id),
|
|
KEY cloud_instance_backup_owner (user_id, id),
|
|
KEY cloud_instance_backup_operation (last_operation_id),
|
|
KEY cloud_instance_backup_delete_due (state, delete_next_check_at, id),
|
|
CONSTRAINT fk_cloud_instance_backup_storage FOREIGN KEY (storage_artifact_id)
|
|
REFERENCES cloud_storage_artifacts (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A publication binds one storage artifact to one concrete business owner
|
|
-- before the first provider-side effect. It also acts as the durable outbox
|
|
-- that resumes the owner workflow after the required replica coverage exists.
|
|
CREATE TABLE cloud_storage_publications (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
publication_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
artifact_id BIGINT UNSIGNED NOT NULL,
|
|
backup_id BIGINT UNSIGNED DEFAULT NULL,
|
|
template_import_intent_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
rescue_template_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'waiting_primary',
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
available_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_error_code VARCHAR(96) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
coverage_ready_at BIGINT UNSIGNED DEFAULT NULL,
|
|
finalized_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_storage_publication_key (publication_key),
|
|
UNIQUE KEY cloud_storage_publication_artifact (artifact_id),
|
|
UNIQUE KEY cloud_storage_publication_backup (backup_id),
|
|
UNIQUE KEY cloud_storage_publication_template_import (template_import_intent_id),
|
|
UNIQUE KEY cloud_storage_publication_rescue (rescue_template_id),
|
|
KEY cloud_storage_publication_due (state, available_at, id),
|
|
KEY cloud_storage_publication_lease (state, lease_until, id),
|
|
CONSTRAINT chk_cloud_storage_publication_owner CHECK (
|
|
(backup_id IS NOT NULL)
|
|
+ (template_import_intent_id IS NOT NULL)
|
|
+ (rescue_template_id IS NOT NULL) = 1
|
|
),
|
|
CONSTRAINT chk_cloud_storage_publication_state CHECK (
|
|
state IN ('waiting_primary','waiting_protection','ready_to_finalize',
|
|
'finalizing','completed','failed','retired')
|
|
),
|
|
CONSTRAINT chk_cloud_storage_publication_lease CHECK (
|
|
(state = 'finalizing' AND lease_token IS NOT NULL AND lease_until > 0)
|
|
OR (state <> 'finalizing' AND lease_token IS NULL AND lease_until = 0)
|
|
),
|
|
CONSTRAINT chk_cloud_storage_publication_terminal CHECK (
|
|
(state IN ('completed','retired') AND finalized_at IS NOT NULL)
|
|
OR (state NOT IN ('completed','retired') AND finalized_at IS NULL)
|
|
),
|
|
CONSTRAINT chk_cloud_storage_publication_coverage CHECK (
|
|
(state IN ('waiting_primary','waiting_protection')
|
|
AND coverage_ready_at IS NULL)
|
|
OR (state IN ('ready_to_finalize','finalizing','completed','retired')
|
|
AND coverage_ready_at IS NOT NULL)
|
|
OR state = 'failed'
|
|
),
|
|
CONSTRAINT fk_cloud_storage_publication_artifact FOREIGN KEY (artifact_id)
|
|
REFERENCES cloud_storage_artifacts (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT,
|
|
CONSTRAINT fk_cloud_storage_publication_backup FOREIGN KEY (backup_id)
|
|
REFERENCES cloud_instance_backups (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT,
|
|
CONSTRAINT fk_cloud_storage_publication_template_import FOREIGN KEY (template_import_intent_id)
|
|
REFERENCES cloud_template_import_intents (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT,
|
|
CONSTRAINT fk_cloud_storage_publication_rescue FOREIGN KEY (rescue_template_id)
|
|
REFERENCES cloud_rescue_templates (id)
|
|
ON DELETE RESTRICT ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- A user-owned, durable deployment source promoted from one automatic cloud
|
|
-- backup. The backing backup row remains the sole owner of the immutable S3
|
|
-- object in this first schema; user backup rotation and listing must exclude
|
|
-- a backup while an active deployment snapshot references it.
|
|
CREATE TABLE cloud_deployment_snapshots (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
snapshot_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
backup_id BIGINT UNSIGNED NOT NULL,
|
|
source_instance_id BIGINT UNSIGNED NOT NULL,
|
|
name VARCHAR(64) NOT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'ready',
|
|
idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
request_hash CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
ready_at BIGINT UNSIGNED NOT NULL,
|
|
deleted_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_deployment_snapshot_key (snapshot_key),
|
|
UNIQUE KEY cloud_deployment_snapshot_backup (backup_id),
|
|
UNIQUE KEY cloud_deployment_snapshot_request (user_id, idempotency_key),
|
|
KEY cloud_deployment_snapshot_owner (user_id, state, id),
|
|
KEY cloud_deployment_snapshot_source (source_instance_id, state, id),
|
|
CONSTRAINT chk_cloud_deployment_snapshot_state CHECK (
|
|
state IN ('ready','deleting','delete_uncertain','deleted')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- An ordinary restore creates a separate administrator-managed VM and does not
|
|
-- copy billing state. PeerMigration V3 also uses this table only as a hidden
|
|
-- target-placement ledger; in that case backup_id and target_instance_id stay
|
|
-- NULL because no object-storage backup is created.
|
|
CREATE TABLE cloud_backup_restores (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
restore_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
backup_id BIGINT UNSIGNED DEFAULT NULL,
|
|
requested_by_user_id BIGINT UNSIGNED DEFAULT NULL,
|
|
request_idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
request_fingerprint CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
selected_plan_json LONGTEXT DEFAULT NULL,
|
|
selected_plan_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
target_host_id BIGINT UNSIGNED NOT NULL,
|
|
target_instance_id BIGINT UNSIGNED DEFAULT NULL,
|
|
reservation_id BIGINT UNSIGNED DEFAULT NULL,
|
|
job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
new_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
new_name VARCHAR(63) NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'restoring',
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
ready_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_backup_restore_key (restore_key),
|
|
UNIQUE KEY cloud_backup_restore_request (
|
|
requested_by_user_id, request_idempotency_key
|
|
),
|
|
UNIQUE KEY cloud_backup_restore_operation (operation_id),
|
|
UNIQUE KEY cloud_backup_restore_reservation (reservation_id),
|
|
UNIQUE KEY cloud_backup_restore_instance (target_instance_id),
|
|
KEY cloud_backup_restore_backup (backup_id, state, id),
|
|
KEY cloud_backup_restore_host (target_host_id, state, id),
|
|
CONSTRAINT chk_cloud_backup_restore_request CHECK (
|
|
(backup_id IS NULL
|
|
AND requested_by_user_id IS NULL
|
|
AND request_idempotency_key IS NULL
|
|
AND request_fingerprint IS NULL
|
|
AND selected_plan_json IS NULL
|
|
AND selected_plan_sha256 IS NULL)
|
|
OR (backup_id IS NOT NULL
|
|
AND requested_by_user_id IS NOT NULL
|
|
AND requested_by_user_id > 0
|
|
AND request_idempotency_key IS NOT NULL
|
|
AND CHAR_LENGTH(request_idempotency_key) BETWEEN 16 AND 128
|
|
AND request_fingerprint IS NOT NULL
|
|
AND CHAR_LENGTH(request_fingerprint) = 64
|
|
AND selected_plan_json IS NOT NULL
|
|
AND CHAR_LENGTH(selected_plan_json) > 1
|
|
AND selected_plan_sha256 IS NOT NULL
|
|
AND CHAR_LENGTH(selected_plan_sha256) = 64)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- Every independent restore dispatch owns one immutable attempt. A confirmed
|
|
-- not-applied retry creates a new generation and operation instead of
|
|
-- rewriting the historical reservation or claim identity. Unknown effects
|
|
-- remain active and therefore keep the complete dual-stack bundle fenced.
|
|
CREATE TABLE cloud_backup_restore_attempts (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
attempt_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
backup_restore_id BIGINT UNSIGNED NOT NULL,
|
|
generation INT UNSIGNED NOT NULL,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
reservation_id BIGINT UNSIGNED NOT NULL,
|
|
target_host_id BIGINT UNSIGNED NOT NULL,
|
|
target_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
target_name VARCHAR(63) NOT NULL,
|
|
target_plan_json LONGTEXT NOT NULL,
|
|
target_plan_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
target_network_attachment_id BIGINT UNSIGNED NOT NULL,
|
|
target_identity_json LONGTEXT NOT NULL,
|
|
target_identity_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
target_claim_set_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
target_public_network_json LONGTEXT NOT NULL,
|
|
target_public_network_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'reserved',
|
|
effect_resolution VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'not_applicable',
|
|
evidence_resolution VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'not_applicable',
|
|
evidence_json LONGTEXT DEFAULT NULL,
|
|
evidence_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
evidence_recorded_at BIGINT UNSIGNED DEFAULT NULL,
|
|
active_attempt TINYINT UNSIGNED DEFAULT 1,
|
|
last_error_code VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
finalization_error_code VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
effect_resolved_at BIGINT UNSIGNED DEFAULT NULL,
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_backup_restore_attempt_key (attempt_key),
|
|
UNIQUE KEY cloud_backup_restore_attempt_operation (operation_id),
|
|
UNIQUE KEY cloud_backup_restore_attempt_generation (
|
|
backup_restore_id, generation
|
|
),
|
|
UNIQUE KEY cloud_backup_restore_attempt_active (
|
|
backup_restore_id, active_attempt
|
|
),
|
|
UNIQUE KEY cloud_backup_restore_attempt_job (job_id),
|
|
UNIQUE KEY cloud_backup_restore_attempt_reservation (reservation_id),
|
|
KEY cloud_backup_restore_attempt_host (target_host_id, state, id),
|
|
CONSTRAINT chk_cloud_backup_restore_attempt_generation CHECK (
|
|
generation >= 1
|
|
),
|
|
CONSTRAINT chk_cloud_backup_restore_attempt_active CHECK (
|
|
active_attempt IS NULL OR active_attempt = 1
|
|
),
|
|
CONSTRAINT chk_cloud_backup_restore_attempt_evidence CHECK (
|
|
(evidence_resolution = 'not_applicable'
|
|
AND evidence_json IS NULL AND evidence_sha256 IS NULL
|
|
AND evidence_recorded_at IS NULL)
|
|
OR (evidence_resolution IN ('applied','not_applied','unknown')
|
|
AND evidence_json IS NOT NULL AND CHAR_LENGTH(evidence_json) > 1
|
|
AND evidence_sha256 IS NOT NULL
|
|
AND CHAR_LENGTH(evidence_sha256) = 64
|
|
AND evidence_recorded_at IS NOT NULL)
|
|
),
|
|
CONSTRAINT chk_cloud_backup_restore_attempt_plan CHECK (
|
|
CHAR_LENGTH(target_plan_json) > 1
|
|
AND CHAR_LENGTH(target_plan_sha256) = 64
|
|
),
|
|
CONSTRAINT chk_cloud_backup_restore_attempt_state CHECK (
|
|
state IN ('reserved','queued','awaiting_receipt','effect_unknown',
|
|
'finalization_pending','succeeded','failed')
|
|
),
|
|
CONSTRAINT chk_cloud_backup_restore_attempt_shape CHECK (
|
|
(state = 'reserved'
|
|
AND job_id IS NULL
|
|
AND effect_resolution = 'not_applicable'
|
|
AND evidence_resolution = 'not_applicable'
|
|
AND active_attempt IS NOT NULL AND active_attempt = 1
|
|
AND effect_resolved_at IS NULL AND terminal_at IS NULL)
|
|
OR (state IN ('queued','awaiting_receipt')
|
|
AND job_id IS NOT NULL
|
|
AND effect_resolution = 'not_applicable'
|
|
AND evidence_resolution = 'not_applicable'
|
|
AND active_attempt IS NOT NULL AND active_attempt = 1
|
|
AND effect_resolved_at IS NULL AND terminal_at IS NULL)
|
|
OR (state = 'effect_unknown' AND effect_resolution = 'unknown'
|
|
AND evidence_resolution = 'unknown'
|
|
AND job_id IS NOT NULL
|
|
AND active_attempt IS NOT NULL AND active_attempt = 1
|
|
AND effect_resolved_at IS NULL AND terminal_at IS NULL)
|
|
OR (state = 'finalization_pending'
|
|
AND job_id IS NOT NULL
|
|
AND effect_resolution IN ('applied','not_applied')
|
|
AND evidence_resolution = effect_resolution
|
|
AND active_attempt IS NOT NULL AND active_attempt = 1
|
|
AND effect_resolved_at IS NOT NULL AND terminal_at IS NULL)
|
|
OR (state = 'succeeded' AND effect_resolution = 'applied'
|
|
AND evidence_resolution = 'applied'
|
|
AND job_id IS NOT NULL
|
|
AND active_attempt IS NULL
|
|
AND effect_resolved_at IS NOT NULL AND terminal_at IS NOT NULL)
|
|
OR (state = 'failed' AND effect_resolution = 'not_applied'
|
|
AND evidence_resolution = 'not_applied'
|
|
AND job_id IS NOT NULL
|
|
AND active_attempt IS NULL
|
|
AND effect_resolved_at IS NOT NULL AND terminal_at IS NOT NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- Restoring a backup onto its source instance is a destructive disk switch,
|
|
-- distinct from creating an independent restored VM. This ledger fences the
|
|
-- original operation until its exact Agent receipt is reconciled.
|
|
CREATE TABLE cloud_backup_recoveries (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
recovery_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
backup_id BIGINT UNSIGNED NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'recovering',
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
completed_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_backup_recovery_key (recovery_key),
|
|
UNIQUE KEY cloud_backup_recovery_operation (operation_id),
|
|
UNIQUE KEY cloud_backup_recovery_job (job_id),
|
|
KEY cloud_backup_recovery_instance (instance_id, state, id),
|
|
KEY cloud_backup_recovery_backup (backup_id, state, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- PeerMigration V3 keeps the original business instance row and its
|
|
-- billing/traffic periods. The panel coordinates only: source and target Agents
|
|
-- exchange immutable qcow2 artifacts directly over pinned TLS 1.3. The legacy
|
|
-- column names store a JSON endpoint array and the source identity SHA-256.
|
|
CREATE TABLE cloud_instance_migrations (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
migration_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
vpc_port_id BIGINT UNSIGNED DEFAULT NULL,
|
|
restore_id BIGINT UNSIGNED NOT NULL,
|
|
source_host_id BIGINT UNSIGNED NOT NULL,
|
|
source_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_reservation_id BIGINT UNSIGNED NOT NULL,
|
|
target_host_id BIGINT UNSIGNED NOT NULL,
|
|
target_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
target_reservation_id BIGINT UNSIGNED DEFAULT NULL,
|
|
source_prepare_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
target_receive_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
firewall_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
activate_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
rollback_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
cleanup_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
cleanup_mode VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'preparing_source',
|
|
recovery_action VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
retry_generation INT UNSIGNED NOT NULL DEFAULT 0,
|
|
source_endpoint VARCHAR(2048) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
peer_trust_id CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
manifest_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
source_was_running TINYINT(1) DEFAULT NULL,
|
|
source_autostart_enabled TINYINT(1) DEFAULT NULL,
|
|
source_service_status VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_network_status VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
cutover_at BIGINT UNSIGNED DEFAULT NULL,
|
|
completed_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_instance_migration_key (migration_key),
|
|
UNIQUE KEY cloud_instance_migration_restore (restore_id),
|
|
UNIQUE KEY cloud_instance_migration_prepare_job (source_prepare_job_id),
|
|
UNIQUE KEY cloud_instance_migration_receive_job (target_receive_job_id),
|
|
UNIQUE KEY cloud_instance_migration_firewall_job (firewall_job_id),
|
|
UNIQUE KEY cloud_instance_migration_activate_job (activate_job_id),
|
|
UNIQUE KEY cloud_instance_migration_rollback_job (rollback_job_id),
|
|
UNIQUE KEY cloud_instance_migration_cleanup_job (cleanup_job_id),
|
|
KEY cloud_instance_migration_instance (instance_id, state, id),
|
|
KEY cloud_instance_migration_vpc_port (vpc_port_id, state, id),
|
|
KEY cloud_instance_migration_source (source_host_id, source_uuid),
|
|
KEY cloud_instance_migration_target (target_host_id, target_uuid)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- After cutover the stopped source duplicate is not an ordinary restore. Its
|
|
-- exact reservation and dual-stack identity remain a durable cleanup debt
|
|
-- until source deletion is confirmed or rollback restores source authority.
|
|
CREATE TABLE cloud_instance_migration_source_debts (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
debt_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
migration_id BIGINT UNSIGNED NOT NULL,
|
|
source_reservation_id BIGINT UNSIGNED NOT NULL,
|
|
source_host_id BIGINT UNSIGNED NOT NULL,
|
|
source_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_network_attachment_id BIGINT UNSIGNED NOT NULL,
|
|
source_identity_json LONGTEXT NOT NULL,
|
|
source_identity_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_claim_set_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_public_network_json LONGTEXT NOT NULL,
|
|
source_public_network_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
cleanup_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
cleanup_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'prepared',
|
|
active_debt TINYINT UNSIGNED DEFAULT 1,
|
|
last_error_code VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
resolved_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_migration_source_debt_key (debt_key),
|
|
UNIQUE KEY cloud_migration_source_debt_migration (migration_id),
|
|
UNIQUE KEY cloud_migration_source_debt_active_reservation (
|
|
source_reservation_id, active_debt
|
|
),
|
|
UNIQUE KEY cloud_migration_source_debt_cleanup_operation (
|
|
cleanup_operation_id
|
|
),
|
|
UNIQUE KEY cloud_migration_source_debt_cleanup_job (cleanup_job_id),
|
|
KEY cloud_migration_source_debt_host (source_host_id, state, id),
|
|
CONSTRAINT chk_cloud_migration_source_debt_active CHECK (
|
|
active_debt IS NULL OR active_debt = 1
|
|
),
|
|
CONSTRAINT chk_cloud_migration_source_debt_state CHECK (
|
|
state IN ('prepared','retained','cleanup_running','released',
|
|
'rollback_restored','attention')
|
|
),
|
|
CONSTRAINT chk_cloud_migration_source_debt_cleanup_pair CHECK (
|
|
(cleanup_operation_id IS NULL AND cleanup_job_id IS NULL)
|
|
OR (cleanup_operation_id IS NOT NULL AND cleanup_job_id IS NOT NULL)
|
|
),
|
|
CONSTRAINT chk_cloud_migration_source_debt_shape CHECK (
|
|
(state IN ('prepared','retained')
|
|
AND active_debt IS NOT NULL AND active_debt = 1
|
|
AND cleanup_operation_id IS NULL AND cleanup_job_id IS NULL
|
|
AND resolved_at IS NULL)
|
|
OR (state = 'cleanup_running'
|
|
AND active_debt IS NOT NULL AND active_debt = 1
|
|
AND cleanup_operation_id IS NOT NULL AND cleanup_job_id IS NOT NULL
|
|
AND resolved_at IS NULL)
|
|
OR (state = 'attention'
|
|
AND active_debt IS NOT NULL AND active_debt = 1
|
|
AND cleanup_operation_id IS NOT NULL AND cleanup_job_id IS NOT NULL
|
|
AND resolved_at IS NULL)
|
|
OR (state = 'released' AND active_debt IS NULL
|
|
AND cleanup_operation_id IS NOT NULL AND cleanup_job_id IS NOT NULL
|
|
AND resolved_at IS NOT NULL)
|
|
OR (state = 'rollback_restored' AND active_debt IS NULL
|
|
AND cleanup_operation_id IS NULL AND cleanup_job_id IS NULL
|
|
AND resolved_at IS NOT NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- Immutable direct-transfer artifacts that exist only for one PeerMigration V3
|
|
-- session. Host paths and tickets are never stored in this catalog.
|
|
CREATE TABLE cloud_peer_migration_artifacts (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
migration_id BIGINT UNSIGNED NOT NULL,
|
|
artifact_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
role VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_snapshot_id BIGINT UNSIGNED DEFAULT NULL,
|
|
snapshot_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
name VARCHAR(64) NOT NULL DEFAULT '',
|
|
consistency VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
object_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
virtual_size_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'creating',
|
|
snapshot_created_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_peer_migration_artifact (migration_id, artifact_id),
|
|
UNIQUE KEY cloud_peer_migration_snapshot (migration_id, snapshot_key),
|
|
UNIQUE KEY cloud_peer_migration_source_snapshot (migration_id, source_snapshot_id),
|
|
KEY cloud_peer_migration_state (migration_id, state, id),
|
|
CONSTRAINT chk_cloud_peer_migration_artifact_role CHECK (
|
|
(role = 'root' AND source_snapshot_id IS NULL AND snapshot_key IS NULL) OR
|
|
(role = 'snapshot' AND source_snapshot_id IS NOT NULL AND snapshot_key IS NOT NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
-- Last-known Agent power state for fast instance-list first paint. This is
|
|
-- an observation cache only; cloud_instances remains the lifecycle source of
|
|
-- truth and the host Agent remains authoritative for the current power state.
|
|
CREATE TABLE cloud_instance_runtime (
|
|
instance_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
uuid CHAR(36) NOT NULL,
|
|
power_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'unknown',
|
|
sync_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never',
|
|
last_success_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_attempt_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_instance_runtime_identity (host_id, uuid),
|
|
KEY cloud_instance_runtime_sync (sync_state, last_success_at),
|
|
KEY cloud_instance_runtime_host (host_id, updated_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_orders (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
plan_id BIGINT UNSIGNED NOT NULL,
|
|
offer_id BIGINT UNSIGNED DEFAULT NULL,
|
|
resource_pool_id BIGINT UNSIGNED DEFAULT NULL,
|
|
host_id BIGINT UNSIGNED DEFAULT NULL,
|
|
reservation_id BIGINT UNSIGNED DEFAULT NULL,
|
|
deployment_snapshot_id BIGINT UNSIGNED DEFAULT NULL,
|
|
idempotency_key VARCHAR(128) NOT NULL,
|
|
request_hash CHAR(64) NOT NULL,
|
|
amount DECIMAL(12,2) NOT NULL,
|
|
currency CHAR(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'USD',
|
|
status VARCHAR(32) NOT NULL DEFAULT 'queued',
|
|
spec_json LONGTEXT NOT NULL,
|
|
sealed_payload LONGTEXT DEFAULT NULL,
|
|
instance_id BIGINT UNSIGNED DEFAULT NULL,
|
|
refunded_at BIGINT DEFAULT NULL,
|
|
stock_reserved_at BIGINT UNSIGNED DEFAULT NULL,
|
|
stock_released_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT NOT NULL,
|
|
updated_at BIGINT NOT NULL,
|
|
UNIQUE KEY uniq_cloud_order_request (user_id, idempotency_key),
|
|
UNIQUE KEY uniq_cloud_order_reservation (reservation_id),
|
|
KEY cloud_order_owner (user_id, id),
|
|
KEY cloud_order_offer_state (offer_id, status, id),
|
|
KEY cloud_order_placement (resource_pool_id, host_id, status),
|
|
KEY cloud_order_admin_created (created_at, id),
|
|
KEY cloud_order_admin_status (status, created_at, id),
|
|
KEY cloud_order_admin_user (user_id, created_at, id),
|
|
KEY cloud_order_deployment_snapshot (deployment_snapshot_id, status, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_order_items (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
order_id BIGINT UNSIGNED NOT NULL,
|
|
code VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
label VARCHAR(128) NOT NULL,
|
|
amount DECIMAL(12,2) NOT NULL,
|
|
currency CHAR(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'USD',
|
|
snapshot_json LONGTEXT NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_order_item_code (order_id, code),
|
|
KEY cloud_order_item_order (order_id, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Reservations are the auditable resource ledger. The per-host capacity
|
|
-- policy row is locked before sums over held/committed/uncertain rows are
|
|
-- evaluated, serializing concurrent schedulers without an Agent round trip.
|
|
CREATE TABLE cloud_resource_reservations (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
reservation_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
order_id BIGINT UNSIGNED DEFAULT NULL,
|
|
backup_restore_id BIGINT UNSIGNED DEFAULT NULL,
|
|
backup_restore_attempt_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
migration_source_debt_id BIGINT UNSIGNED DEFAULT NULL,
|
|
offer_id BIGINT UNSIGNED DEFAULT NULL,
|
|
resource_pool_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
instance_id BIGINT UNSIGNED DEFAULT NULL,
|
|
network_attachment_id BIGINT UNSIGNED DEFAULT NULL,
|
|
public_ip_pool_id BIGINT UNSIGNED DEFAULT NULL,
|
|
public_ip_id BIGINT UNSIGNED DEFAULT NULL,
|
|
cpu_cores SMALLINT UNSIGNED NOT NULL,
|
|
memory_mib BIGINT UNSIGNED NOT NULL,
|
|
disk_gib BIGINT UNSIGNED NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'held',
|
|
expires_at BIGINT UNSIGNED DEFAULT NULL,
|
|
released_at BIGINT UNSIGNED DEFAULT NULL,
|
|
release_reason VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_resource_reservation_key (reservation_key),
|
|
UNIQUE KEY cloud_resource_reservation_operation (operation_id),
|
|
UNIQUE KEY cloud_resource_reservation_order (order_id),
|
|
UNIQUE KEY cloud_resource_reservation_backup_restore (backup_restore_id),
|
|
UNIQUE KEY cloud_resource_reservation_backup_attempt (
|
|
backup_restore_attempt_key
|
|
),
|
|
UNIQUE KEY cloud_resource_reservation_migration_debt (
|
|
migration_source_debt_id
|
|
),
|
|
KEY cloud_resource_reservation_host (host_id, state, expires_at, id),
|
|
KEY cloud_resource_reservation_pool (resource_pool_id, state, id),
|
|
KEY cloud_resource_reservation_instance (instance_id),
|
|
KEY cloud_resource_reservation_network (network_attachment_id, public_ip_pool_id),
|
|
KEY cloud_resource_reservation_ip (public_ip_id),
|
|
CONSTRAINT chk_cloud_resource_reservation_source CHECK (
|
|
(order_id IS NOT NULL AND offer_id IS NOT NULL
|
|
AND backup_restore_id IS NULL
|
|
AND backup_restore_attempt_key IS NULL
|
|
AND migration_source_debt_id IS NULL)
|
|
OR (order_id IS NULL AND offer_id IS NULL
|
|
AND backup_restore_id IS NOT NULL
|
|
AND backup_restore_attempt_key IS NULL
|
|
AND migration_source_debt_id IS NULL)
|
|
OR (order_id IS NULL AND offer_id IS NULL
|
|
AND backup_restore_id IS NULL
|
|
AND backup_restore_attempt_key IS NOT NULL
|
|
AND migration_source_debt_id IS NULL)
|
|
OR (order_id IS NULL AND offer_id IS NULL
|
|
AND backup_restore_id IS NULL
|
|
AND backup_restore_attempt_key IS NULL
|
|
AND migration_source_debt_id IS NOT NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- One resource reservation owns one address in each required family. Claims
|
|
-- are retained after release so reconciliation can prove which exact bundle
|
|
-- an operation held without overloading nullable columns on the reservation.
|
|
CREATE TABLE cloud_resource_reservation_ips (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
reservation_id BIGINT UNSIGNED NOT NULL,
|
|
address_family TINYINT UNSIGNED NOT NULL,
|
|
claim_generation BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
active_claim TINYINT UNSIGNED DEFAULT 1,
|
|
network_attachment_id BIGINT UNSIGNED NOT NULL,
|
|
public_ip_pool_id BIGINT UNSIGNED NOT NULL,
|
|
public_ip_id BIGINT UNSIGNED NOT NULL,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'reserved',
|
|
released_at BIGINT UNSIGNED DEFAULT NULL,
|
|
release_reason VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_reservation_ip_active (
|
|
reservation_id, address_family, active_claim
|
|
),
|
|
UNIQUE KEY cloud_reservation_ip_generation (
|
|
reservation_id, claim_generation, address_family
|
|
),
|
|
UNIQUE KEY cloud_reservation_ip_operation (operation_id, address_family),
|
|
KEY cloud_reservation_ip_address (public_ip_id, state, id),
|
|
KEY cloud_reservation_ip_pool (public_ip_pool_id, state, id),
|
|
KEY cloud_reservation_ip_attachment (network_attachment_id, state, id),
|
|
CONSTRAINT chk_cloud_reservation_ip_family CHECK (
|
|
address_family IN (4,6)
|
|
),
|
|
CONSTRAINT chk_cloud_reservation_ip_generation CHECK (
|
|
claim_generation >= 1
|
|
),
|
|
CONSTRAINT chk_cloud_reservation_ip_active CHECK (
|
|
(
|
|
state = 'released'
|
|
AND active_claim IS NULL
|
|
)
|
|
OR (
|
|
state = 'committed'
|
|
AND active_claim IS NOT NULL
|
|
AND active_claim = 1
|
|
)
|
|
OR (
|
|
state IN ('reserved','uncertain')
|
|
AND (active_claim IS NULL OR active_claim = 1)
|
|
)
|
|
),
|
|
CONSTRAINT chk_cloud_reservation_ip_state CHECK (
|
|
state IN ('reserved','committed','uncertain','released')
|
|
),
|
|
CONSTRAINT chk_cloud_reservation_ip_release CHECK (
|
|
(state = 'released' AND released_at IS NOT NULL AND release_reason <> '')
|
|
OR (state <> 'released' AND released_at IS NULL AND release_reason = '')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A network transition owns the complete source and target dual-stack
|
|
-- identity. Remote uncertainty remains active and non-terminal; once the
|
|
-- Agent effect is proven, local finalization can be retried without
|
|
-- dispatching the original mutation again.
|
|
CREATE TABLE cloud_public_network_transitions (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
transition_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
kind VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
reservation_id BIGINT UNSIGNED NOT NULL,
|
|
invoice_id BIGINT UNSIGNED DEFAULT NULL,
|
|
pool_replacement_batch_item_id BIGINT UNSIGNED DEFAULT NULL,
|
|
requested_by_user_id INT NOT NULL,
|
|
source_network_attachment_id BIGINT UNSIGNED NOT NULL,
|
|
target_network_attachment_id BIGINT UNSIGNED NOT NULL,
|
|
source_claim_set_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
target_claim_set_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_public_network_json LONGTEXT NOT NULL,
|
|
source_public_network_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
target_public_network_json LONGTEXT NOT NULL,
|
|
target_public_network_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'reserved',
|
|
effect_resolution VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'not_applicable',
|
|
active_transition TINYINT UNSIGNED DEFAULT 1,
|
|
last_error_code VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
effect_resolved_at BIGINT UNSIGNED DEFAULT NULL,
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_public_network_transition_key (transition_key),
|
|
UNIQUE KEY cloud_public_network_transition_operation (operation_id),
|
|
UNIQUE KEY cloud_public_network_transition_active_instance (
|
|
instance_id, active_transition
|
|
),
|
|
UNIQUE KEY cloud_public_network_transition_active_reservation (
|
|
reservation_id, active_transition
|
|
),
|
|
KEY cloud_public_network_transition_host_state (host_id, state, id),
|
|
UNIQUE KEY cloud_public_network_transition_invoice (invoice_id),
|
|
UNIQUE KEY cloud_public_network_transition_batch_item (
|
|
pool_replacement_batch_item_id
|
|
),
|
|
CONSTRAINT chk_cloud_public_network_transition_kind CHECK (
|
|
(kind = 'user_paid' AND invoice_id IS NOT NULL
|
|
AND pool_replacement_batch_item_id IS NULL)
|
|
OR (kind = 'admin_manual' AND invoice_id IS NULL
|
|
AND pool_replacement_batch_item_id IS NULL)
|
|
OR (kind = 'pool_replacement' AND invoice_id IS NULL
|
|
AND pool_replacement_batch_item_id IS NOT NULL)
|
|
),
|
|
CONSTRAINT chk_cloud_public_network_transition_state CHECK (
|
|
state IN ('reserved','queued','awaiting_receipt','effect_unknown',
|
|
'finalization_pending','succeeded','failed')
|
|
),
|
|
CONSTRAINT chk_cloud_public_network_transition_active CHECK (
|
|
active_transition IS NULL OR active_transition = 1
|
|
),
|
|
CONSTRAINT chk_cloud_public_network_transition_shape CHECK (
|
|
(state IN ('reserved','queued','awaiting_receipt')
|
|
AND effect_resolution = 'not_applicable'
|
|
AND active_transition IS NOT NULL AND active_transition = 1
|
|
AND effect_resolved_at IS NULL AND terminal_at IS NULL)
|
|
OR (state = 'effect_unknown' AND effect_resolution = 'unknown'
|
|
AND active_transition IS NOT NULL AND active_transition = 1
|
|
AND effect_resolved_at IS NULL AND terminal_at IS NULL)
|
|
OR (state = 'finalization_pending'
|
|
AND effect_resolution IN ('applied','not_applied')
|
|
AND active_transition IS NOT NULL AND active_transition = 1
|
|
AND effect_resolved_at IS NOT NULL AND terminal_at IS NULL)
|
|
OR (state = 'succeeded' AND effect_resolution = 'applied'
|
|
AND active_transition IS NULL
|
|
AND effect_resolved_at IS NOT NULL AND terminal_at IS NOT NULL)
|
|
OR (state = 'failed' AND effect_resolution = 'not_applied'
|
|
AND active_transition IS NULL
|
|
AND effect_resolved_at IS NOT NULL AND terminal_at IS NOT NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Every transition freezes both families. A family that remains unchanged
|
|
-- references only its source claim; a changed family owns one exact target
|
|
-- claim that no other transition may reuse.
|
|
CREATE TABLE cloud_public_network_transition_ips (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
transition_id BIGINT UNSIGNED NOT NULL,
|
|
address_family TINYINT UNSIGNED NOT NULL,
|
|
source_claim_id BIGINT UNSIGNED NOT NULL,
|
|
target_claim_id BIGINT UNSIGNED DEFAULT NULL,
|
|
changed TINYINT UNSIGNED NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_public_network_transition_ip_family (
|
|
transition_id, address_family
|
|
),
|
|
UNIQUE KEY cloud_public_network_transition_ip_target (target_claim_id),
|
|
KEY cloud_public_network_transition_ip_source (
|
|
source_claim_id, transition_id
|
|
),
|
|
CONSTRAINT chk_cloud_public_network_transition_ip_family CHECK (
|
|
address_family IN (4,6)
|
|
),
|
|
CONSTRAINT chk_cloud_public_network_transition_ip_changed CHECK (
|
|
changed IN (0,1)
|
|
),
|
|
CONSTRAINT chk_cloud_public_network_transition_ip_target CHECK (
|
|
(changed = 1 AND target_claim_id IS NOT NULL
|
|
AND source_claim_id <> target_claim_id)
|
|
OR (changed = 0 AND target_claim_id IS NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_service_periods (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
plan_id BIGINT UNSIGNED DEFAULT NULL,
|
|
order_id BIGINT UNSIGNED DEFAULT NULL,
|
|
renewal_id BIGINT UNSIGNED DEFAULT NULL,
|
|
traffic_pool_group_id BIGINT UNSIGNED DEFAULT NULL,
|
|
traffic_quota_mode VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'finite',
|
|
starts_at BIGINT UNSIGNED NOT NULL,
|
|
ends_at BIGINT UNSIGNED NOT NULL,
|
|
traffic_quota_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
download_base_bytes BIGINT UNSIGNED DEFAULT NULL,
|
|
upload_base_bytes BIGINT UNSIGNED DEFAULT NULL,
|
|
download_used_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
upload_used_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
status VARCHAR(16) NOT NULL DEFAULT 'scheduled',
|
|
activated_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY uniq_cloud_period_order (order_id),
|
|
UNIQUE KEY uniq_cloud_period_renewal (renewal_id),
|
|
KEY cloud_period_timeline (instance_id, starts_at, ends_at),
|
|
KEY cloud_period_activation (status, starts_at, id),
|
|
KEY cloud_period_traffic_pool (traffic_pool_group_id, status, starts_at, ends_at, id),
|
|
CONSTRAINT chk_cloud_period_traffic_quota_mode CHECK (
|
|
traffic_quota_mode IN ('finite','unlimited')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Mutable pool and entitlement rows are rebuildable projections. Immutable
|
|
-- ledger rows below remain the audit source for every granted, consumed,
|
|
-- forfeited and overage byte.
|
|
CREATE TABLE cloud_traffic_pools (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
traffic_pool_group_id BIGINT UNSIGNED NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'available',
|
|
available_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
overage_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
version BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_sequence BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_event_id BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_traffic_pool_owner_group (user_id, traffic_pool_group_id),
|
|
KEY cloud_traffic_pool_state (state, updated_at, id),
|
|
CONSTRAINT chk_cloud_traffic_pool_state CHECK (
|
|
state IN ('available','exhausted','attention')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_traffic_entitlements (
|
|
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,
|
|
starts_at BIGINT UNSIGNED NOT NULL,
|
|
ends_at BIGINT UNSIGNED NOT NULL,
|
|
quota_mode VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
granted_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
consumed_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
forfeited_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'scheduled',
|
|
activated_at BIGINT UNSIGNED DEFAULT NULL,
|
|
closed_at BIGINT UNSIGNED DEFAULT NULL,
|
|
version BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_traffic_entitlement_period (service_period_id),
|
|
KEY cloud_traffic_entitlement_fefo (pool_id, state, ends_at, id),
|
|
KEY cloud_traffic_entitlement_activation (state, starts_at, id),
|
|
KEY cloud_traffic_entitlement_owner (user_id, id),
|
|
KEY cloud_traffic_entitlement_instance (instance_id, state, ends_at, id),
|
|
CONSTRAINT chk_cloud_traffic_entitlement_window CHECK (starts_at < ends_at),
|
|
CONSTRAINT chk_cloud_traffic_entitlement_mode CHECK (
|
|
(quota_mode = 'finite' AND granted_bytes > 0)
|
|
OR (quota_mode = 'unlimited' AND granted_bytes = 0)
|
|
),
|
|
CONSTRAINT chk_cloud_traffic_entitlement_balance CHECK (
|
|
consumed_bytes + forfeited_bytes <= granted_bytes
|
|
),
|
|
CONSTRAINT chk_cloud_traffic_entitlement_state CHECK (
|
|
state IN ('scheduled','active','closing','exhausted','expired')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_traffic_ledger_events (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
pool_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
pool_sequence BIGINT UNSIGNED NOT NULL,
|
|
event_key VARCHAR(191) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
event_type VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_type VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_id VARCHAR(191) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
payload_hash CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
instance_id BIGINT UNSIGNED DEFAULT NULL,
|
|
service_period_id BIGINT UNSIGNED DEFAULT NULL,
|
|
entitlement_id BIGINT UNSIGNED DEFAULT NULL,
|
|
amount_bytes BIGINT NOT NULL DEFAULT 0,
|
|
effective_at BIGINT UNSIGNED NOT NULL,
|
|
observed_at BIGINT UNSIGNED DEFAULT NULL,
|
|
payload_json LONGTEXT NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_traffic_ledger_event_key (event_key),
|
|
UNIQUE KEY cloud_traffic_ledger_sequence (pool_id, pool_sequence),
|
|
UNIQUE KEY cloud_traffic_ledger_source (
|
|
source_type, source_id, source_revision, event_type, entitlement_id
|
|
),
|
|
KEY cloud_traffic_ledger_owner (user_id, id),
|
|
KEY cloud_traffic_ledger_instance (instance_id, id),
|
|
KEY cloud_traffic_ledger_period (service_period_id, id),
|
|
KEY cloud_traffic_ledger_pool_time (pool_id, effective_at, id)
|
|
) 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,
|
|
pool_id BIGINT UNSIGNED NOT NULL,
|
|
accounted_download_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
accounted_upload_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_observed_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
last_event_id BIGINT UNSIGNED DEFAULT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'ready',
|
|
attention_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
version BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
KEY cloud_traffic_cursor_pool (pool_id, last_observed_at, instance_id),
|
|
KEY cloud_traffic_cursor_owner (user_id, instance_id),
|
|
CONSTRAINT chk_cloud_traffic_cursor_state CHECK (
|
|
state IN ('ready','attention')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A failed bounded scan is quarantined with backoff so a deterministic bad
|
|
-- row cannot permanently starve higher IDs, including one-shot workers that
|
|
-- do not retain an in-memory cursor between invocations.
|
|
CREATE TABLE cloud_traffic_scan_failures (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
scan_kind VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
subject_id BIGINT UNSIGNED NOT NULL,
|
|
attempt_count INT UNSIGNED NOT NULL DEFAULT 1,
|
|
last_error_code VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
retry_at BIGINT UNSIGNED NOT NULL,
|
|
first_failed_at BIGINT UNSIGNED NOT NULL,
|
|
last_failed_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_traffic_scan_failure_subject (scan_kind, subject_id),
|
|
KEY cloud_traffic_scan_failure_retry (scan_kind, retry_at, subject_id),
|
|
CONSTRAINT chk_cloud_traffic_scan_failure_kind CHECK (
|
|
scan_kind IN ('period','instance')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_instance_network_restrictions (
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
reason_code VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
desired_active TINYINT(1) NOT NULL DEFAULT 1,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
source_type VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_id VARCHAR(191) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
PRIMARY KEY (instance_id, reason_code),
|
|
KEY cloud_network_restriction_desired (desired_active, updated_at, instance_id),
|
|
KEY cloud_network_restriction_owner (user_id, instance_id),
|
|
CONSTRAINT chk_cloud_network_restriction_reason CHECK (
|
|
reason_code IN ('traffic_pool_exhausted','service_expired','admin_hold')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Restriction rows are independent policy facts. The remote NIC mutation is
|
|
-- one aggregate operation per instance, so its execution state must not be
|
|
-- duplicated onto whichever reason happened to trigger the transition.
|
|
CREATE TABLE cloud_instance_network_policy_states (
|
|
instance_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
desired_suspended TINYINT(1) NOT NULL DEFAULT 0,
|
|
applied_suspended TINYINT(1) NOT NULL DEFAULT 0,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'applied',
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_network_policy_operation (operation_id),
|
|
KEY cloud_network_policy_state (state, updated_at, instance_id),
|
|
KEY cloud_network_policy_owner (user_id, instance_id),
|
|
CONSTRAINT chk_cloud_network_policy_state CHECK (
|
|
state IN ('pending','applying','applied','failed','unknown')
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_renewals (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
plan_id BIGINT UNSIGNED DEFAULT NULL,
|
|
period_id BIGINT UNSIGNED DEFAULT NULL,
|
|
idempotency_key VARCHAR(128) NOT NULL,
|
|
request_hash CHAR(64) NOT NULL,
|
|
amount DECIMAL(12,2) NOT NULL,
|
|
validity_days INT UNSIGNED NOT NULL,
|
|
traffic_bytes_added BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
previous_expires_at BIGINT UNSIGNED NOT NULL,
|
|
new_expires_at BIGINT UNSIGNED NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY uniq_cloud_renewal_request (user_id, idempotency_key),
|
|
KEY cloud_renewal_instance (instance_id, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_invoices (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
invoice_no VARCHAR(40) NOT NULL,
|
|
purpose VARCHAR(16) NOT NULL DEFAULT 'renewal',
|
|
instance_id BIGINT UNSIGNED DEFAULT NULL,
|
|
order_id BIGINT UNSIGNED DEFAULT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
plan_id BIGINT UNSIGNED DEFAULT NULL,
|
|
offer_id BIGINT UNSIGNED DEFAULT NULL,
|
|
renewal_id BIGINT UNSIGNED DEFAULT NULL,
|
|
renews_expires_at BIGINT UNSIGNED DEFAULT NULL,
|
|
due_at BIGINT UNSIGNED NOT NULL,
|
|
amount DECIMAL(12,2) NOT NULL,
|
|
currency CHAR(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'USD',
|
|
validity_days INT UNSIGNED NOT NULL,
|
|
traffic_quota_bytes BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
status VARCHAR(16) NOT NULL DEFAULT 'open',
|
|
paid_via VARCHAR(32) DEFAULT NULL,
|
|
payment_reference VARCHAR(80) DEFAULT NULL,
|
|
paid_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY uniq_cloud_invoice_no (invoice_no),
|
|
UNIQUE KEY uniq_cloud_invoice_order (order_id),
|
|
KEY cloud_invoice_period (instance_id, renews_expires_at, status),
|
|
UNIQUE KEY uniq_cloud_invoice_renewal (renewal_id),
|
|
KEY cloud_invoice_owner (user_id, status, due_at),
|
|
KEY cloud_invoice_due (status, due_at, id),
|
|
KEY cloud_invoice_overview_paid (status, paid_at, purpose, plan_id),
|
|
KEY cloud_invoice_admin_created (created_at, id),
|
|
KEY cloud_invoice_admin_status (status, created_at, id),
|
|
KEY cloud_invoice_admin_purpose (purpose, created_at, id),
|
|
KEY cloud_invoice_admin_user (user_id, created_at, id),
|
|
KEY cloud_invoice_admin_method (paid_via, created_at, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_invoice_items (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
invoice_id BIGINT UNSIGNED NOT NULL,
|
|
order_item_id BIGINT UNSIGNED DEFAULT NULL,
|
|
code VARCHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
label VARCHAR(128) NOT NULL,
|
|
amount DECIMAL(12,2) NOT NULL,
|
|
currency CHAR(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'USD',
|
|
snapshot_json LONGTEXT NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_invoice_item_code (invoice_id, code),
|
|
KEY cloud_invoice_item_invoice (invoice_id, id),
|
|
KEY cloud_invoice_item_order_item (order_item_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_invoice_payments (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
invoice_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
provider VARCHAR(24) NOT NULL,
|
|
provider_order_no VARCHAR(64) NOT NULL,
|
|
idempotency_key VARCHAR(128) NOT NULL,
|
|
amount DECIMAL(12,2) NOT NULL,
|
|
status VARCHAR(24) NOT NULL DEFAULT 'creating',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY uniq_cloud_invoice_provider_order (provider, provider_order_no),
|
|
UNIQUE KEY uniq_cloud_invoice_payment_request (user_id, idempotency_key),
|
|
KEY cloud_invoice_payment_invoice (invoice_id, id),
|
|
KEY cloud_invoice_payment_admin_created (created_at, id),
|
|
KEY cloud_invoice_payment_admin_status (status, created_at, id),
|
|
KEY cloud_invoice_payment_admin_provider (provider, created_at, id),
|
|
KEY cloud_invoice_payment_admin_user (user_id, created_at, id),
|
|
CONSTRAINT chk_cloud_invoice_payment_status CHECK (status IN (
|
|
'creating','pending','paid_invoice','credited_balance',
|
|
'failed','expired','not_created','creation_unknown'
|
|
))
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_mail_outbox (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
invoice_id BIGINT UNSIGNED NOT NULL,
|
|
kind VARCHAR(32) NOT NULL,
|
|
status VARCHAR(16) NOT NULL DEFAULT 'pending',
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
available_at BIGINT UNSIGNED NOT NULL,
|
|
lease_token CHAR(32) DEFAULT NULL,
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sent_at BIGINT UNSIGNED DEFAULT NULL,
|
|
last_error VARCHAR(500) NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY uniq_cloud_invoice_mail (invoice_id, kind),
|
|
KEY cloud_mail_delivery (status, available_at, lease_until, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- One immutable administrator maintenance notice targets either one compute
|
|
-- host or one public address pool. Audience rows are frozen before delivery;
|
|
-- later placement or address changes never rewrite what was announced.
|
|
CREATE TABLE cloud_maintenance_notices (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
notice_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
requested_by_user_id BIGINT UNSIGNED NOT NULL,
|
|
request_idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
request_fingerprint CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
scope_type VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
scope_id BIGINT UNSIGNED NOT NULL,
|
|
scope_snapshot_json LONGTEXT NOT NULL,
|
|
subject VARCHAR(180) NOT NULL,
|
|
message_text TEXT NOT NULL,
|
|
impact VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
maintenance_starts_at BIGINT UNSIGNED NOT NULL,
|
|
maintenance_ends_at BIGINT UNSIGNED NOT NULL,
|
|
scheduled_at BIGINT UNSIGNED NOT NULL,
|
|
audience_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
instance_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
recipient_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
skipped_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
status VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'scheduled',
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_maintenance_notice_key (notice_key),
|
|
UNIQUE KEY cloud_maintenance_notice_request (
|
|
requested_by_user_id, request_idempotency_key
|
|
),
|
|
KEY cloud_maintenance_notice_delivery (status, scheduled_at, id),
|
|
KEY cloud_maintenance_notice_scope (scope_type, scope_id, created_at, id),
|
|
CONSTRAINT chk_cloud_maintenance_notice_scope CHECK (
|
|
scope_type IN ('host','public_ip_pool')
|
|
),
|
|
CONSTRAINT chk_cloud_maintenance_notice_impact CHECK (
|
|
impact IN (
|
|
'network_interruption','instance_restart',
|
|
'service_interruption','no_interruption'
|
|
)
|
|
),
|
|
CONSTRAINT chk_cloud_maintenance_notice_status CHECK (
|
|
status IN ('scheduled','sending','completed','attention','cancelled')
|
|
),
|
|
CONSTRAINT chk_cloud_maintenance_notice_window CHECK (
|
|
scope_id > 0
|
|
AND maintenance_ends_at > maintenance_starts_at
|
|
AND instance_count > 0
|
|
AND recipient_count > 0
|
|
AND recipient_count + skipped_count <= instance_count
|
|
AND CHAR_LENGTH(request_idempotency_key) BETWEEN 16 AND 128
|
|
AND CHAR_LENGTH(request_fingerprint) = 64
|
|
AND CHAR_LENGTH(audience_digest) = 64
|
|
),
|
|
CONSTRAINT chk_cloud_maintenance_notice_terminal CHECK (
|
|
(status IN ('scheduled','sending') AND terminal_at IS NULL)
|
|
OR
|
|
(status IN ('completed','attention','cancelled') AND terminal_at IS NOT NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Frozen instance evidence lets one recipient see only their own affected
|
|
-- instances while preserving the exact scope reviewed by the administrator.
|
|
CREATE TABLE cloud_maintenance_notice_instances (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
notice_id BIGINT UNSIGNED NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
public_ip_pool_id BIGINT UNSIGNED DEFAULT NULL,
|
|
instance_name VARCHAR(63) NOT NULL,
|
|
ipv4 VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
ipv6 VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
evidence_json LONGTEXT NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_maintenance_notice_instance (notice_id, instance_id),
|
|
KEY cloud_maintenance_notice_instance_owner (notice_id, user_id, id),
|
|
KEY cloud_maintenance_notice_instance_source (instance_id, notice_id),
|
|
CONSTRAINT fk_cloud_maintenance_notice_instance_notice
|
|
FOREIGN KEY (notice_id) REFERENCES cloud_maintenance_notices (id)
|
|
ON DELETE CASCADE ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Recipient rows are both the immutable audience and the bounded delivery
|
|
-- outbox. A stale sending lease becomes unknown and is never replayed
|
|
-- automatically because SMTP acceptance may already have happened.
|
|
CREATE TABLE cloud_maintenance_notice_recipients (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
notice_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
email_snapshot VARCHAR(254) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
status VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
available_at BIGINT UNSIGNED NOT NULL,
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sent_at BIGINT UNSIGNED DEFAULT NULL,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_error VARCHAR(500) NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_maintenance_notice_recipient (notice_id, user_id),
|
|
KEY cloud_maintenance_notice_recipient_due (status, available_at, id),
|
|
KEY cloud_maintenance_notice_recipient_lease (status, lease_until, id),
|
|
KEY cloud_maintenance_notice_recipient_owner (user_id, created_at, id),
|
|
CONSTRAINT chk_cloud_maintenance_notice_recipient_status CHECK (
|
|
status IN (
|
|
'pending','sending','sent','failed','unknown','skipped','cancelled'
|
|
)
|
|
),
|
|
CONSTRAINT chk_cloud_maintenance_notice_recipient_shape CHECK (
|
|
available_at > 0
|
|
AND (
|
|
(status = 'pending' AND lease_token IS NULL AND lease_until = 0 AND sent_at IS NULL AND last_error_code = '' AND last_error = '')
|
|
OR
|
|
(status = 'sending' AND attempts > 0 AND lease_token IS NOT NULL AND lease_until > 0 AND sent_at IS NULL)
|
|
OR
|
|
(status = 'sent' AND lease_token IS NULL AND lease_until = 0 AND sent_at IS NOT NULL AND last_error_code = '' AND last_error = '')
|
|
OR
|
|
(status IN ('failed','unknown') AND lease_token IS NULL AND lease_until = 0 AND sent_at IS NULL AND last_error_code <> '')
|
|
OR
|
|
(status IN ('skipped','cancelled') AND lease_token IS NULL AND lease_until = 0 AND sent_at IS NULL AND last_error_code <> '')
|
|
)
|
|
),
|
|
CONSTRAINT fk_cloud_maintenance_notice_recipient_notice
|
|
FOREIGN KEY (notice_id) REFERENCES cloud_maintenance_notices (id)
|
|
ON DELETE CASCADE ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- One administrator service-compensation request freezes an affected scope and
|
|
-- its exact per-instance evidence. The batch is retained as aggregate audit
|
|
-- after tenant PII in item and recipient rows is removed during account
|
|
-- deletion.
|
|
CREATE TABLE cloud_service_compensations (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
compensation_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
incident_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
requested_by_user_id BIGINT UNSIGNED NOT NULL,
|
|
request_idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
request_fingerprint CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
scope_type VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
scope_id BIGINT UNSIGNED NOT NULL,
|
|
scope_snapshot_json LONGTEXT NOT NULL,
|
|
reason_text VARCHAR(500) NOT NULL,
|
|
incident_starts_at BIGINT UNSIGNED DEFAULT NULL,
|
|
incident_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
compensation_seconds BIGINT UNSIGNED NOT NULL,
|
|
notify_users TINYINT(1) NOT NULL DEFAULT 1,
|
|
audience_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
instance_count INT UNSIGNED NOT NULL,
|
|
recipient_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
applied_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
deferred_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
rejected_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
attention_count INT UNSIGNED NOT NULL DEFAULT 0,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_service_compensation_key (compensation_key),
|
|
UNIQUE KEY cloud_service_compensation_request (
|
|
requested_by_user_id, request_idempotency_key
|
|
),
|
|
UNIQUE KEY cloud_service_compensation_incident_identity (id, incident_key),
|
|
KEY cloud_service_compensation_incident (incident_key, id),
|
|
KEY cloud_service_compensation_scope (scope_type, scope_id, created_at, id),
|
|
KEY cloud_service_compensation_state (state, created_at, id),
|
|
CONSTRAINT chk_cloud_service_compensation_scope CHECK (
|
|
scope_type IN ('instance','host','public_ip_pool') AND scope_id > 0
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_request CHECK (
|
|
CHAR_LENGTH(request_idempotency_key) BETWEEN 16 AND 128
|
|
AND CHAR_LENGTH(request_fingerprint) = 64
|
|
AND CHAR_LENGTH(incident_key) BETWEEN 1 AND 128
|
|
AND CHAR_LENGTH(audience_digest) = 64
|
|
AND CHAR_LENGTH(reason_text) BETWEEN 1 AND 500
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_window CHECK (
|
|
compensation_seconds BETWEEN 1 AND 31622400
|
|
AND (
|
|
(incident_starts_at IS NULL AND incident_ends_at IS NULL)
|
|
OR (incident_starts_at IS NOT NULL AND incident_ends_at IS NOT NULL
|
|
AND incident_ends_at > incident_starts_at)
|
|
)
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_counts CHECK (
|
|
notify_users IN (0,1)
|
|
AND instance_count > 0
|
|
AND recipient_count <= instance_count
|
|
AND applied_count + deferred_count + rejected_count + attention_count
|
|
<= instance_count
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_state CHECK (
|
|
state IN ('pending','applying','completed','partial','attention')
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_terminal CHECK (
|
|
(state IN ('pending','applying') AND terminal_at IS NULL)
|
|
OR (state IN ('completed','partial','attention') AND terminal_at IS NOT NULL)
|
|
)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Per-instance rows are both the durable work queue and the immutable before /
|
|
-- after audit. The incident key is repeated under a composite foreign key so
|
|
-- an item can never be attached to a batch for another incident.
|
|
CREATE TABLE cloud_service_compensation_items (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
item_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
batch_id BIGINT UNSIGNED NOT NULL,
|
|
incident_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
instance_name VARCHAR(63) NOT NULL,
|
|
requested_seconds BIGINT UNSIGNED NOT NULL,
|
|
service_period_id BIGINT UNSIGNED DEFAULT NULL,
|
|
traffic_entitlement_id BIGINT UNSIGNED DEFAULT NULL,
|
|
backup_entitlement_id BIGINT UNSIGNED DEFAULT NULL,
|
|
source_invoice_id BIGINT UNSIGNED DEFAULT NULL,
|
|
replacement_invoice_id BIGINT UNSIGNED DEFAULT NULL,
|
|
audit_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
before_expires_at BIGINT UNSIGNED DEFAULT NULL,
|
|
after_expires_at BIGINT UNSIGNED DEFAULT NULL,
|
|
before_period_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
after_period_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
before_traffic_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
after_traffic_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
before_backup_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
after_backup_ends_at BIGINT UNSIGNED DEFAULT NULL,
|
|
before_snapshot_json LONGTEXT NOT NULL,
|
|
after_snapshot_json LONGTEXT DEFAULT NULL,
|
|
state VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
available_at BIGINT UNSIGNED NOT NULL,
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
applied_at BIGINT UNSIGNED DEFAULT NULL,
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_error VARCHAR(500) NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_service_compensation_item_key (item_key),
|
|
UNIQUE KEY cloud_service_compensation_item_instance (batch_id, instance_id),
|
|
UNIQUE KEY cloud_service_compensation_item_incident (incident_key, instance_id),
|
|
KEY cloud_service_compensation_item_batch_state (batch_id, state, id),
|
|
KEY cloud_service_compensation_item_due (state, available_at, id),
|
|
KEY cloud_service_compensation_item_lease (state, lease_until, id),
|
|
KEY cloud_service_compensation_item_open (instance_id, state, id),
|
|
KEY cloud_service_compensation_item_owner (user_id, created_at, id),
|
|
KEY cloud_service_compensation_item_instance_history (instance_id, created_at, id),
|
|
KEY cloud_service_compensation_item_audit_job (audit_job_id, id),
|
|
CONSTRAINT chk_cloud_service_compensation_item_state CHECK (
|
|
state IN (
|
|
'pending','applying','deferred','applied',
|
|
'rejected','attention','cancelled'
|
|
)
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_item_window CHECK (
|
|
requested_seconds BETWEEN 1 AND 31622400
|
|
AND attempts <= 8 AND available_at > 0
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_item_lease CHECK (
|
|
(state = 'applying' AND attempts > 0
|
|
AND lease_token IS NOT NULL AND lease_until > 0)
|
|
OR (state <> 'applying' AND lease_token IS NULL AND lease_until = 0)
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_item_terminal CHECK (
|
|
(state IN ('pending','applying','deferred') AND terminal_at IS NULL)
|
|
OR (state IN ('applied','rejected','attention','cancelled')
|
|
AND terminal_at IS NOT NULL)
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_item_applied CHECK (
|
|
state <> 'applied'
|
|
OR (
|
|
applied_at IS NOT NULL
|
|
AND service_period_id IS NOT NULL
|
|
AND before_expires_at IS NOT NULL AND after_expires_at IS NOT NULL
|
|
AND after_expires_at = before_expires_at + requested_seconds
|
|
AND before_period_ends_at IS NOT NULL
|
|
AND after_period_ends_at IS NOT NULL
|
|
AND after_period_ends_at = before_period_ends_at + requested_seconds
|
|
AND (
|
|
(traffic_entitlement_id IS NULL
|
|
AND before_traffic_ends_at IS NULL
|
|
AND after_traffic_ends_at IS NULL)
|
|
OR (traffic_entitlement_id IS NOT NULL
|
|
AND before_traffic_ends_at IS NOT NULL
|
|
AND after_traffic_ends_at IS NOT NULL
|
|
AND after_traffic_ends_at = before_traffic_ends_at + requested_seconds)
|
|
)
|
|
AND (
|
|
(backup_entitlement_id IS NULL
|
|
AND before_backup_ends_at IS NULL
|
|
AND after_backup_ends_at IS NULL)
|
|
OR (backup_entitlement_id IS NOT NULL
|
|
AND before_backup_ends_at IS NOT NULL
|
|
AND after_backup_ends_at IS NOT NULL
|
|
AND after_backup_ends_at = before_backup_ends_at + requested_seconds)
|
|
)
|
|
AND after_snapshot_json IS NOT NULL
|
|
AND audit_job_id IS NOT NULL
|
|
AND last_error_code = '' AND last_error = ''
|
|
)
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_item_error CHECK (
|
|
state NOT IN ('deferred','rejected','attention','cancelled')
|
|
OR last_error_code <> ''
|
|
),
|
|
CONSTRAINT fk_cloud_service_compensation_item_batch
|
|
FOREIGN KEY (batch_id, incident_key)
|
|
REFERENCES cloud_service_compensations (id, incident_key)
|
|
ON DELETE CASCADE ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Compensation mail uses the same no-blind-replay lease contract as maintenance
|
|
-- notices. The exact payload is frozen so an unknown SMTP effect can be
|
|
-- inspected without recomposing changed instance data.
|
|
CREATE TABLE cloud_service_compensation_recipients (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
batch_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
email_snapshot VARCHAR(254) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
instance_count INT UNSIGNED NOT NULL,
|
|
payload_json LONGTEXT NOT NULL,
|
|
payload_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
status VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'pending',
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
available_at BIGINT UNSIGNED NOT NULL,
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
sent_at BIGINT UNSIGNED DEFAULT NULL,
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
last_error VARCHAR(500) NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_service_compensation_recipient (batch_id, user_id),
|
|
KEY cloud_service_compensation_recipient_due (status, available_at, id),
|
|
KEY cloud_service_compensation_recipient_lease (status, lease_until, id),
|
|
KEY cloud_service_compensation_recipient_owner (user_id, created_at, id),
|
|
CONSTRAINT chk_cloud_service_compensation_recipient_status CHECK (
|
|
status IN (
|
|
'pending','sending','sent','failed','unknown','skipped','cancelled'
|
|
)
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_recipient_payload CHECK (
|
|
instance_count > 0 AND CHAR_LENGTH(payload_sha256) = 64
|
|
),
|
|
CONSTRAINT chk_cloud_service_compensation_recipient_shape CHECK (
|
|
available_at > 0
|
|
AND (
|
|
(status = 'pending' AND lease_token IS NULL AND lease_until = 0
|
|
AND sent_at IS NULL AND last_error_code = '' AND last_error = '')
|
|
OR (status = 'sending' AND attempts > 0
|
|
AND lease_token IS NOT NULL AND lease_until > 0 AND sent_at IS NULL)
|
|
OR (status = 'sent' AND lease_token IS NULL AND lease_until = 0
|
|
AND sent_at IS NOT NULL AND last_error_code = '' AND last_error = '')
|
|
OR (status IN ('failed','unknown') AND lease_token IS NULL
|
|
AND lease_until = 0 AND sent_at IS NULL AND last_error_code <> '')
|
|
OR (status IN ('skipped','cancelled') AND lease_token IS NULL
|
|
AND lease_until = 0 AND sent_at IS NULL AND last_error_code <> '')
|
|
)
|
|
),
|
|
CONSTRAINT fk_cloud_service_compensation_recipient_batch
|
|
FOREIGN KEY (batch_id) REFERENCES cloud_service_compensations (id)
|
|
ON DELETE CASCADE ON UPDATE RESTRICT
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE cloud_jobs (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
operation_id CHAR(32) NOT NULL,
|
|
request_idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
request_fingerprint CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
parent_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
supersedes_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
vpc_repair_root_job_id BIGINT UNSIGNED DEFAULT NULL,
|
|
order_id BIGINT UNSIGNED DEFAULT NULL,
|
|
invoice_id BIGINT UNSIGNED DEFAULT NULL,
|
|
instance_id BIGINT UNSIGNED DEFAULT NULL,
|
|
snapshot_id BIGINT UNSIGNED DEFAULT NULL,
|
|
backup_id BIGINT UNSIGNED DEFAULT NULL,
|
|
backup_restore_id BIGINT UNSIGNED DEFAULT NULL,
|
|
backup_recovery_id BIGINT UNSIGNED DEFAULT NULL,
|
|
public_network_transition_id BIGINT UNSIGNED DEFAULT NULL,
|
|
vpc_id BIGINT UNSIGNED DEFAULT NULL,
|
|
vpc_port_id BIGINT UNSIGNED DEFAULT NULL,
|
|
vpc_batch_id BIGINT UNSIGNED DEFAULT NULL,
|
|
user_id INT NOT NULL,
|
|
host_id BIGINT UNSIGNED DEFAULT NULL,
|
|
kind VARCHAR(32) NOT NULL,
|
|
execution_mode ENUM('agent','local','aggregate') CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
phase VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'accepted',
|
|
outcome VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
status VARCHAR(32) NOT NULL DEFAULT 'queued',
|
|
sealed_payload LONGTEXT NOT NULL,
|
|
attempts INT NOT NULL DEFAULT 0,
|
|
dispatch_attempts TINYINT UNSIGNED NOT NULL DEFAULT 0,
|
|
dispatch_deadline_at BIGINT UNSIGNED NOT NULL,
|
|
dispatch_started_at BIGINT UNSIGNED DEFAULT NULL,
|
|
agent_accepted_at BIGINT UNSIGNED DEFAULT NULL,
|
|
receipt_deadline_at BIGINT UNSIGNED DEFAULT NULL,
|
|
terminal_at BIGINT UNSIGNED DEFAULT NULL,
|
|
effect_may_have_applied TINYINT(1) DEFAULT NULL,
|
|
safe_to_resubmit TINYINT(1) DEFAULT NULL,
|
|
effect_resolution VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'not_applicable',
|
|
effect_resolved_at BIGINT UNSIGNED DEFAULT NULL,
|
|
effect_resolved_by BIGINT UNSIGNED DEFAULT NULL,
|
|
effect_resolution_reason VARCHAR(500) NOT NULL DEFAULT '',
|
|
finalization_incident TINYINT(1) NOT NULL DEFAULT 0,
|
|
finalization_error_code VARCHAR(128) DEFAULT NULL,
|
|
completion_event_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
read_at BIGINT UNSIGNED DEFAULT NULL,
|
|
dispatched_at BIGINT DEFAULT NULL,
|
|
lease_token CHAR(32) DEFAULT NULL,
|
|
lease_until BIGINT NOT NULL DEFAULT 0,
|
|
available_at BIGINT NOT NULL,
|
|
error_code VARCHAR(128) DEFAULT NULL,
|
|
result_json LONGTEXT DEFAULT NULL,
|
|
created_at BIGINT NOT NULL,
|
|
updated_at BIGINT NOT NULL,
|
|
UNIQUE KEY uniq_cloud_operation (operation_id),
|
|
UNIQUE KEY uniq_cloud_job_request (user_id, request_idempotency_key),
|
|
UNIQUE KEY uniq_cloud_job_completion_event (completion_event_id),
|
|
UNIQUE KEY uniq_cloud_provision_order (order_id),
|
|
CONSTRAINT chk_cloud_job_dispatch_once CHECK (dispatch_attempts <= 1),
|
|
CONSTRAINT chk_cloud_job_attempt_shape CHECK (attempts = dispatch_attempts),
|
|
CONSTRAINT chk_cloud_job_phase CHECK (phase IN ('accepted','dispatching','awaiting_receipt','terminal')),
|
|
CONSTRAINT chk_cloud_job_outcome CHECK (outcome IS NULL OR outcome IN ('succeeded','failed')),
|
|
CONSTRAINT chk_cloud_job_effect_resolution CHECK (effect_resolution IN ('not_applicable','unknown','applied','not_applied')),
|
|
CONSTRAINT chk_cloud_job_finalization_incident CHECK (
|
|
(finalization_incident = 0 AND finalization_error_code IS NULL)
|
|
OR
|
|
(finalization_incident = 1 AND phase = 'terminal'
|
|
AND finalization_error_code IS NOT NULL)
|
|
),
|
|
CONSTRAINT chk_cloud_job_terminal_shape CHECK (
|
|
(phase = 'terminal' AND outcome IS NOT NULL AND status = outcome
|
|
AND terminal_at IS NOT NULL AND effect_may_have_applied IS NOT NULL
|
|
AND safe_to_resubmit IS NOT NULL
|
|
AND (
|
|
(outcome = 'succeeded' AND effect_may_have_applied = 0
|
|
AND safe_to_resubmit = 0 AND effect_resolution = 'applied'
|
|
AND error_code IS NULL)
|
|
OR
|
|
(outcome = 'failed' AND (
|
|
(effect_may_have_applied = 1 AND safe_to_resubmit = 0
|
|
AND effect_resolution IN ('unknown','applied','not_applied'))
|
|
OR
|
|
(effect_may_have_applied = 0
|
|
AND effect_resolution = 'not_applied')
|
|
))
|
|
))
|
|
OR
|
|
(phase <> 'terminal' AND outcome IS NULL AND terminal_at IS NULL
|
|
AND effect_may_have_applied IS NULL AND safe_to_resubmit IS NULL
|
|
AND status IN ('queued','running')
|
|
AND effect_resolution = 'not_applicable')
|
|
),
|
|
CONSTRAINT chk_cloud_job_dispatch_shape CHECK (
|
|
phase = 'terminal'
|
|
OR (phase = 'accepted' AND execution_mode IN ('agent','local')
|
|
AND status = 'queued' AND attempts = 0 AND dispatch_attempts = 0
|
|
AND dispatch_started_at IS NULL AND agent_accepted_at IS NULL
|
|
AND dispatched_at IS NULL AND receipt_deadline_at IS NULL)
|
|
OR (phase = 'dispatching' AND execution_mode IN ('agent','local')
|
|
AND status = 'running' AND attempts = 1 AND dispatch_attempts = 1
|
|
AND dispatch_started_at IS NOT NULL AND dispatched_at IS NOT NULL
|
|
AND receipt_deadline_at IS NOT NULL)
|
|
OR (phase = 'awaiting_receipt' AND execution_mode = 'agent'
|
|
AND status = 'running' AND attempts = 1 AND dispatch_attempts = 1
|
|
AND dispatch_started_at IS NOT NULL AND dispatched_at IS NOT NULL
|
|
AND receipt_deadline_at IS NOT NULL)
|
|
OR (phase = 'awaiting_receipt' AND execution_mode = 'aggregate'
|
|
AND host_id IS NULL AND parent_job_id IS NULL AND status = 'running'
|
|
AND attempts = 0 AND dispatch_attempts = 0
|
|
AND dispatch_started_at IS NULL AND dispatched_at IS NULL
|
|
AND receipt_deadline_at IS NOT NULL)
|
|
),
|
|
CONSTRAINT chk_cloud_job_target_shape CHECK (
|
|
(execution_mode = 'agent' AND host_id IS NOT NULL)
|
|
OR (execution_mode = 'local' AND host_id IS NULL AND (
|
|
(parent_job_id IS NULL
|
|
AND kind IN ('payment_create','vpc_membership_batch',
|
|
'public_ip_pool_replacement_batch'))
|
|
OR (parent_job_id IS NULL AND kind = 'service_compensation'
|
|
AND instance_id IS NOT NULL)
|
|
OR (parent_job_id IS NOT NULL
|
|
AND kind = 'vpc_batch_instance_fence'
|
|
AND instance_id IS NOT NULL AND vpc_id IS NOT NULL
|
|
AND vpc_port_id IS NOT NULL AND vpc_batch_id IS NOT NULL)
|
|
))
|
|
OR (execution_mode = 'aggregate' AND host_id IS NULL
|
|
AND parent_job_id IS NULL
|
|
AND kind IN ('template_import','template_metadata_sync','template_delete',
|
|
'user_iso_import','user_iso_delete'))
|
|
),
|
|
CONSTRAINT chk_cloud_job_effect_shape CHECK (
|
|
effect_may_have_applied IS NULL
|
|
OR effect_may_have_applied = 0
|
|
OR safe_to_resubmit = 0
|
|
),
|
|
CONSTRAINT fk_cloud_job_user FOREIGN KEY (user_id)
|
|
REFERENCES `user` (id) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
|
KEY cloud_job_poll (phase, dispatch_deadline_at, id),
|
|
KEY cloud_job_receipt_deadline (phase, receipt_deadline_at, id),
|
|
KEY cloud_job_instance_state (instance_id, status, id),
|
|
KEY cloud_job_invoice_state (invoice_id, phase, id),
|
|
KEY cloud_job_snapshot (snapshot_id, id),
|
|
KEY cloud_job_backup (backup_id, id),
|
|
KEY cloud_job_backup_restore (backup_restore_id, id),
|
|
KEY cloud_job_backup_recovery (backup_recovery_id, id),
|
|
UNIQUE KEY cloud_job_public_network_transition (
|
|
public_network_transition_id
|
|
),
|
|
KEY cloud_job_vpc (vpc_id, id),
|
|
KEY cloud_job_vpc_port (vpc_port_id, id),
|
|
KEY cloud_job_vpc_batch (vpc_batch_id, id),
|
|
KEY cloud_job_overview_state (kind, order_id, phase, outcome, terminal_at, created_at),
|
|
KEY cloud_job_owner (user_id, id),
|
|
KEY cloud_job_parent (parent_job_id, id),
|
|
KEY cloud_job_supersedes (supersedes_job_id, id),
|
|
KEY cloud_job_vpc_repair_root (vpc_repair_root_job_id, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Agent terminal receipts are immutable transport events. Retransmission of
|
|
-- the same event is safe and never replays the host mutation.
|
|
CREATE TABLE cloud_agent_completion_events (
|
|
event_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
payload_sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
outcome VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
effect_may_have_applied TINYINT(1) NOT NULL,
|
|
safe_to_resubmit TINYINT(1) NOT NULL,
|
|
error_code VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
result_json LONGTEXT DEFAULT NULL,
|
|
disposition VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'received',
|
|
received_at BIGINT UNSIGNED NOT NULL,
|
|
applied_at BIGINT UNSIGNED DEFAULT NULL,
|
|
UNIQUE KEY uniq_cloud_completion_operation (host_id, operation_id),
|
|
CONSTRAINT chk_cloud_completion_outcome CHECK (outcome IN ('succeeded','failed')),
|
|
CONSTRAINT chk_cloud_completion_disposition CHECK (disposition IN ('received','applied','duplicate','late','rejected'))
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_ssh_keys (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
name VARCHAR(80) NOT NULL,
|
|
public_key TEXT NOT NULL,
|
|
fingerprint VARCHAR(80) NOT NULL,
|
|
created_at BIGINT NOT NULL,
|
|
UNIQUE KEY uniq_cloud_user_key (user_id, fingerprint)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE cloud_sessions (
|
|
id CHAR(64) NOT NULL PRIMARY KEY,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
version BIGINT NOT NULL,
|
|
fingerprint CHAR(64) NOT NULL,
|
|
auth_driver VARCHAR(16) NOT NULL,
|
|
auth_reference TEXT DEFAULT NULL,
|
|
active TINYINT(1) NOT NULL DEFAULT 1,
|
|
expires_at BIGINT NOT NULL,
|
|
created_at BIGINT NOT NULL,
|
|
UNIQUE KEY uniq_cloud_session_fingerprint (fingerprint),
|
|
KEY cloud_session_owner (user_id, active)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Browser console tickets are one-use, panel-owned mappings to the short-lived
|
|
-- Agent ticket. Only a purpose-bound sealed Agent ticket is stored at rest.
|
|
CREATE TABLE cloud_console_tickets (
|
|
ticket_hash CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
|
session_id CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
vm_uuid CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
sealed_agent_ticket LONGTEXT NOT NULL,
|
|
agent_expires_at BIGINT UNSIGNED NOT NULL,
|
|
ticket_expires_at BIGINT UNSIGNED NOT NULL,
|
|
connection_expires_at BIGINT UNSIGNED NOT NULL,
|
|
consumed_at BIGINT UNSIGNED DEFAULT NULL,
|
|
connection_id CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
KEY cloud_console_ticket_session_expiry (session_id, ticket_expires_at),
|
|
KEY cloud_console_ticket_connection_expiry (connection_id, connection_expires_at),
|
|
KEY cloud_console_ticket_instance (instance_id, created_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|