38676-vm/db/migrate_units.php
2026-03-07 02:50:28 +00:00

37 lines
1.3 KiB
PHP

<?php
require_once __DIR__ . '/config.php';
$db = db();
try {
$db->exec("CREATE TABLE IF NOT EXISTS units (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
slug VARCHAR(255) NOT NULL UNIQUE,
image_url VARCHAR(255) NULL,
grid_data TEXT NULL,
faction_id INT NULL,
can_be_destroyed TINYINT(1) DEFAULT 0,
can_be_captured TINYINT(1) DEFAULT 0,
points_per_hit INT DEFAULT 1,
bonus_destruction INT DEFAULT 0,
bonus_capture INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (faction_id) REFERENCES factions(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
$db->exec("CREATE TABLE IF NOT EXISTS unit_rewards (
id INT AUTO_INCREMENT PRIMARY KEY,
unit_id INT NOT NULL,
action_type ENUM('destroy', 'capture') NOT NULL,
resource_id INT NOT NULL,
amount INT NOT NULL,
FOREIGN KEY (unit_id) REFERENCES units(id) ON DELETE CASCADE,
FOREIGN KEY (resource_id) REFERENCES game_resources(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
echo "Migration completed: units and unit_rewards tables created.\n";
} catch (PDOException $e) {
die("Migration failed: " . $e->getMessage() . "\n");
}