Scalr\Upgrade\Updates\Update20150827140744::run1 PHP Метод

run1() защищенный Метод

protected run1 ( $stage )
    protected function run1($stage)
    {
        $this->console->out("Creating servers_history_tmp table.");
        $this->db->Execute("CREATE TABLE servers_history_tmp LIKE servers_history");
        $this->console->out("Make changes to tmp table.");
        $this->db->Execute("\n            ALTER TABLE servers_history_tmp\n                DROP COLUMN id,\n                DROP PRIMARY KEY,\n                DROP INDEX server_id,\n                ADD PRIMARY KEY (server_id),\n                ADD COLUMN project_id binary(16) DEFAULT NULL AFTER cloud_location,\n                ADD COLUMN cc_id binary(16) DEFAULT NULL AFTER project_id,\n                ADD COLUMN instance_type_name VARCHAR(50) DEFAULT NULL AFTER cc_id,\n                ADD COLUMN role_id INT(11) DEFAULT NULL AFTER env_id,\n                ADD COLUMN farm_created_by_id INT(11) DEFAULT NULL AFTER farm_roleid,\n                ADD INDEX `idx_project_id` (project_id),\n                ADD INDEX `idx_cc_id` (cc_id),\n                MODIFY `server_id` VARCHAR(36) NOT NULL\n        ");
        $this->console->out("Swap table names.");
        $this->db->Execute("RENAME TABLE servers_history TO servers_history_backup, servers_history_tmp TO servers_history");
        $this->console->out("Initializing cloud_location in servers_history_backup table");
        $this->db->Execute("\n            UPDATE servers_history_backup h, farm_roles r\n            SET h.cloud_location = r.cloud_location\n            WHERE r.id = h.farm_roleid AND h.cloud_location IS NULL AND r.id > 0;");
        $this->console->out("Insert data from backup table to new servers_history.");
        $this->db->Execute("\n            INSERT IGNORE INTO servers_history (\n                    client_id, server_id, cloud_server_id, cloud_location,\n                    dtlaunched, dtterminated, launch_reason_id, launch_reason,\n                    terminate_reason_id, terminate_reason, platform, `type`,\n                    env_id, farm_id, farm_roleid, server_index,\n                    scu_used,scu_reported, scu_updated, scu_collecting)\n                SELECT client_id, server_id, cloud_server_id, cloud_location,\n                       dtlaunched, dtterminated, launch_reason_id, launch_reason,\n                       terminate_reason_id, terminate_reason, platform, `type`,\n                       env_id, farm_id, farm_roleid, server_index,\n                       scu_used, scu_reported, scu_updated, scu_collecting\n                FROM servers_history_backup\n                ORDER BY id DESC");
        $this->console->out("Drop backup table.");
        $this->db->Execute("DROP TABLE IF EXISTS servers_history_backup");
    }