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.
1124 lines
61 KiB
SQL
1124 lines
61 KiB
SQL
-- Fresh-install cloud business tables. PHP is the sole writer of these records.
|
|
|
|
-- Retire the former host-inventory storage on upgrades. Capacity and IP
|
|
-- availability now come exclusively from panel policy, reservations and the
|
|
-- concrete IP ledger.
|
|
DROP TABLE IF EXISTS cloud_host_inventory_attempts;
|
|
DROP TABLE IF EXISTS cloud_host_capacity_snapshots;
|
|
|
|
ALTER TABLE ticket ADD INDEX IF NOT EXISTS
|
|
ticket_overview_root_status (rootid, status);
|
|
ALTER TABLE ticket ADD COLUMN IF NOT EXISTS
|
|
ticket_type VARCHAR(24) NOT NULL DEFAULT 'technical' AFTER status;
|
|
ALTER TABLE ticket ADD COLUMN IF NOT EXISTS
|
|
priority VARCHAR(8) NOT NULL DEFAULT 'medium' AFTER ticket_type;
|
|
ALTER TABLE ticket ADD COLUMN IF NOT EXISTS
|
|
instance_id BIGINT UNSIGNED NULL AFTER priority;
|
|
ALTER TABLE ticket ADD INDEX IF NOT EXISTS
|
|
ticket_instance (instance_id, userid, rootid);
|
|
CREATE TABLE IF NOT EXISTS ticket_attachments (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
ticket_id BIGINT UNSIGNED NOT NULL,
|
|
message_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
storage_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
original_name VARCHAR(180) NOT NULL DEFAULT '',
|
|
mime_type VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
bytes INT UNSIGNED NOT NULL DEFAULT 0,
|
|
sha256 CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
created_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
UNIQUE KEY ticket_attachment_storage_key (storage_key),
|
|
KEY ticket_attachment_ticket (ticket_id, message_id),
|
|
KEY ticket_attachment_user (user_id, created_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Public sales geography is independent from the engine host 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 IF NOT EXISTS 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;
|
|
|
|
-- The engine Fabric identity is platform-owned and is not derived from a
|
|
-- tenant request or from the mutable numeric region primary key. An active
|
|
-- region must have one explicit mapping before a tenant VPC can be created.
|
|
-- Fabric revisions are pinned into each VPC desired document and may only be
|
|
-- changed by an administrator after existing VPCs in that region are drained.
|
|
CREATE TABLE IF NOT EXISTS cloud_region_fabrics (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
region_id BIGINT UNSIGNED NOT NULL,
|
|
fabric_id VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
fabric_region VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
fabric_revision BIGINT UNSIGNED NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'active',
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_region_fabric_region (region_id),
|
|
UNIQUE KEY cloud_region_fabric_id (fabric_id),
|
|
KEY cloud_region_fabric_state (region_id, state, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_region_fabrics ADD COLUMN IF NOT EXISTS
|
|
fabric_region VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '' AFTER fabric_id;
|
|
|
|
-- 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 IF NOT EXISTS cloud_network_lines (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
region_id BIGINT UNSIGNED NOT 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)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS 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,
|
|
resource_pool_id BIGINT UNSIGNED DEFAULT NULL,
|
|
scheduler_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'disabled',
|
|
default_network VARCHAR(128) NOT NULL DEFAULT 'default',
|
|
created_at BIGINT NOT NULL,
|
|
updated_at BIGINT NOT NULL,
|
|
KEY cloud_host_name (name),
|
|
KEY cloud_host_scheduler (resource_pool_id, scheduler_state, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_hosts ADD COLUMN IF NOT EXISTS
|
|
resource_pool_id BIGINT UNSIGNED NULL AFTER enabled;
|
|
ALTER TABLE cloud_hosts ADD COLUMN IF NOT EXISTS
|
|
scheduler_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'disabled' AFTER resource_pool_id;
|
|
ALTER TABLE cloud_hosts DROP INDEX IF EXISTS cloud_host_scheduler;
|
|
ALTER TABLE cloud_hosts DROP COLUMN IF EXISTS health_error_code;
|
|
ALTER TABLE cloud_hosts DROP COLUMN IF EXISTS health_checked_at;
|
|
ALTER TABLE cloud_hosts DROP COLUMN IF EXISTS last_seen_at;
|
|
ALTER TABLE cloud_hosts DROP COLUMN IF EXISTS health_state;
|
|
ALTER TABLE cloud_hosts ADD INDEX IF NOT EXISTS
|
|
cloud_host_name (name);
|
|
ALTER TABLE cloud_hosts ADD INDEX IF NOT EXISTS
|
|
cloud_host_scheduler (resource_pool_id, scheduler_state, id);
|
|
|
|
-- A physical host may eventually participate in more than one commercial
|
|
-- resource pool. Compute capacity remains host-global; this relation only
|
|
-- controls which pools may schedule work onto the host. The first multi-CIDR
|
|
-- release keeps at most one active membership per host in application logic,
|
|
-- while the schema is already safe for a later multi-line rollout.
|
|
CREATE TABLE IF NOT EXISTS 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,
|
|
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-time compatibility import for hosts configured before membership rows
|
|
-- existed. Once any relation is present for a host, that relation is the
|
|
-- authority and rerunning cloudInit must never recreate a stale scalar link.
|
|
INSERT IGNORE INTO cloud_host_resource_pool_memberships
|
|
(host_id, resource_pool_id, scheduler_state, priority, weight, created_at, updated_at)
|
|
SELECT h.id, h.resource_pool_id,
|
|
CASE WHEN h.scheduler_state IN ('active', 'draining', 'disabled')
|
|
THEN h.scheduler_state ELSE 'disabled' END,
|
|
0, 100, GREATEST(0, h.created_at), GREATEST(0, h.updated_at)
|
|
FROM cloud_hosts AS h
|
|
LEFT JOIN cloud_host_resource_pool_memberships AS membership
|
|
ON membership.host_id = h.id
|
|
WHERE h.resource_pool_id IS NOT NULL AND membership.id IS NULL;
|
|
|
|
-- One attachment is one real host egress such as bridge:br0. Several CIDR
|
|
-- blocks may share the same attachment. Binding the attachment to a network
|
|
-- line keeps physical egress separate from compute capacity and lets a future
|
|
-- premium line use another bridge/VLAN without duplicating the host record.
|
|
CREATE TABLE IF NOT EXISTS 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 'bridge',
|
|
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,
|
|
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),
|
|
KEY cloud_host_network_attachment_line (host_id, line_id, state, priority, id),
|
|
KEY cloud_network_attachment_sync (sync_state, updated_at, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- 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 IF NOT EXISTS 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,
|
|
name VARCHAR(80) NOT NULL,
|
|
cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
gateway VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
guest_prefix_length TINYINT UNSIGNED NOT NULL,
|
|
dns_servers_json TEXT NOT NULL,
|
|
reserved_ips_json TEXT NOT NULL,
|
|
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, cidr),
|
|
KEY cloud_public_ip_pool_attachment (network_attachment_id, state, priority, id),
|
|
KEY cloud_public_ip_pool_sync (host_id, sync_state, updated_at, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Private VPC CIDRs are allocated from one configured global RFC1918 pool
|
|
-- (10.0.0.0/8 by default). Allocation uses /24 quantum claims rather than
|
|
-- a process-local or global application mutex: the unique block_cidr key is
|
|
-- the cross-worker serialization point. A /16 therefore claims 256 rows in
|
|
-- one transaction, while independent blocks can be allocated concurrently.
|
|
CREATE TABLE IF NOT EXISTS cloud_private_cidr_allocator_configs (
|
|
id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
pool_cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
quantum_prefix_length TINYINT UNSIGNED NOT NULL DEFAULT 24,
|
|
min_prefix_length TINYINT UNSIGNED NOT NULL DEFAULT 16,
|
|
max_prefix_length TINYINT UNSIGNED NOT NULL DEFAULT 24,
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
updated_at BIGINT UNSIGNED NOT NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
INSERT IGNORE INTO cloud_private_cidr_allocator_configs
|
|
(id, pool_cidr, quantum_prefix_length, min_prefix_length, max_prefix_length,
|
|
revision, updated_at)
|
|
VALUES (1, '10.0.0.0/8', 24, 16, 24, 1, UNIX_TIMESTAMP());
|
|
|
|
CREATE TABLE IF NOT EXISTS cloud_private_cidr_claims (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
block_cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
allocation_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_private_cidr_claim_block (block_cidr),
|
|
KEY cloud_private_cidr_claim_allocation (allocation_key, block_cidr)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- One row is one VPC network allocation. `network_address` and
|
|
-- `broadcast_address` make overlap checks explicit and indexable; the
|
|
-- canonical `active_cidr` unique key is an additional database guard for
|
|
-- exact duplicate claims. Interval overlap is serialized by the unique
|
|
-- quantum claims above because MariaDB has no exclusion constraint for
|
|
-- arbitrary ranges.
|
|
CREATE TABLE IF NOT EXISTS cloud_private_networks (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
vpc_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
allocation_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
region_id BIGINT UNSIGNED NOT NULL,
|
|
cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
requested_cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
active_cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
network_address BIGINT UNSIGNED NOT NULL,
|
|
broadcast_address BIGINT UNSIGNED NOT NULL,
|
|
prefix_length TINYINT UNSIGNED NOT NULL,
|
|
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,
|
|
released_at BIGINT UNSIGNED DEFAULT NULL,
|
|
UNIQUE KEY cloud_private_network_vpc_key (vpc_key),
|
|
UNIQUE KEY cloud_private_network_allocation_key (allocation_key),
|
|
UNIQUE KEY cloud_private_network_active_cidr (active_cidr),
|
|
KEY cloud_private_network_overlap (state, network_address, broadcast_address, id),
|
|
KEY cloud_private_network_region (region_id, state, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- VPC control-plane state is deliberately separate from the CIDR allocator
|
|
-- above and from the public-IP/network_change tables. The allocator row is
|
|
-- only an address reservation; this root row owns tenant intent, revisions,
|
|
-- and the observed activation gate.
|
|
CREATE TABLE IF NOT EXISTS 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,
|
|
private_network_id BIGINT UNSIGNED NOT NULL,
|
|
name VARCHAR(63) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
fabric_id VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
fabric_region VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '',
|
|
fabric_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
max_members INT UNSIGNED NOT NULL DEFAULT 256,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'applying',
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
observed_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 DEFAULT NULL,
|
|
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_key (vpc_key),
|
|
UNIQUE KEY cloud_vpc_private_network (private_network_id),
|
|
KEY cloud_vpc_fabric (fabric_id, fabric_revision, region_id),
|
|
KEY cloud_vpc_owner (user_id, state, id),
|
|
KEY cloud_vpc_region (region_id, state, id),
|
|
KEY cloud_vpc_sync (sync_state, updated_at, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_vpcs ADD COLUMN IF NOT EXISTS
|
|
fabric_id VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '' AFTER cidr;
|
|
ALTER TABLE cloud_vpcs ADD COLUMN IF NOT EXISTS
|
|
fabric_revision BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER fabric_id;
|
|
ALTER TABLE cloud_vpcs ADD COLUMN IF NOT EXISTS
|
|
fabric_region VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '' AFTER fabric_id;
|
|
ALTER TABLE cloud_vpcs ADD INDEX IF NOT EXISTS
|
|
cloud_vpc_fabric (fabric_id, fabric_revision, region_id);
|
|
|
|
-- Subnets are typed L3 ranges inside a VPC. No guest gateway, DHCP or RA is
|
|
-- implied; members receive exact /32 addresses in this ledger.
|
|
CREATE TABLE IF NOT EXISTS cloud_vpc_subnets (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
subnet_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
network_address BIGINT UNSIGNED NOT NULL,
|
|
broadcast_address BIGINT UNSIGNED NOT NULL,
|
|
prefix_length TINYINT UNSIGNED NOT NULL,
|
|
gateway_ip VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'applying',
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
observed_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
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,
|
|
UNIQUE KEY cloud_vpc_subnet_key (vpc_id, subnet_key),
|
|
UNIQUE KEY cloud_vpc_subnet_cidr (vpc_id, cidr),
|
|
KEY cloud_vpc_subnet_interval (vpc_id, network_address, broadcast_address, id),
|
|
KEY cloud_vpc_subnet_sync (vpc_id, desired_revision, observed_revision)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- A private address is its own durable lease, separate from the VM member
|
|
-- relation. Keeping the lease row lets deletion/reconciliation retain an
|
|
-- address tombstone even when the member row is being replaced, and gives
|
|
-- concurrent allocators a row/index lock independent of the public IP lane.
|
|
CREATE TABLE IF NOT EXISTS cloud_vpc_private_ips (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
ip_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
subnet_id BIGINT UNSIGNED NOT NULL,
|
|
member_id BIGINT UNSIGNED DEFAULT NULL,
|
|
instance_id BIGINT UNSIGNED DEFAULT NULL,
|
|
private_ip VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
private_ip_int BIGINT UNSIGNED NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'applying',
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
observed_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
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,
|
|
UNIQUE KEY cloud_vpc_private_ip_key (vpc_id, ip_key),
|
|
UNIQUE KEY cloud_vpc_private_ip_address (vpc_id, private_ip),
|
|
UNIQUE KEY cloud_vpc_private_ip_member (member_id),
|
|
KEY cloud_vpc_private_ip_subnet (vpc_id, subnet_id, state, private_ip_int),
|
|
KEY cloud_vpc_private_ip_instance (instance_id, state),
|
|
KEY cloud_vpc_private_ip_sync (vpc_id, desired_revision, observed_revision)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- One VM membership owns one exact private address. The instance, address and
|
|
-- lease-reference unique keys are database conflict points for concurrent
|
|
-- attach requests and for legacy rows during migration.
|
|
CREATE TABLE IF NOT EXISTS cloud_vpc_members (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
member_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
subnet_id BIGINT UNSIGNED NOT NULL,
|
|
private_ip_id BIGINT UNSIGNED DEFAULT NULL,
|
|
instance_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
private_ip VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
private_ip_int BIGINT UNSIGNED NOT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'applying',
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
observed_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
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,
|
|
UNIQUE KEY cloud_vpc_member_key (vpc_id, member_key),
|
|
UNIQUE KEY cloud_vpc_member_instance (vpc_id, instance_id),
|
|
UNIQUE KEY cloud_vpc_member_instance_global (instance_id),
|
|
UNIQUE KEY cloud_vpc_member_ip (vpc_id, private_ip),
|
|
UNIQUE KEY cloud_vpc_member_private_ip (private_ip_id),
|
|
KEY cloud_vpc_member_host (vpc_id, host_id, state, id),
|
|
KEY cloud_vpc_member_subnet (subnet_id, state, private_ip_int)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_vpc_members ADD COLUMN IF NOT EXISTS
|
|
private_ip_id BIGINT UNSIGNED NULL AFTER subnet_id;
|
|
ALTER TABLE cloud_vpc_members ADD UNIQUE INDEX IF NOT EXISTS
|
|
cloud_vpc_member_private_ip (private_ip_id);
|
|
|
|
-- Routes are restricted by the service to typed in-VPC destinations and a
|
|
-- member next hop. They are not a reuse of the public IP-change payload.
|
|
CREATE TABLE IF NOT EXISTS cloud_vpc_routes (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
route_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
member_id BIGINT UNSIGNED NOT NULL,
|
|
destination_cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
destination_int BIGINT UNSIGNED NOT NULL,
|
|
broadcast_int BIGINT UNSIGNED NOT NULL,
|
|
prefix_length TINYINT UNSIGNED NOT NULL,
|
|
next_hop_ip VARCHAR(15) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
metric SMALLINT UNSIGNED NOT NULL DEFAULT 100,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'applying',
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
observed_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
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,
|
|
UNIQUE KEY cloud_vpc_route_key (vpc_id, route_key),
|
|
UNIQUE KEY cloud_vpc_route_destination (vpc_id, destination_cidr),
|
|
KEY cloud_vpc_route_sync (vpc_id, desired_revision, observed_revision)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Private ACL intent is a typed DTO. The engine later renders it into its
|
|
-- own nftables context; no public0 nwfilter or raw host rule is stored here.
|
|
CREATE TABLE IF NOT EXISTS cloud_vpc_acl_rules (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
rule_key CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
priority INT UNSIGNED NOT NULL,
|
|
direction VARCHAR(8) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
action VARCHAR(8) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
protocol VARCHAR(8) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
source_int BIGINT UNSIGNED NOT NULL,
|
|
source_broadcast_int BIGINT UNSIGNED NOT NULL,
|
|
source_prefix_length TINYINT UNSIGNED NOT NULL,
|
|
destination_cidr VARCHAR(18) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
destination_int BIGINT UNSIGNED NOT NULL,
|
|
destination_broadcast_int BIGINT UNSIGNED NOT NULL,
|
|
destination_prefix_length TINYINT UNSIGNED NOT NULL,
|
|
port_from SMALLINT UNSIGNED DEFAULT NULL,
|
|
port_to SMALLINT UNSIGNED DEFAULT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'applying',
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
observed_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
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,
|
|
UNIQUE KEY cloud_vpc_acl_rule_key (vpc_id, rule_key),
|
|
UNIQUE KEY cloud_vpc_acl_priority (vpc_id, direction, priority),
|
|
KEY cloud_vpc_acl_sync (vpc_id, desired_revision, observed_revision)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_vpc_acl_rules ADD COLUMN IF NOT EXISTS
|
|
source_int BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER source_cidr;
|
|
ALTER TABLE cloud_vpc_acl_rules ADD COLUMN IF NOT EXISTS
|
|
source_broadcast_int BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER source_int;
|
|
ALTER TABLE cloud_vpc_acl_rules ADD COLUMN IF NOT EXISTS
|
|
source_prefix_length TINYINT UNSIGNED NOT NULL DEFAULT 0 AFTER source_broadcast_int;
|
|
ALTER TABLE cloud_vpc_acl_rules ADD COLUMN IF NOT EXISTS
|
|
destination_int BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER destination_cidr;
|
|
ALTER TABLE cloud_vpc_acl_rules ADD COLUMN IF NOT EXISTS
|
|
destination_broadcast_int BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER destination_int;
|
|
ALTER TABLE cloud_vpc_acl_rules ADD COLUMN IF NOT EXISTS
|
|
destination_prefix_length TINYINT UNSIGNED NOT NULL DEFAULT 0 AFTER destination_broadcast_int;
|
|
|
|
-- A VPC can span several hosts. This row is the all-host observed gate used
|
|
-- by the worker; a root VPC is never marked active from one host alone.
|
|
CREATE TABLE IF NOT EXISTS cloud_vpc_host_deployments (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
fabric_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
fabric_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
desired_revision BIGINT UNSIGNED NOT NULL DEFAULT 1,
|
|
observed_revision BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
desired_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
observed_digest CHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'applying',
|
|
last_operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
last_error_code VARCHAR(64) 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,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
UNIQUE KEY cloud_vpc_host_deployment (vpc_id, host_id),
|
|
KEY cloud_vpc_host_sync (host_id, state, desired_revision, observed_revision)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
|
|
-- Long-lived control-plane operations have their own lease/status lane. The
|
|
-- public CloudJob/network_change worker never claims these rows.
|
|
CREATE TABLE IF NOT EXISTS cloud_vpc_operations (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
operation_id CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
vpc_id BIGINT UNSIGNED NOT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
kind VARCHAR(24) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
desired_revision BIGINT UNSIGNED NOT NULL,
|
|
idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
request_hash CHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
|
|
status VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'queued',
|
|
payload_json LONGTEXT NOT NULL,
|
|
observed_json LONGTEXT DEFAULT NULL,
|
|
error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
finished_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,
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0,
|
|
UNIQUE KEY cloud_vpc_operation_id (operation_id),
|
|
UNIQUE KEY cloud_vpc_operation_idempotency (vpc_id, idempotency_key),
|
|
UNIQUE KEY cloud_vpc_operation_revision (vpc_id, desired_revision),
|
|
KEY cloud_vpc_operation_status (status, updated_at, id),
|
|
KEY cloud_vpc_operation_vpc (vpc_id, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_vpc_operations ADD COLUMN IF NOT EXISTS
|
|
idempotency_key VARCHAR(128) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '' AFTER desired_revision;
|
|
ALTER TABLE cloud_vpc_operations ADD COLUMN IF NOT EXISTS
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin NULL AFTER finished_at;
|
|
ALTER TABLE cloud_vpc_operations ADD COLUMN IF NOT EXISTS
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER lease_token;
|
|
ALTER TABLE cloud_vpc_operations ADD COLUMN IF NOT EXISTS
|
|
attempts INT UNSIGNED NOT NULL DEFAULT 0 AFTER lease_until;
|
|
ALTER TABLE cloud_vpc_operations ADD UNIQUE INDEX IF NOT EXISTS
|
|
cloud_vpc_operation_idempotency (vpc_id, idempotency_key);
|
|
|
|
-- 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 IF NOT EXISTS 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 private engine still validates the claim on the selected host. An
|
|
-- uncertain operation keeps the address unavailable until reconciliation.
|
|
CREATE TABLE IF NOT EXISTS 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 VARCHAR(45) CHARACTER SET ascii COLLATE ascii_bin 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,
|
|
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),
|
|
KEY cloud_public_ip_available (host_id, state, id),
|
|
KEY cloud_public_ip_pool_available (public_ip_pool_id, state, id),
|
|
UNIQUE KEY cloud_public_ip_reservation (reservation_id),
|
|
KEY cloud_public_ip_instance (instance_id),
|
|
UNIQUE KEY cloud_public_ip_operation (operation_id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_public_ips ADD COLUMN IF NOT EXISTS
|
|
public_ip_pool_id BIGINT UNSIGNED NULL AFTER host_id;
|
|
ALTER TABLE cloud_public_ips ADD INDEX IF NOT EXISTS
|
|
cloud_public_ip_pool_available (public_ip_pool_id, state, id);
|
|
|
|
-- 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 IF NOT EXISTS 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,
|
|
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;
|
|
CREATE TABLE IF NOT EXISTS cloud_template_retirements (
|
|
template_id VARCHAR(80) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
|
state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'deleting',
|
|
template_created_at BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
|
created_at BIGINT UNSIGNED NOT NULL,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
KEY cloud_template_retirement_state (state, updated_at)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_template_retirements ADD COLUMN IF NOT EXISTS
|
|
template_created_at BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER state;
|
|
CREATE TABLE IF NOT EXISTS cloud_template_catalog_locks (
|
|
id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
|
|
updated_at BIGINT UNSIGNED NOT NULL,
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
lease_kind VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_template_catalog_locks ADD COLUMN IF NOT EXISTS
|
|
lease_token CHAR(32) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL AFTER updated_at;
|
|
ALTER TABLE cloud_template_catalog_locks ADD COLUMN IF NOT EXISTS
|
|
lease_kind VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL AFTER lease_token;
|
|
ALTER TABLE cloud_template_catalog_locks ADD COLUMN IF NOT EXISTS
|
|
lease_until BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER lease_kind;
|
|
INSERT IGNORE INTO cloud_template_catalog_locks (id, updated_at) VALUES (1, 0);
|
|
ALTER TABLE cloud_hosts ADD COLUMN IF NOT EXISTS
|
|
country_code CHAR(2) NOT NULL DEFAULT '' AFTER region;
|
|
CREATE TABLE IF NOT EXISTS 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,
|
|
credential_cipher 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;
|
|
ALTER TABLE cloud_instances ADD COLUMN IF NOT EXISTS
|
|
offer_id BIGINT UNSIGNED NULL AFTER plan_id;
|
|
ALTER TABLE cloud_instances ADD COLUMN IF NOT EXISTS
|
|
resource_pool_id BIGINT UNSIGNED NULL AFTER offer_id;
|
|
ALTER TABLE cloud_instances ADD COLUMN IF NOT EXISTS
|
|
reservation_id BIGINT UNSIGNED NULL AFTER resource_pool_id;
|
|
ALTER TABLE cloud_instances ADD UNIQUE INDEX IF NOT EXISTS
|
|
uniq_cloud_instance_reservation (reservation_id);
|
|
ALTER TABLE cloud_instances ADD INDEX IF NOT EXISTS
|
|
cloud_instance_placement (resource_pool_id, host_id, status);
|
|
-- 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 libvirt XML or host commands).
|
|
CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS 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 IF NOT EXISTS 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(18) 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 IF NOT EXISTS 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 IF NOT EXISTS 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; engine volume names and host paths never
|
|
-- cross into the business database or tenant API.
|
|
CREATE TABLE IF NOT EXISTS 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;
|
|
-- Last-known engine power state for fast instance-list first paint. This is
|
|
-- an observation cache only; cloud_instances remains the lifecycle source of
|
|
-- truth and the engine remains authoritative for the current power state.
|
|
CREATE TABLE IF NOT EXISTS 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;
|
|
ALTER TABLE cloud_instance_runtime ADD COLUMN IF NOT EXISTS
|
|
power_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'unknown' AFTER uuid;
|
|
ALTER TABLE cloud_instance_runtime ADD COLUMN IF NOT EXISTS
|
|
sync_state VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'never' AFTER power_state;
|
|
ALTER TABLE cloud_instance_runtime ADD COLUMN IF NOT EXISTS
|
|
last_success_at BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER sync_state;
|
|
ALTER TABLE cloud_instance_runtime ADD COLUMN IF NOT EXISTS
|
|
last_attempt_at BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER last_success_at;
|
|
ALTER TABLE cloud_instance_runtime ADD COLUMN IF NOT EXISTS
|
|
revision BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER last_attempt_at;
|
|
ALTER TABLE cloud_instance_runtime ADD COLUMN IF NOT EXISTS
|
|
last_error_code VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '' AFTER revision;
|
|
ALTER TABLE cloud_instance_runtime ADD COLUMN IF NOT EXISTS
|
|
created_at BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER last_error_code;
|
|
ALTER TABLE cloud_instance_runtime ADD COLUMN IF NOT EXISTS
|
|
updated_at BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER created_at;
|
|
ALTER TABLE cloud_instance_runtime ADD UNIQUE INDEX IF NOT EXISTS
|
|
cloud_instance_runtime_identity (host_id, uuid);
|
|
ALTER TABLE cloud_instance_runtime ADD INDEX IF NOT EXISTS
|
|
cloud_instance_runtime_sync (sync_state, last_success_at);
|
|
ALTER TABLE cloud_instance_runtime ADD INDEX IF NOT EXISTS
|
|
cloud_instance_runtime_host (host_id, updated_at);
|
|
CREATE TABLE IF NOT EXISTS 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,
|
|
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,
|
|
payload_cipher 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)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_orders MODIFY host_id BIGINT UNSIGNED NULL;
|
|
ALTER TABLE cloud_orders ADD COLUMN IF NOT EXISTS
|
|
offer_id BIGINT UNSIGNED NULL AFTER plan_id;
|
|
ALTER TABLE cloud_orders ADD COLUMN IF NOT EXISTS
|
|
resource_pool_id BIGINT UNSIGNED NULL AFTER offer_id;
|
|
ALTER TABLE cloud_orders ADD COLUMN IF NOT EXISTS
|
|
reservation_id BIGINT UNSIGNED NULL AFTER host_id;
|
|
ALTER TABLE cloud_orders ADD COLUMN IF NOT EXISTS
|
|
currency CHAR(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'USD' AFTER amount;
|
|
ALTER TABLE cloud_orders ADD UNIQUE INDEX IF NOT EXISTS
|
|
uniq_cloud_order_reservation (reservation_id);
|
|
ALTER TABLE cloud_orders ADD INDEX IF NOT EXISTS
|
|
cloud_order_offer_state (offer_id, status, id);
|
|
ALTER TABLE cloud_orders ADD INDEX IF NOT EXISTS
|
|
cloud_order_placement (resource_pool_id, host_id, status);
|
|
|
|
-- 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 engine round trip.
|
|
CREATE TABLE IF NOT EXISTS 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 NOT NULL,
|
|
offer_id BIGINT UNSIGNED NOT 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),
|
|
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)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_resource_reservations ADD COLUMN IF NOT EXISTS
|
|
network_attachment_id BIGINT UNSIGNED NULL AFTER instance_id;
|
|
ALTER TABLE cloud_resource_reservations ADD COLUMN IF NOT EXISTS
|
|
public_ip_pool_id BIGINT UNSIGNED NULL AFTER network_attachment_id;
|
|
ALTER TABLE cloud_resource_reservations ADD INDEX IF NOT EXISTS
|
|
cloud_resource_reservation_network (network_attachment_id, public_ip_pool_id);
|
|
CREATE TABLE IF NOT EXISTS 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,
|
|
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)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS 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)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_invoices ADD COLUMN IF NOT EXISTS
|
|
offer_id BIGINT UNSIGNED NULL AFTER plan_id;
|
|
ALTER TABLE cloud_invoices ADD COLUMN IF NOT EXISTS
|
|
currency CHAR(3) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT 'USD' AFTER amount;
|
|
-- Releases created before void invoices became replaceable used a unique
|
|
-- period key. Keep void rows as an audit trail while permitting one corrected
|
|
-- replacement bill for the same expiry.
|
|
ALTER TABLE cloud_invoices DROP INDEX IF EXISTS uniq_cloud_invoice_period;
|
|
ALTER TABLE cloud_invoices ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_period (instance_id, renews_expires_at, status);
|
|
-- Upgrade an existing installation so unpaid provisioning requests can live
|
|
-- behind an invoice without fabricating an instance or expiry timestamp.
|
|
ALTER TABLE cloud_orders ADD COLUMN IF NOT EXISTS payload_cipher LONGTEXT NULL AFTER spec_json;
|
|
ALTER TABLE cloud_orders ADD COLUMN IF NOT EXISTS stock_reserved_at BIGINT UNSIGNED NULL AFTER refunded_at;
|
|
ALTER TABLE cloud_orders ADD COLUMN IF NOT EXISTS stock_released_at BIGINT UNSIGNED NULL AFTER stock_reserved_at;
|
|
ALTER TABLE cloud_invoices ADD COLUMN IF NOT EXISTS purpose VARCHAR(16) NOT NULL DEFAULT 'renewal' AFTER invoice_no;
|
|
ALTER TABLE cloud_invoices MODIFY instance_id BIGINT UNSIGNED NULL;
|
|
ALTER TABLE cloud_invoices ADD COLUMN IF NOT EXISTS order_id BIGINT UNSIGNED NULL AFTER instance_id;
|
|
ALTER TABLE cloud_invoices MODIFY renews_expires_at BIGINT UNSIGNED NULL;
|
|
ALTER TABLE cloud_invoices ADD UNIQUE INDEX IF NOT EXISTS uniq_cloud_invoice_order (order_id);
|
|
ALTER TABLE cloud_invoices ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_admin_created (created_at, id);
|
|
ALTER TABLE cloud_invoices ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_admin_status (status, created_at, id);
|
|
ALTER TABLE cloud_invoices ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_admin_purpose (purpose, created_at, id);
|
|
ALTER TABLE cloud_invoices ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_admin_user (user_id, created_at, id);
|
|
ALTER TABLE cloud_invoices ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_admin_method (paid_via, created_at, id);
|
|
ALTER TABLE cloud_invoices ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_overview_paid (status, paid_at, purpose, plan_id);
|
|
ALTER TABLE cloud_orders ADD INDEX IF NOT EXISTS
|
|
cloud_order_admin_created (created_at, id);
|
|
ALTER TABLE cloud_orders ADD INDEX IF NOT EXISTS
|
|
cloud_order_admin_status (status, created_at, id);
|
|
ALTER TABLE cloud_orders ADD INDEX IF NOT EXISTS
|
|
cloud_order_admin_user (user_id, created_at, id);
|
|
CREATE TABLE IF NOT EXISTS 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)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_invoice_payments ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_payment_admin_created (created_at, id);
|
|
ALTER TABLE cloud_invoice_payments ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_payment_admin_status (status, created_at, id);
|
|
ALTER TABLE cloud_invoice_payments ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_payment_admin_provider (provider, created_at, id);
|
|
ALTER TABLE cloud_invoice_payments ADD INDEX IF NOT EXISTS
|
|
cloud_invoice_payment_admin_user (user_id, created_at, id);
|
|
CREATE TABLE IF NOT EXISTS 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;
|
|
CREATE TABLE IF NOT EXISTS cloud_jobs (
|
|
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
operation_id CHAR(32) NOT NULL,
|
|
order_id BIGINT UNSIGNED DEFAULT NULL,
|
|
instance_id BIGINT UNSIGNED DEFAULT NULL,
|
|
snapshot_id BIGINT UNSIGNED DEFAULT NULL,
|
|
user_id BIGINT UNSIGNED NOT NULL,
|
|
host_id BIGINT UNSIGNED NOT NULL,
|
|
kind VARCHAR(32) NOT NULL,
|
|
status VARCHAR(32) NOT NULL DEFAULT 'queued',
|
|
payload_cipher LONGTEXT NOT NULL,
|
|
attempts INT NOT NULL DEFAULT 0,
|
|
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_provision_order (order_id),
|
|
KEY cloud_job_poll (status, available_at, lease_until),
|
|
KEY cloud_job_instance_state (instance_id, status, id),
|
|
KEY cloud_job_snapshot (snapshot_id, id),
|
|
KEY cloud_job_overview_status_updated (status, updated_at),
|
|
KEY cloud_job_overview_kind_created (kind, created_at),
|
|
KEY cloud_job_owner (user_id, id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
ALTER TABLE cloud_jobs ADD COLUMN IF NOT EXISTS
|
|
snapshot_id BIGINT UNSIGNED NULL AFTER instance_id;
|
|
ALTER TABLE cloud_jobs ADD INDEX IF NOT EXISTS
|
|
cloud_job_snapshot (snapshot_id, id);
|
|
ALTER TABLE cloud_jobs ADD INDEX IF NOT EXISTS
|
|
cloud_job_overview_status_updated (status, updated_at);
|
|
ALTER TABLE cloud_jobs ADD INDEX IF NOT EXISTS
|
|
cloud_job_overview_kind_created (kind, created_at);
|
|
CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS 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;
|