Commit 75d8a6b9 authored by Leigh Stoller's avatar Leigh Stoller

Switch the DB migration method form instructions to database-migrate.txt,

to numbered update scripts. To install updates:

	boss> cd /your/srcdir/sql/updates
	boss> perl /your/objdir/db/dbupdate tbdb

For developers, please look in the sql/updates/4/1 file for an example
of how to do updates. For each revision in database-create.sql, create
a corresponding script and add it to the repository. The scripts will
be applied in numeric order (see db/dbupdate.in), starting with the
version recorded in the version_info table. This table is updated by
dbupdate as it runs each script.
parent d970b69b
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003, 2006 University of Utah and the Flux Group.
# Copyright (c) 2000-2009 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
......@@ -82,19 +82,22 @@ my $diff = (system("$schemadiff $db_schema $master_schema") >> 8);
unlink($db_schema);
if ($diff) {
my $objdir = `/bin/pwd`;
chomp($objdir);
print << "EOSTR";
The schema from $master_schema differs from
the running database. As a safety measure, you will not be able to install
until this is resolved.
the running database. As a safety measure, you will not be able to
install until this is resolved.
If you are a user of the emulab software outside of Utah, this is
probably because your database was created for an older version of the
emulab software. You can update your database by:
If you are a user of the emulab software outside of Utah, this is probably
because your database was created for an older version of the emulab software.
Contact testbed-ops\@eMulab.net for help in updating your database.
boss> cd /your/srcdir/sql/updates
boss> perl $objdir/dbupdate $DBNAME
If you're a developer at Utah, this is probably because you (or someone else)
forgot to update sql/database-create.sql .
Be sure look in /your/srcdir/doc/UPDATING for any other instructions.
EOSTR
......
......@@ -3465,6 +3465,17 @@ CREATE TABLE `v2pmap` (
UNIQUE KEY `pideid` (`pid`,`eid`,`vname`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Table structure for table `version_info`
--
DROP TABLE IF EXISTS `version_info`;
CREATE TABLE `version_info` (
`name` varchar(32) NOT NULL default '',
`value` tinytext NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Table structure for table `veth_interfaces`
--
......
......@@ -4575,124 +4575,18 @@ last_net_act,last_cpu_act,last_ext_act);
enum('0','10','100','1000','4000','10000','40000','100000') \
NOT NULL default '0';
4.161: Another protogeni addition to the reserved table.
NOTE: The above entry (4.160) is the last entry in this file. Database
updates are now scripted. After you have built your object tree,
please go to your src directory, and cd into the sql/updates subdir.
Then run the following:
alter table reserved add `tmcd_redirect` tinytext;
/your/objdir/db/dbupdate tbdb
4.162: Some stuff for prototyping widearea assignment of federated Emulabs.
For developers, please look in the updates/4/1 file for an example of
how to do updates. For each revision in database-create.sql, create a
corresponding script and add it to the repository. The scripts will be
applied in numeric order (see db/dbupdate.in), starting with the
version recorded in the version_info table. This table is updated by
dbupdate as it runs each script.
alter table nodes change `role` `role`
enum('testnode','virtnode','ctrlnode','testswitch',
'ctrlswitch','powerctrl','widearea_switch','unused')
NOT NULL default 'unused';
CREATE TABLE `widearea_switches` (
`hrn` varchar(255) NOT NULL default '',
`node_id` varchar(32) NOT NULL default '',
PRIMARY KEY (`hrn`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
4.163: Fix to previous revision; skip to next entry.
4.164: Rework the certs table for protogeni and crls.
DROP TABLE IF EXISTS `user_sslcerts`;
CREATE TABLE `user_sslcerts` (
`uid` varchar(8) NOT NULL default '',
`uid_idx` mediumint(8) unsigned NOT NULL default '0',
`idx` int(10) unsigned NOT NULL default '0',
`created` datetime default NULL,
`expires` datetime default NULL,
`revoked` datetime default NULL,
`password` tinytext,
`encrypted` tinyint(1) NOT NULL default '0',
`DN` text,
`cert` text,
`privkey` text,
PRIMARY KEY (`idx`),
KEY `uid` (`uid`),
KEY `uid_idx` (`uid_idx`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
See the comments in doc/UPDATING. This must be done after
installation.
./initcerts.pl
Then restart the ssl xmlrpc server.
sudo kill `cat /var/run/sslxmlrpc_server.pid`
/usr/testbed/sbin/sslxmlrpc_server.py
4.165: Add a geniflags slot to the experiments table so that we can
alter the way things behave (like the web interface) when
operating on an experiment that is the container for a slice.
alter table experiments add
`geniflags` int(11) NOT NULL default '0';
4.166: Add backfill values to the database to be used in a future
commit:
alter table virt_lans
add backfill int(10) unsigned default 0 after bandwidth,
add rbackfill int(10) unsigned default 0 after rbandwidth;
alter table delays
add backfill0 int(10) unsigned NOT NULL default 0 after bandwidth0,
add backfill1 int(10) unsigned NOT NULL default 0 after bandwidth1;
replace into table_regex VALUES
('virt_lans','backfill','int','redirect','default:int',
0,2147483647,NULL);
replace into table_regex VALUES
('virt_lans','rbackfill','int','redirect','default:int',
0,2147483647,NULL);
4.167: Change to backfill default values in virt_lans, skip to next
entry
4.168: Various changes to support storing control network vlans in
the DB, and eventually elabinelab firewalls.
# Allow arbitrary the names for the ids. Forgot who wanted this.
alter table elabinelab_vlans change `inner_id`
`inner_id` varchar(32) NOT NULL default '';
alter table elabinelab_vlans change `outer_id`
`outer_id` varchar(32) NOT NULL default '';
# Tag elabinelab created vlans with the stack module.
alter table elabinelab_vlans add `stack`
enum('Control','Experimental') NOT NULL default 'Experimental';
# Tag vlans softstate table with the stack module.
alter table vlans add `stack`
enum('Control','Experimental') NOT NULL default 'Experimental';
# A new table, to store softstate on interfaces. snmpit will
# modify this table whenever a port is enabled/trunked(tagged)
# on the command line. Eventually speed/duplex should go here.
CREATE TABLE `interface_state` (
`node_id` varchar(32) NOT NULL default '',
`card` tinyint(3) unsigned NOT NULL default '0',
`port` tinyint(3) unsigned NOT NULL default '0',
`iface` varchar(32) NOT NULL,
`enabled` tinyint(1) default '1',
`tagged` tinyint(1) default '0',
PRIMARY KEY (`node_id`,`card`,`port`),
KEY `nodeiface` (`node_id`,`iface`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
# Initialize the above table.
insert into interface_state (node_id,card,port,iface)
select node_id,card,port,iface from interfaces;
# Cleanup the vlans table which was filling with cruft
# cause of a bug in the swapout code. Finally figured
# out how to combine delete and join!
delete v FROM vlans v LEFT JOIN lans l on l.lanid=v.id
WHERE l.lanid IS NULL;
# Fix an unrelated bug; slot overflow.
alter table nodelog change `log_id`
`log_id` int(10) unsigned NOT NULL auto_increment;
#
# This is the first DB update script. It adds a new table to the DB
# to track version info for doing this.
#
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBTableExists("version_info")) {
DBQueryFatal("CREATE TABLE `version_info` ( ".
" `name` varchar(32) NOT NULL default '', ".
" `value` tinytext NOT NULL, ".
" PRIMARY KEY (`name`) ".
") ENGINE=MyISAM DEFAULT CHARSET=latin1");
}
# Initialize new table.
my $query_result =
DBQueryFatal("select value from version_info where name='dbrev'");
if (! $query_result->numrows) {
DBQueryFatal("replace into `version_info` values ('dbrev', '4.0')");
}
return 0;
}
1;
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("reserved", "tmcd_redirect")) {
DBQueryFatal("alter table reserved add `tmcd_redirect` tinytext");
}
return 0;
}
1;
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBTableExists("widearea_switches")) {
DBQueryFatal("CREATE TABLE `widearea_switches` ( ".
" `hrn` varchar(255) NOT NULL default '', ".
" `node_id` varchar(32) NOT NULL default '', ".
" PRIMARY KEY (`hrn`) ".
") ENGINE=MyISAM DEFAULT CHARSET=latin1");
}
my $type = DBSlotType("nodes", "role");
if (!$type) {
Fatal("No 'role' slot in 'nodes' table");
}
if (! ($type =~ /widearea_switch/)) {
DBQueryFatal("alter table nodes change `role` `role` ".
" enum('testnode','virtnode','ctrlnode','testswitch', ".
" 'ctrlswitch','powerctrl','widearea_switch','unused') ".
"NOT NULL default 'unused'");
}
return 0;
}
1;
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("user_sslcerts", "DN")) {
DBQueryFatal("DROP TABLE IF EXISTS `user_sslcerts`");
DBQueryFatal("CREATE TABLE `user_sslcerts` ( ".
" `uid` varchar(8) NOT NULL default '', ".
" `uid_idx` mediumint(8) unsigned NOT NULL default '0', ".
" `idx` int(10) unsigned NOT NULL default '0', ".
" `created` datetime default NULL, ".
" `expires` datetime default NULL, ".
" `revoked` datetime default NULL, ".
" `password` tinytext, ".
" `encrypted` tinyint(1) NOT NULL default '0', ".
" `DN` text, ".
" `cert` text, ".
" `privkey` text, ".
" PRIMARY KEY (`idx`), ".
" KEY `uid` (`uid`), ".
" KEY `uid_idx` (`uid_idx`) ".
") ENGINE=MyISAM DEFAULT CHARSET=latin1");
print " *** NOTE: See the comments in doc/UPDATING\n";
print " *** You must run sql/initcerts.pl after install.\n";
}
return 0;
}
1;
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("experiments", "geniflags")) {
DBQueryFatal("alter table experiments add ".
" `geniflags` int(11) NOT NULL default '0'");
}
return 0;
}
1;
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
if (!DBSlotExists("virt_lans", "backfill")) {
DBQueryFatal("alter table virt_lans add ".
"backfill int(10) unsigned default 0 after bandwidth");
}
if (!DBSlotExists("virt_lans", "backfill")) {
DBQueryFatal("alter table virt_lans add ".
"rbackfill int(10) unsigned default 0 after rbandwidth");
}
if (!DBSlotExists("delays", "backfill0")) {
DBQueryFatal("alter table delays add ".
"backfill0 int(10) unsigned NOT NULL ".
"default 0 after bandwidth0");
}
if (!DBSlotExists("delays", "backfill1")) {
DBQueryFatal("alter table delays add ".
"backfill1 int(10) unsigned NOT NULL ".
"default 0 after bandwidth1");
}
DBQueryFatal("replace into table_regex VALUES ".
" ('virt_lans','backfill','int','redirect','default:int', ".
" 0,2147483647,NULL)");
DBQueryFatal("replace into table_regex VALUES ".
" ('virt_lans','rbackfill','int','redirect','default:int', ".
" 0,2147483647,NULL)");
return 0;
}
1;
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
# Allow arbitrary the names for the ids. Forgot who wanted this.
DBQueryFatal("alter table elabinelab_vlans change ".
" `inner_id` `inner_id` varchar(32) NOT NULL default ''");
DBQueryFatal("alter table elabinelab_vlans change ".
" `outer_id` `outer_id` varchar(32) NOT NULL default ''");
# Tag elabinelab created vlans with the stack module.
if (! DBSlotExists("elabinelab_vlans", "stack")) {
DBQueryFatal("alter table elabinelab_vlans add `stack` ".
" enum('Control','Experimental') ".
"NOT NULL default 'Experimental'");
}
# Tag vlans softstate table with the stack module.
if (! DBSlotExists("vlans", "stack")) {
DBQueryFatal("alter table vlans add `stack` ".
" enum('Control','Experimental') ".
"NOT NULL default 'Experimental'");
}
# A new table, to store softstate on interfaces. snmpit will
# modify this table whenever a port is enabled/trunked(tagged)
# on the command line. Eventually speed/duplex should go here.
if (!DBTableExists("interface_state")) {
DBQueryFatal("CREATE TABLE `interface_state` ( ".
" `node_id` varchar(32) NOT NULL default '', ".
" `card` tinyint(3) unsigned NOT NULL default '0', ".
" `port` tinyint(3) unsigned NOT NULL default '0', ".
" `iface` varchar(32) NOT NULL, ".
" `enabled` tinyint(1) default '1', ".
" `tagged` tinyint(1) default '0', ".
" PRIMARY KEY (`node_id`,`card`,`port`), ".
" KEY `nodeiface` (`node_id`,`iface`) ".
" ) ENGINE=MyISAM DEFAULT CHARSET=latin1");
# Initialize the above table.
DBQueryFatal("insert into interface_state (node_id,card,port,iface) ".
"select node_id,card,port,iface from interfaces");
}
#
# Cleanup the vlans table which was filling with cruft cause of a
# bug in the swapout code. Finally figured out how to combine
# delete and join!
#
DBQueryFatal("delete v FROM vlans v LEFT JOIN lans l on l.lanid=v.id ".
"WHERE l.lanid IS NULL ");
# Fix an unrelated bug; slot overflow.
DBQueryFatal("alter table nodelog change `log_id` ".
" `log_id` int(10) unsigned NOT NULL auto_increment");
return 0;
}
1;
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002, 2005 University of Utah and the Flux Group.
# Copyright (c) 2000-2009 University of Utah and the Flux Group.
# All rights reserved.
#
# Set the version and build info into the DB, at a toplevel install.
......@@ -49,36 +49,4 @@ if (!$query_result) {
" Unable to set sitevar 'general/version/build' to $buildinfo\n");
}
#
# Now dig out the version info from the database-migrate file.
#
my $major = "96";
my $minor = "96";
open(MIG, $DBMIGRATE) or
die("*** $0:\n".
" Unable to open $DBMIGRATE\n");
while (<MIG>) {
if ($_ =~ /^(\d*)\.(\d*)/) {
$major = $1;
$minor = $2;
}
}
#
# The last entry is the build info.
#
$query_result =
$dbh->query("update sitevariables set value='$major' ".
"where name='general/version/major'");
if (!$query_result) {
die("*** $0:\n".
" Unable to set sitevar 'general/version/major' to '$major'\n");
}
$query_result =
$dbh->query("update sitevariables set value='$minor' ".
"where name='general/version/minor'");
if (!$query_result) {
die("*** $0:\n".
" Unable to set sitevar 'general/version/minor' to '$minor'\n");
}
exit(0);
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
# Copyright (c) 2000-2009 University of Utah and the Flux Group.
# All rights reserved.
#
# Database Constants
......@@ -563,21 +563,30 @@ function TBSetFirstInitPid($pid)
function TBGetVersionInfo(&$major, &$minor, &$build)
{
$query_result =
DBQueryFatal("select name,value from sitevariables ".
"where name='general/version/major' or ".
" name='general/version/minor' or ".
" name='general/version/build'");
while (($row = mysql_fetch_row($query_result))) {
$name = $row[0];
$value = $row[1];
if ($name == "general/version/major")
$major = $value;
elseif ($name == "general/version/minor")
$minor = $value;
elseif ($name == "general/version/build")
$build = $value;
DBQueryFatal("select value from sitevariables ".
"where name='general/version/build'");
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_row($query_result);
$build = $row[0];
}
else {
$build = "Unknown";
}
$query_result =
DBQuery("select value from version_info where name='dbrev'");
if ($query_result && mysql_num_rows($query_result)) {
$row = mysql_fetch_row($query_result);
list($a,$b) = split('\.', $row[0]);
$a = (isset($a) && $a != "" ? $a : "x");
$b = (isset($b) && $b != "" ? $b : "y");
$major = $a;
$minor = $b;
}
else {
$major = "X";
$minor = "Y";
}
return 1;
}
......
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