Commit 6cd11736 authored by Thomas Goirand's avatar Thomas Goirand

Switch to a db migration system with the schema saved in PHP format.

parent 7aa7ec0e
......@@ -14,6 +14,7 @@ openstack-cluster-installer (21) UNRELEASED; urgency=medium
* Add some sysctl customization (low swappiness, higher conntrack, etc.).
* Provision ssh public / private keypair between nova nodes in the
/var/lib/nova/.ssh folder, to allow (live) migration using ssh / scp.
* Switch to a db migration system with the schema saved in PHP format.
[ Oliver Chaze ]
* swift: do not log in syslog general logs
......
#!/usr/bin/env php
<?php
require_once("inc/read_conf.php");
require_once("inc/db.php");
$conf = readmyconf();
$con = connectme($conf);
if(isset($_SERVER['REMOTE_ADDR'])){
die("This script should be invoked from the shell, not from the web.");
}
$q = "SHOW TABLES";
$result = mysqli_query($con, $q)or die("Cannot query \"$q\" !\nError in ".__FILE__." line ".__LINE__.": ".mysqli_error($con));
if (!$result) {
echo "DB Error, could not list tables\n";
echo 'MySQL Error: ' . mysqli_error($con);
exit;
}
$out = "";
$out .= "<?php
// Automatic database array generation for OCI
// Generation date: ".date("Y-m(M)-d l H:i")."
\$database = array(
\"version\" => \"1.0.0\",
\"tables\" => array(\n";
$num = mysqli_num_rows($result);
for($j=0;$j<$num;$j++){
$row = mysqli_fetch_row($result);
$out .= "\t\"$row[0]\" => array(\n";
$q = "DESCRIBE $row[0];";
$r = mysqli_query($con, $q)or die("Cannot query \"$q\" !\nError in ".__FILE__." line ".__LINE__.": ".mysqli_error($con));
$n = mysqli_num_rows($r);
$out .= "\t\t\"vars\" => array(\n";
for($i=0;$i<$n;$i++){
$a = mysqli_fetch_array($r);
$out .= "\t\t\t\"".$a['Field']."\" => \"".$a['Type'];
$qshow = "SHOW FULL COLUMNS FROM $row[0] WHERE Field='".$a['Field']."'";
$rshow = mysqli_query($con, $qshow)or die("Cannot query \"$qshow\" !\nError in ".__FILE__." line ".__LINE__.": ".mysqli_error($con));
$myfield = mysqli_fetch_array($rshow);
$a_type = $myfield["Type"];
$a_extra = $myfield["Extra"];
if(isset($myfield["Collation"])){
$a_collate = $myfield["Collation"];
}
switch($a_type){
case "text":
$q2 = "SELECT character_set_name FROM information_schema.`COLUMNS` WHERE table_name = '".$row[0]."' AND column_name = '".$a['Field']."'";
$r2 = mysqli_query($con, $q2)or die("Cannot execute query: \"$q2\" line ".__LINE__." in file ".__FILE__.", mysql said: ".mysqli_error($con));
$a2 = mysqli_fetch_array($r2);
if($a2["character_set_name"] != 'latin1'){
$out .= ' character set '.$a2["character_set_name"];
}
mysqli_free_result($r2);
if($a_collate != 'latin1_bin'){
$out .= ' collate '.$a_collate;
}
break;
default:
if($a['Null'] == 'YES'){
$out .= " NULL";
if($a['Default'] == NULL){
$out .= " default NULL";
}
}else{
$out .= " NOT NULL";
if($a['Extra'] != ''){
$out .= " ".$a['Extra'];
}else{
if($a['Default'] == "NULL" && $a["Extra"] == ''){
$out .= " default ''";
}else{
$out .= " default '".$a['Default']."'";
}
}
}
break;
}
$out .= "\"";
if($i < $n-1)
$out .= ",\n";
else
$out .= "\n\t\t\t)";
}
$q = "SHOW INDEX FROM $row[0];";
$r = mysqli_query($con, $q)or die("Cannot query \"$q\" !\nError in ".__FILE__." line ".__LINE__.": ".mysqli_error($con));
$n = mysqli_num_rows($r);
if($i > 0){
$out .= ",\n";
// Get all the keys and index in memory for the given table
unset($primaries);
unset($keys);
unset($indexes);
for($i=0;$i<$n;$i++){
$a = mysqli_fetch_array($r);
if($a['Key_name'] == "PRIMARY"){
$primaries[] = $a['Column_name'];
}else{
if($a['Non_unique'] == "0"){
$keys[ $a['Key_name'] ][] = $a['Column_name'];
}else{
$indexes[ $a['Key_name'] ][] = $a['Column_name'];
}
}
}
// Produce the array of index and keys
if(sizeof($primaries) > 0){
$out .= "\t\t\"primary\" => \"(".$primaries[0];
// Display all the keys here...
for($i=1;$i<sizeof($primaries);$i++){
$out .= ",".$primaries[$i];
}
$out .= ")\"";
if( (isset($keys) && sizeof($keys) > 0) || (isset($indexes) && sizeof($indexes) > 0)){
$out .= ",\n";
}else{
$out .= "\n";
}
}
if(isset($keys) && sizeof($keys) > 0){
$out .= "\t\t\"keys\" => array(\n";
// Backup all the UNIC keys here
$kkeys = @array_keys($keys);
for($i=0;$i<sizeof($kkeys);$i++){
$cur = $keys[ $kkeys[$i] ];
$out .= "\t\t\t\"".$kkeys[$i]."\" => \"(";
for($k=0;$k<sizeof($cur);$k++){
if($k>0) $out .= ",";
$out .= $cur[$k];
}
if($i<sizeof($kkeys)-1)
$out .= ")\",\n";
else
$out .= ")\"\n";
}
$out .= "\t\t\t)";
if(isset($indexes) && sizeof($indexes) > 0){
$out .= ",\n";
}else{
$out .= "\n";
}
}
if(isset($indexes) && sizeof($indexes) > 0){
$out .= "\t\t\"index\" => array(\n";
// Backup all the INDEX keys here
$kkeys = @array_keys($indexes);
for($i=0;$i<sizeof($kkeys);$i++){
$cur = $indexes[ $kkeys[$i] ];
$out .= "\t\t\t\"".$kkeys[$i]."\" => \"(";
for($k=0;$k<sizeof($cur);$k++){
if($k>0) $out .= ",";
$out .= $cur[$k];
}
if($i<sizeof($kkeys)-1)
$out .= ")\",\n";
else
$out .= ")\"\n";
}
$out .= "\t\t\t)\n";
}
}else{
$out .= "\n";
}
if($j < $num-1)
$out .= "\t\t),\n";
else
$out .= "\t\t)\n";
mysqli_free_result($r);
}
$out .= "\t)\n);\n?>\n";
mysqli_free_result($result);
$fp = fopen("oci_db.php","w+b");
fwrite($fp,$out);
fclose($fp);
?>
\ No newline at end of file
This diff is collapsed.
<?php
// Automatic database array generation for OCI
// Generation date: 2019-03(Mar)-14 Thursday 14:42
$database = array(
"version" => "1.0.0",
"tables" => array(
"blockdevices" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"machine_id" => "int(11) NOT NULL default ''",
"name" => "varchar(255) NOT NULL default ''",
"size_mb" => "int(11) NOT NULL default ''"
),
"primary" => "(id)"
),
"clusters" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"name" => "varchar(64) NOT NULL default ''",
"domain" => "varchar(253) NOT NULL default ''",
"vip_hostname" => "varchar(255) NOT NULL default ''",
"first_master_machine_id" => "int(11) NULL default NULL",
"swift_part_power" => "int(11) NOT NULL default '18'",
"swift_replicas" => "int(11) NOT NULL default '3'",
"swift_min_part_hours" => "int(11) NOT NULL default '1'",
"swift_proxy_hostname" => "varchar(255) NOT NULL default ''",
"swift_encryption_key_id" => "varchar(255) NOT NULL default ''",
"haproxy_custom_url" => "varchar(255) NOT NULL default ''",
"statsd_hostname" => "varchar(255) NOT NULL default ''"
),
"primary" => "(id)",
"keys" => array(
"name" => "(name)"
)
),
"ifnames" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"machine_id" => "int(11) NOT NULL default ''",
"name" => "varchar(255) NOT NULL default ''",
"macaddr" => "varchar(20) NOT NULL default ''",
"max_speed" => "int(11) NOT NULL default '10'"
),
"primary" => "(id)"
),
"ips" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"network" => "int(11) NOT NULL default ''",
"ip" => "bigint(128) NOT NULL default ''",
"type" => "enum('4','6') NOT NULL default '4'",
"machine" => "int(11) NOT NULL default ''",
"usefor" => "enum('machine','vip') NOT NULL default 'machine'"
),
"primary" => "(id)",
"keys" => array(
"uniqueip" => "(ip)",
"uniquemachine" => "(network,machine)"
)
),
"locations" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"name" => "varchar(64) NOT NULL default ''",
"swiftregion" => "varchar(64) NOT NULL default ''"
),
"primary" => "(id)",
"keys" => array(
"uniquename" => "(name)"
)
),
"machines" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"memory" => "int(11) NOT NULL default ''",
"ipaddr" => "varchar(255) NOT NULL default ''",
"serial" => "varchar(128) NOT NULL default ''",
"product_name" => "varchar(128) NOT NULL default ''",
"hostname" => "varchar(255) NOT NULL default ''",
"installed" => "enum('yes','no') NOT NULL default 'no'",
"lastseen" => "timestamp NOT NULL default 'CURRENT_TIMESTAMP'",
"status" => "varchar(128) NOT NULL default 'None'",
"role" => "varchar(64) NOT NULL default ''",
"cluster" => "int(11) NULL default NULL",
"ipmi_use" => "enum('yes','no') NOT NULL default 'no'",
"ipmi_call_chassis_bootdev" => "enum('yes','no') NOT NULL default 'no'",
"ipmi_addr" => "varchar(254) NOT NULL default ''",
"ipmi_port" => "int(11) NOT NULL default '623'",
"ipmi_username" => "varchar(64) NOT NULL default ''",
"ipmi_password" => "varchar(64) NOT NULL default ''",
"location_id" => "int(11) NULL default NULL",
"notes" => "varchar(256) NOT NULL default ''",
"ladvd_report" => "varchar(128) NOT NULL default ''",
"bios_version" => "varchar(128) NOT NULL default ''",
"ipmi_firmware_version" => "varchar(128) NOT NULL default ''",
"ipmi_detected_ip" => "varchar(64) NOT NULL default ''",
"use_ceph_if_available" => "enum('yes','no') NOT NULL default 'no'"
),
"primary" => "(id)",
"keys" => array(
"serial" => "(serial)"
)
),
"networks" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"name" => "varchar(128) NOT NULL default ''",
"ip" => "varchar(64) NOT NULL default ''",
"cidr" => "int(3) NOT NULL default ''",
"is_public" => "enum('yes','no') NOT NULL default 'no'",
"cluster" => "int(11) NULL default NULL",
"role" => "varchar(64) NULL default NULL",
"iface1" => "varchar(32) NULL default NULL",
"iface2" => "varchar(32) NULL default NULL",
"bridgename" => "varchar(32) NULL default NULL",
"vlan" => "int(11) NULL default NULL",
"mtu" => "int(11) NOT NULL default '0'",
"location_id" => "int(11) NULL default NULL"
),
"primary" => "(id)",
"keys" => array(
"name" => "(name)"
)
),
"passwords" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"cluster" => "int(11) NOT NULL default ''",
"service" => "varchar(64) NOT NULL default ''",
"passtype" => "varchar(64) NOT NULL default ''",
"pass" => "varchar(128) NOT NULL default ''",
"passtxt1" => "text character set utf8 collate utf8_unicode_ci",
"passtxt2" => "text character set utf8 collate utf8_unicode_ci"
),
"primary" => "(id)"
),
"rolecounts" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"cluster" => "int(11) NOT NULL default ''",
"role" => "int(11) NOT NULL default ''",
"count" => "int(11) NOT NULL default ''"
),
"primary" => "(id)",
"keys" => array(
"cluster" => "(cluster,role)"
)
),
"roles" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"name" => "varchar(64) NOT NULL default ''"
),
"primary" => "(id)",
"keys" => array(
"name" => "(name)"
)
),
"swiftregions" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"name" => "varchar(64) NOT NULL default ''"
),
"primary" => "(id)",
"keys" => array(
"name" => "(name)"
)
),
"users" => array(
"vars" => array(
"id" => "int(11) NOT NULL auto_increment",
"login" => "varchar(128) NOT NULL default ''",
"hashed_password" => "varchar(128) NOT NULL default ''",
"use_radius" => "enum('yes','no') NOT NULL default 'yes'",
"activated" => "enum('yes','no') NOT NULL default 'yes'",
"is_admin" => "enum('yes','no') NOT NULL default 'no'"
),
"primary" => "(id)",
"keys" => array(
"name" => "(login)"
)
)
)
);
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment