<?php /* * WiND - Wireless Nodes Database * * Copyright (C) 2005-2014 by WiND Contributors (see AUTHORS.txt) * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ $update = new DBUpdateDescriptor(new SchemaVersion(1, 1), new SchemaVersion(1, 2)); /****************************************** * CNAME database changes */ // TABLE ip_cname $tb = $update->newTable('ip_cname'); $tb->addColumn('id', 'int unsigned', array('not_null' => true, 'ai' => true, 'pk' => true)); $tb->addColumn('date_in', 'datetime', array('not_null' => true, 'default' => "'0000-00-00 00:00:00'")); $tb->addColumn('node_id', 'int unsigned', array('not_null' => true, 'default' => '0', 'unique' => true)); $tb->addColumn('hostname', 'varchar(50)', array('not_null' => true, 'default' => '')); $tb->addColumn('cname', 'varchar(50)', array('not_null' => true, 'default' => '')); $tb->addColumn('info', 'text'); return $update;
* * Copyright (C) 2005-2014 by WiND Contributors (see AUTHORS.txt) * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ $update = new DBUpdateDescriptor(new SchemaVersion(1, 1), new SchemaVersion(1, 2)); /****************************************** * CNAME database changes */ // TABLE ip_cname $tb = $update->newTable('ip_cname'); $tb->addColumn('id', 'int unsigned', array('not_null' => true, 'ai' => true, 'pk' => true)); $tb->addColumn('date_in', 'datetime', array('not_null' => true, 'default' => "'0000-00-00 00:00:00'")); $tb->addColumn('node_id', 'int unsigned', array('not_null' => true, 'default' => '0')); $tb->addColumn('hostname', 'varchar(50)', array('not_null' => true)); $tb->addColumn('cname', 'varchar(50)', array('not_null' => true)); $tb->addColumn('info', 'text'); /******************************************************* * Change IP columns to unsigned ints */ // areas $update->modifyColumn('areas', 'ip_start', 'ip_start', 'int unsigned', array('not_null' => true, 'default' => '0')); $update->modifyColumn('areas', 'ip_end', 'ip_end', 'int unsigned', array('not_null' => true, 'default' => '0'));
/** * @brief Apply a specific update on the database * @param DBUpdateDescriptor $update The update to apply */ public function applyUpdate($update) { printf("Upgrading DB Schema to %s...\n", $update->getTargetVersion()); $sql_commands = array(); // New tables foreach ($update->getNewTables() as $table) { $sql_commands[] = $table->getSQL(); } // New Column modifications foreach ($update->getNewColumns() as $columns) { $sql_commands[] = $columns->getSQL(); } // Modified Columns foreach ($update->getModifiedColumns() as $modification) { $sql_commands[] = $modification->getSQL(); } //Execute all SQL commands foreach ($sql_commands as $sql) { $res = $this->db_conn->query($sql); if (!$res) { printf($sql); throw new RuntimeException("Error executing SQL query: " . $this->db_conn->error); } } // Mark update log for this change $res = $this->db_conn->query("INSERT INTO `update_log` (`version_major`, `version_minor`) VALUES(" . "'" . $this->db_conn->real_escape_string($update->getTargetVersion()->getMajor()) . "'," . "'" . $this->db_conn->real_escape_string($update->getTargetVersion()->getMinor()) . "');"); if (!$res) { throw new RuntimeException("Error executing SQL query: " . $this->db_conn->error); } }
* * Copyright (C) 2005-2014 by WiND Contributors (see AUTHORS.txt) * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ $update = new DBUpdateDescriptor(new SchemaVersion(1, 0), new SchemaVersion(1, 1)); /****************************************** * IPv6 database changes */ // TABLE ipv6_node_repos $tb = $update->newTable('ipv6_node_repos'); $tb->addColumn('id', 'int unsigned', array('not_null' => true, 'ai' => true, 'pk' => true)); $tb->addColumn('area_id', 'int unsigned', array('not_null' => true, 'key' => true, 'default' => '0', 'unique' => false)); $tb->addColumn('node_id', 'int unsigned', array('not_null' => true, 'key' => true, 'default' => '0', 'unique' => false)); $tb->addColumn('v6net', 'varbinary(16)', array('not_null' => true, 'default' => '0', 'unique' => true)); // TABLE ipv6_area_repos $tb = $update->newTable('ipv6_area_repos'); $tb->addColumn('id', 'int unsigned', array('not_null' => true, 'ai' => true, 'pk' => true)); $tb->addColumn('area_id', 'int unsigned', array('not_null' => true, 'key' => true, 'default' => '0', 'unique' => false)); $tb->addColumn('region_id', 'int unsigned', array('not_null' => true, 'key' => true, 'default' => '0', 'unique' => false)); $tb->addColumn('v6net', 'varbinary(16)', array('not_null' => true, 'default' => '0', 'unique' => true)); // TABLE ip_ranges_v6
<?php /* * WiND - Wireless Nodes Database * * Copyright (C) 2005-2014 by WiND Contributors (see AUTHORS.txt) * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ $update = new DBUpdateDescriptor(new SchemaVersion(1, 2), new SchemaVersion(1, 3)); /****************************************** * ip_addresses database changes */ // column for zone_types // Note as default will be a text value, its purposely double quoted. $update->newColumn('ip_addresses', 'zone_type', "enum('forward', 'reverse', 'fwdNrev')", array('default' => "'fwdNrev'")); // add index key on node_id $update->modifyColumn('ip_cname', 'node_id', 'node_id', 'int unsigned', array('key' => true, 'not_null' => true, 'default' => '0')); return $update;