3 ## Rough check that the base and postgres "tables.sql" are in sync
4 ## Should be run from maintenance/postgres
10 my @old = ("../tables.sql", "../mysql5/tables.sql");
11 my $new = "tables.sql";
14 ## Read in exceptions and other metadata
17 next unless /^(\w+)\s*:\s*([^#]+)/;
18 my ($name,$val) = ($1,$2);
20 if ($name eq 'RENAME') {
21 die "Invalid rename\n" unless $val =~ /(\w+)\s+(\w+)/;
26 if ($name eq 'XFILE') {
30 for (split(/\s+/ => $val)) {
35 my $datatype = join '|' => qw(
37 tinyint int bigint real float
38 tinytext mediumtext text char varchar varbinary
40 tinyblob mediumblob blob
42 $datatype .= q{|ENUM\([\"\w, ]+\)};
43 $datatype = qr{($datatype)};
45 my $typeval = qr{(\(\d+\))?};
47 my $typeval2 = qr{ unsigned| binary| NOT NULL| NULL| auto_increment| default ['\-\d\w"]+| REFERENCES .+CASCADE};
49 my $indextype = join '|' => qw(INDEX KEY FULLTEXT), "PRIMARY KEY", "UNIQUE INDEX", "UNIQUE KEY";
50 $indextype = qr{$indextype};
52 my $engine = qr{TYPE|ENGINE};
54 my $tabletype = qr{InnoDB|MyISAM|HEAP|HEAP MAX_ROWS=\d+};
56 my $charset = qr{utf8};
59 open my $newfh, "<", $new or die qq{Could
not open $new: $!\n};
66 for my $xfile (@xfile) {
67 print "Loading $xfile\n";
68 my $info = &parse_sql
($xfile);
70 $xinfo{$_} = $info->{$_};
74 for my $oldfile (@old) {
75 print "Loading $oldfile\n";
76 my $info = &parse_sql
($oldfile);
78 $info->{$_} = $xinfo{$_};
80 $old{$oldfile} = $info;
87 open my $oldfh, "<", $oldfile or die qq{Could
not open $oldfile: $!\n};
91 next if /^\s*\-\-/ or /^\s+$/;
95 if (/CREATE\s*TABLE/i) {
96 m{^CREATE TABLE /\*\$wgDBprefix\*/(\w+) \($}
97 or die qq{Invalid CREATE TABLE at line
$. of
$oldfile\n};
99 $info{$table}{name
}=$table;
101 elsif (/^\) ($engine)=($tabletype);$/) {
102 $info{$table}{engine
}=$1;
103 $info{$table}{type
}=$2;
105 elsif (/^\) ($engine)=($tabletype), DEFAULT CHARSET=($charset);$/) {
106 $info{$table}{engine
}=$1;
107 $info{$table}{type
}=$2;
108 $info{$table}{charset
}=$3;
110 elsif (/^ (\w+) $datatype$typeval$typeval2{0,3},?$/) {
111 $info{$table}{column
}{$1} = $2;
113 elsif (/^ ($indextype)(?: (\w+))? \(([\w, \(\)]+)\),?$/) {
114 $info{$table}{lc $1."_name"} = $2 ?
$2 : "";
115 $info{$table}{lc $1."pk_target"} = $3;
118 die "Cannot parse line $. of $oldfile:\n$_\n";
126 } ## end of parse_sql
128 for my $oldfile (@old) {
130 ## Begin non-standard indent
132 ## MySQL sanity checks
133 for my $table (sort keys %{$old{$oldfile}}) {
134 my $t = $old{$oldfile}{$table};
135 if (($oldfile =~ /5/ and $t->{engine
} ne 'ENGINE')
137 ($oldfile !~ /5/ and $t->{engine
} ne 'TYPE')) {
138 die "Invalid engine for $oldfile: $t->{engine}\n" unless $t->{name
} eq 'profiling';
142 my $dtype = join '|' => qw(
143 SMALLINT INTEGER BIGINT NUMERIC SERIAL
149 $dtype = qr{($dtype)};
151 my ($infunction,$inview,$inrule) = (0,0,0);
154 next if /^\s*\-\-/ or /^\s*$/;
155 s/\s*\-\- [\w ']+$//;
156 next if /^BEGIN;/ or /^SET / or /^COMMIT;/;
157 next if /^CREATE SEQUENCE/;
158 next if /^CREATE(?: UNIQUE)? INDEX/;
159 next if /^CREATE FUNCTION/;
160 next if /^CREATE TRIGGER/ or /^ FOR EACH ROW/;
161 next if /^INSERT INTO/ or /^ VALUES \(/;
162 next if /^ALTER TABLE/;
166 $infunction = $infunction ?
0 : 1;
171 next if /^CREATE VIEW/ and $inview = 1;
173 /;$/ and $inview = 0;
177 next if /^CREATE RULE/ and $inrule = 1;
179 /;$/ and $inrule = 0;
183 if (/^CREATE TABLE "?(\w+)"? \($/) {
185 $new{$table}{name
}=$table;
189 elsif (/^ (\w+) +$dtype/) {
190 $new{$table}{column
}{$1} = $2;
193 die "Cannot parse line $. of $new:\n$_\n";
198 for my $t (sort keys %{$old{$oldfile}}) {
199 if (!exists $new{$t} and !exists $ok{OLD
}{$t}) {
200 print "Table not in $new: $t\n";
203 next if exists $ok{OLD
}{$t} and !$ok{OLD
}{$t};
204 my $newt = exists $ok{OLD
}{$t} ?
$ok{OLD
}{$t} : $t;
205 my $oldcol = $old{$oldfile}{$t}{column
};
206 my $newcol = $new{$newt}{column
};
207 for my $c (keys %$oldcol) {
208 if (!exists $newcol->{$c}) {
209 print "Column $t.$c not in new\n";
213 for my $c (keys %$newcol) {
214 if (!exists $oldcol->{$c}) {
215 print "Column $t.$c not in old\n";
221 for (sort keys %new) {
222 if (!exists $old{$oldfile}{$_} and !exists $ok{NEW
}{$_}) {
223 print "Not in old: $_\n";
229 } ## end each file to be parsed
234 OLD
: searchindex
## We use tsearch2 directly on the page table instead
235 OLD
: archive
## This is a view due to the char(14) timestamp hack
236 RENAME
: user mwuser
## Reserved word causing lots of problems
237 RENAME
: text pagecontent
## Reserved word
238 NEW
: archive2
## The real archive table
239 NEW
: mediawiki_version
## Just us, for now
240 XFILE
: ../archives/patch
-profiling
.sql