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", "../mysql5/tables-binary.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|binary};
58 open my $newfh, "<", $new or die qq{Could
not open $new: $!\n};
65 for my $xfile (@xfile) {
66 print "Loading $xfile\n";
67 my $info = &parse_sql
($xfile);
69 $xinfo{$_} = $info->{$_};
73 for my $oldfile (@old) {
74 print "Loading $oldfile\n";
75 my $info = &parse_sql
($oldfile);
77 $info->{$_} = $xinfo{$_};
79 $old{$oldfile} = $info;
86 open my $oldfh, "<", $oldfile or die qq{Could
not open $oldfile: $!\n};
90 next if /^\s*\-\-/ or /^\s+$/;
94 if (/CREATE\s*TABLE/i) {
95 m{^CREATE TABLE /\*\$wgDBprefix\*/(\w+) \($}
96 or die qq{Invalid CREATE TABLE at line
$. of
$oldfile\n};
98 $info{$table}{name
}=$table;
100 elsif (/^\) ($engine)=($tabletype);$/) {
101 $info{$table}{engine
}=$1;
102 $info{$table}{type
}=$2;
104 elsif (/^\) ($engine)=($tabletype), DEFAULT CHARSET=($charset);$/) {
105 $info{$table}{engine
}=$1;
106 $info{$table}{type
}=$2;
107 $info{$table}{charset
}=$3;
109 elsif (/^ (\w+) $datatype$typeval$typeval2{0,3},?$/) {
110 $info{$table}{column
}{$1} = $2;
112 elsif (/^ ($indextype)(?: (\w+))? \(([\w, \(\)]+)\),?$/) {
113 $info{$table}{lc $1."_name"} = $2 ?
$2 : "";
114 $info{$table}{lc $1."pk_target"} = $3;
117 die "Cannot parse line $. of $oldfile:\n$_\n";
125 } ## end of parse_sql
127 for my $oldfile (@old) {
129 ## Begin non-standard indent
131 ## MySQL sanity checks
132 for my $table (sort keys %{$old{$oldfile}}) {
133 my $t = $old{$oldfile}{$table};
134 if (($oldfile =~ /5/ and $t->{engine
} ne 'ENGINE')
136 ($oldfile !~ /5/ and $t->{engine
} ne 'TYPE')) {
137 die "Invalid engine for $oldfile: $t->{engine}\n" unless $t->{name
} eq 'profiling';
139 my $charset = $t->{charset
} || '';
140 if ($oldfile !~ /binary/ and $charset eq 'binary') {
141 die "Invalid charset for $oldfile: $charset\n";
145 my $dtype = join '|' => qw(
146 SMALLINT INTEGER BIGINT NUMERIC SERIAL
152 $dtype = qr{($dtype)};
154 my ($infunction,$inview,$inrule) = (0,0,0);
157 next if /^\s*\-\-/ or /^\s*$/;
158 s/\s*\-\- [\w ']+$//;
159 next if /^BEGIN;/ or /^SET / or /^COMMIT;/;
160 next if /^CREATE SEQUENCE/;
161 next if /^CREATE(?: UNIQUE)? INDEX/;
162 next if /^CREATE FUNCTION/;
163 next if /^CREATE TRIGGER/ or /^ FOR EACH ROW/;
164 next if /^INSERT INTO/ or /^ VALUES \(/;
165 next if /^ALTER TABLE/;
169 $infunction = $infunction ?
0 : 1;
174 next if /^CREATE VIEW/ and $inview = 1;
176 /;$/ and $inview = 0;
180 next if /^CREATE RULE/ and $inrule = 1;
182 /;$/ and $inrule = 0;
186 if (/^CREATE TABLE "?(\w+)"? \($/) {
188 $new{$table}{name
}=$table;
192 elsif (/^ (\w+) +$dtype/) {
193 $new{$table}{column
}{$1} = $2;
196 die "Cannot parse line $. of $new:\n$_\n";
201 for my $t (sort keys %{$old{$oldfile}}) {
202 if (!exists $new{$t} and !exists $ok{OLD
}{$t}) {
203 print "Table not in $new: $t\n";
206 next if exists $ok{OLD
}{$t} and !$ok{OLD
}{$t};
207 my $newt = exists $ok{OLD
}{$t} ?
$ok{OLD
}{$t} : $t;
208 my $oldcol = $old{$oldfile}{$t}{column
};
209 my $newcol = $new{$newt}{column
};
210 for my $c (keys %$oldcol) {
211 if (!exists $newcol->{$c}) {
212 print "Column $t.$c not in new\n";
216 for my $c (keys %$newcol) {
217 if (!exists $oldcol->{$c}) {
218 print "Column $t.$c not in old\n";
224 for (sort keys %new) {
225 if (!exists $old{$oldfile}{$_} and !exists $ok{NEW
}{$_}) {
226 print "Not in old: $_\n";
232 } ## end each file to be parsed
237 OLD
: searchindex
## We use tsearch2 directly on the page table instead
238 OLD
: archive
## This is a view due to the char(14) timestamp hack
239 RENAME
: user mwuser
## Reserved word causing lots of problems
240 RENAME
: text pagecontent
## Reserved word
241 NEW
: archive2
## The real archive table
242 NEW
: mediawiki_version
## Just us, for now
243 XFILE
: ../archives/patch
-profiling
.sql