Commit 53c29cfa authored by Leigh Stoller's avatar Leigh Stoller

Munge the schemacheck code to deal with all the oddities of the way

mysql 5.0 dumps the schema. What a pain in the ass.

Note that "timestamp" is basically impossible since its radically
different between 3.X and 5.X, which would break schemacheck on 3.X
based Emulabs. Since there are only three of them in the schema, I
changed schemadiff to not look too hard at them.
parent 4bd494e4
......@@ -30,7 +30,7 @@ USERLIBS = libtbdb.pm
# configure if the .in file is changed.
#
all: $(BIN_SCRIPTS) $(SBIN_SCRIPTS) $(LIBEXEC_SCRIPTS) $(LIB_SCRIPTS) \
$(USERSBINS) $(USERLIBS)
$(USERSBINS) $(USERLIBS) schemacheck
include $(TESTBED_SRCDIR)/GNUmakerules
......
......@@ -2,7 +2,7 @@
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# Copyright (c) 2000-2003, 2006 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
......@@ -29,11 +29,14 @@ my $DBNAME = "@TBDBNAME@";
my $master_schema = "$testbed_srcdir/sql/database-create.sql";
my $schemadiff = "$testbed_srcdir/utils/schemadiff";
my $isvers5 = system("mysql -V | egrep 'Distrib 5.'") == 0;
my $extraopts = ($isvers5 ? "--skip-quote-names" : "");
#
# XXX: Requires that mysqldump be in caller's $PATH - probably an OK
# assumption, but maybe not always
#
my $mysqldump = "mysqldump -d $DBNAME";
my $mysqldump = "mysqldump -d $extraopts $DBNAME";
#
# We use Mysql module instead of the tesbed libraries, so that we can get
......
......@@ -146,8 +146,14 @@ sub read_schema($) {
if (!$create_table) {
if (/^\s*$/ || /^\s*#/ || /^--/ || /^INSERT INTO/) {
# An insert statement, a comment, or a blank line. Do nothing.
} elsif (/^CREATE TABLE (\w+) \($/) {
}
elsif (/^\/\*.*\*\/[;]+$/) {
# Also a comment
}
elsif (/^DROP TABLE /) {
# mysql 5.0 add these now.
}
elsif (/^CREATE TABLE `?(\w+)`? \($/) {
# Start of a new table definition
$create_table = 1;
$table_name = $1;
......@@ -176,7 +182,8 @@ sub read_schema($) {
# what this line is trying to do...
#
if (/^\) TYPE\s*=\s*(\w+);/) {
if (/^\) TYPE\s*=\s*(\w+);/ ||
/^\) ENGINE\s*=\s*(\w+)\s*DEFAULT\s*CHARSET=(\w+);/) {
# The end of the table definition
my $type = $1;
......@@ -214,18 +221,22 @@ sub read_schema($) {
my $key = $1;
# Strip whitespace
$key =~ s/\s+//g;
# Strip backquotes
$key =~ s/\`//g;
debug("Putting primary key $key in table $table_name\n");
$tables{$table_name}{PRIMARY}{$key} = 1;
} elsif (/^\s*(KEY|INDEX)\s+(\w+)?\s+\((.+[^,])\),?$/) {
} elsif (/^\s*(UNIQUE)?\s+(KEY|INDEX)\s+`?(\w+)?`?\s+\((.+[^,])\),?$/) {
# A key/index (synonmyms)
my ($name, $key) = ($2, $3);
# Strip whitespace
$key =~ s/\s+//g;
debug("Putting key $key in table $table_name\n");
# Strip backquotes
$key =~ s/\`//g;
debug("Putting key $key in table $table_name\n");
if ($name) {
if ($name) {
$tables{$table_name}{KEYS}{$name} = $key;
} else {
die "Found a key without a name: $key\n";
......@@ -236,6 +247,11 @@ sub read_schema($) {
# A column definition
my ($name, $definition) = ($1, $2);
debug("Found column $name with type $definition\n");
# Change timestamp(14) to timestamp!
$definition =~ s/timestamp NOT NULL default.*/timestamp NOT NULL/g;
$definition =~ s/timestamp\(14\)/timestamp/g;
$tables{$table_name}{COLUMNS}{$name} = $definition;
push @{ $tables{$table_name}{ORDERED_COLUMNS} },
......
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