From 8bfec9c69ff5041dcec78267e0cc516261de50aa Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Sun, 30 Jul 2006 23:49:25 +0000 Subject: [PATCH] Add XFILE to allow for more than one source file, add float as valid mysql type. --- maintenance/postgres/compare_schemas.pl | 99 ++++++++++++++----------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/maintenance/postgres/compare_schemas.pl b/maintenance/postgres/compare_schemas.pl index 22e8c1524a..4a76b27018 100644 --- a/maintenance/postgres/compare_schemas.pl +++ b/maintenance/postgres/compare_schemas.pl @@ -7,15 +7,35 @@ use strict; use warnings; use Data::Dumper; -my $old = "../tables.sql"; +my @old = ("../tables.sql"); my $new = "tables.sql"; -open my $oldfh, "<", $old or die qq{Could not open $old: $!\n}; +## Read in exceptions and other metadata +my %ok; +while () { + next unless /^(\w+)\s*:\s*([^#]+)/; + my ($name,$val) = ($1,$2); + chomp $val; + if ($name eq 'RENAME') { + die "Invalid rename\n" unless $val =~ /(\w+)\s+(\w+)/; + $ok{OLD}{$1} = $2; + $ok{NEW}{$2} = $1; + next; + } + if ($name eq 'XFILE') { + push @old, $val; + next; + } + for (split(/\s+/ => $val)) { + $ok{$name}{$_} = 0; + } +} + open my $newfh, "<", $new or die qq{Could not open $new: $!\n}; my $datatype = join '|' => qw( bool -tinyint int bigint real +tinyint int bigint real float tinytext mediumtext text char varchar timestamp datetime tinyblob mediumblob blob @@ -30,35 +50,39 @@ my $typeval2 = qr{ unsigned| binary| NOT NULL| NULL| auto_increment| default ['\ my $indextype = join '|' => qw(INDEX KEY FULLTEXT), "PRIMARY KEY", "UNIQUE INDEX", "UNIQUE KEY"; $indextype = qr{$indextype}; -my $tabletype = qr{InnoDB|MyISAM|HEAP MAX_ROWS=\d+}; +my $tabletype = qr{InnoDB|MyISAM|HEAP|HEAP MAX_ROWS=\d+}; my ($table,%old); -while (<$oldfh>) { - next if /^\s*\-\-/ or /^\s+$/; - s/\s*\-\- [\w ]+$//; - chomp; - - if (/CREATE\s*TABLE/i) { - m{^CREATE TABLE /\*\$wgDBprefix\*/(\w+) \($} - or die qq{Invalid CREATE TABLE at line $. of $old\n}; - $table = $1; - $old{$table}{name}=$table; - } - elsif (/^\) TYPE=($tabletype);$/) { - $old{$table}{type}=$1; - } - elsif (/^ (\w+) $datatype$typeval$typeval2{0,3},?$/) { - $old{$table}{column}{$1} = $2; - } - elsif (/^ ($indextype)(?: (\w+))? \(([\w, \(\)]+)\),?$/) { - $old{$table}{lc $1."_name"} = $2 ? $2 : ""; - $old{$table}{lc $1."pk_target"} = $3; - } - else { - die "Cannot parse line $. of $old:\n$_\n"; +for my $old (@old) { + open my $oldfh, "<", $old or die qq{Could not open $old: $!\n}; + + while (<$oldfh>) { + next if /^\s*\-\-/ or /^\s+$/; + s/\s*\-\- [\w ]+$//; + chomp; + + if (/CREATE\s*TABLE/i) { + m{^CREATE TABLE /\*\$wgDBprefix\*/(\w+) \($} + or die qq{Invalid CREATE TABLE at line $. of $old\n}; + $table = $1; + $old{$table}{name}=$table; + } + elsif (/^\) TYPE=($tabletype);$/) { + $old{$table}{type}=$1; + } + elsif (/^ (\w+) $datatype$typeval$typeval2{0,3},?$/) { + $old{$table}{column}{$1} = $2; + } + elsif (/^ ($indextype)(?: (\w+))? \(([\w, \(\)]+)\),?$/) { + $old{$table}{lc $1."_name"} = $2 ? $2 : ""; + $old{$table}{lc $1."pk_target"} = $3; + } + else { + die "Cannot parse line $. of $old:\n$_\n"; + } } + close $oldfh; } -close $oldfh; $datatype = join '|' => qw( SMALLINT INTEGER BIGINT NUMERIC SERIAL @@ -115,22 +139,6 @@ while (<$newfh>) { } close $newfh; -## Read in known exceptions -my %ok; -while () { - next unless /^(\w+)\s*:\s*([^#]+)/; - my ($name,$val) = ($1,$2); - if ($name eq 'RENAME') { - die "Invalid rename\n" unless $val =~ /(\w+)\s+(\w+)/; - $ok{OLD}{$1} = $2; - $ok{NEW}{$2} = $1; - next; - } - for (split(/\s+/ => $val)) { - $ok{$name}{$_} = 0; - } -} - ## Old but not new for my $t (sort keys %old) { if (!exists $new{$t} and !exists $ok{OLD}{$t}) { @@ -157,7 +165,7 @@ for my $t (sort keys %old) { ## New but not old: for (sort keys %new) { if (!exists $old{$_} and !exists $ok{NEW}{$_}) { - print "Not in $old: $_\n"; + print "Not in old: $_\n"; next; } } @@ -170,3 +178,4 @@ RENAME: user mwuser ## Reserved word causing lots of problems RENAME: text pagecontent ## Reserved word NEW: archive2 ## The real archive table NEW: mediawiki_version ## Just us, for now +XFILE: ../archives/patch-profiling.sql -- 2.20.1