38676-vm/db/migrate_status_rules.php
2026-02-26 01:39:06 +00:00

31 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/config.php';
$db = db();
$sql = "
CREATE TABLE IF NOT EXISTS celestial_object_status_rules (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
status_id INT NOT NULL,
object_type_id INT NULL,
priority INT DEFAULT 0,
is_active TINYINT(1) DEFAULT 1,
condition_type ENUM('orbital_control', 'terrestrial_control', 'uncontrolled', 'fixed') NOT NULL DEFAULT 'fixed',
min_control_value FLOAT DEFAULT NULL,
max_control_value FLOAT DEFAULT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (status_id) REFERENCES celestial_object_statuses(id) ON DELETE CASCADE,
FOREIGN KEY (object_type_id) REFERENCES celestial_object_types(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
";
try {
$db->exec($sql);
echo "Table celestial_object_status_rules created successfully.\n";
} catch (PDOException $e) {
echo "Error creating table: " . $e->getMessage() . "\n";
}