From 75d8a6b93065962fe30f4a646d1ca8873c68f217 Mon Sep 17 00:00:00 2001 From: "Leigh B. Stoller" Date: Wed, 21 Jan 2009 20:47:55 +0000 Subject: [PATCH] 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. --- db/schemacheck.in | 23 ++++--- sql/database-create.sql | 11 ++++ sql/database-migrate.txt | 128 ++++----------------------------------- sql/updates/4/1 | 28 +++++++++ sql/updates/4/161 | 13 ++++ sql/updates/4/162 | 27 +++++++++ sql/updates/4/164 | 31 ++++++++++ sql/updates/4/165 | 14 +++++ sql/updates/4/166 | 35 +++++++++++ sql/updates/4/168 | 62 +++++++++++++++++++ utils/setbuildinfo.in | 34 +---------- www/dbdefs.php3.in | 41 ++++++++----- 12 files changed, 271 insertions(+), 176 deletions(-) create mode 100644 sql/updates/4/1 create mode 100644 sql/updates/4/161 create mode 100644 sql/updates/4/162 create mode 100644 sql/updates/4/164 create mode 100644 sql/updates/4/165 create mode 100644 sql/updates/4/166 create mode 100644 sql/updates/4/168 diff --git a/db/schemacheck.in b/db/schemacheck.in index 4038f24de..5bbd769b3 100755 --- a/db/schemacheck.in +++ b/db/schemacheck.in @@ -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 diff --git a/sql/database-create.sql b/sql/database-create.sql index 8f0d8ae25..8ffe27ef8 100644 --- a/sql/database-create.sql +++ b/sql/database-create.sql @@ -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` -- diff --git a/sql/database-migrate.txt b/sql/database-migrate.txt index 03fa00f40..86c1a624a 100644 --- a/sql/database-migrate.txt +++ b/sql/database-migrate.txt @@ -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; diff --git a/sql/updates/4/1 b/sql/updates/4/1 new file mode 100644 index 000000000..d80ce5cb5 --- /dev/null +++ b/sql/updates/4/1 @@ -0,0 +1,28 @@ +# +# 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; diff --git a/sql/updates/4/161 b/sql/updates/4/161 new file mode 100644 index 000000000..d3f18cb15 --- /dev/null +++ b/sql/updates/4/161 @@ -0,0 +1,13 @@ +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; diff --git a/sql/updates/4/162 b/sql/updates/4/162 new file mode 100644 index 000000000..0110845f1 --- /dev/null +++ b/sql/updates/4/162 @@ -0,0 +1,27 @@ +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; diff --git a/sql/updates/4/164 b/sql/updates/4/164 new file mode 100644 index 000000000..d341410e7 --- /dev/null +++ b/sql/updates/4/164 @@ -0,0 +1,31 @@ +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; diff --git a/sql/updates/4/165 b/sql/updates/4/165 new file mode 100644 index 000000000..80d8d42b7 --- /dev/null +++ b/sql/updates/4/165 @@ -0,0 +1,14 @@ +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; diff --git a/sql/updates/4/166 b/sql/updates/4/166 new file mode 100644 index 000000000..809117340 --- /dev/null +++ b/sql/updates/4/166 @@ -0,0 +1,35 @@ +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; diff --git a/sql/updates/4/168 b/sql/updates/4/168 new file mode 100644 index 000000000..a3f930faf --- /dev/null +++ b/sql/updates/4/168 @@ -0,0 +1,62 @@ +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; diff --git a/utils/setbuildinfo.in b/utils/setbuildinfo.in index 34f960e18..05b0efeb9 100644 --- a/utils/setbuildinfo.in +++ b/utils/setbuildinfo.in @@ -1,7 +1,7 @@ #!/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 () { - 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); diff --git a/www/dbdefs.php3.in b/www/dbdefs.php3.in index 050245fdb..792bc695d 100644 --- a/www/dbdefs.php3.in +++ b/www/dbdefs.php3.in @@ -1,7 +1,7 @@