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');
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+|InnoDB MAX_ROWS=\d+ AVG_ROW_LENGTH=\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 (m
#^\) /\*\$wgDBTableOptions\*/#) {
101 $info{$table}{engine
} = 'TYPE';
102 $info{$table}{type
} = 'variable';
104 elsif (/^\) ($engine)=($tabletype);$/) {
105 $info{$table}{engine
}=$1;
106 $info{$table}{type
}=$2;
108 elsif (/^\) ($engine)=($tabletype), DEFAULT CHARSET=($charset);$/) {
109 $info{$table}{engine
}=$1;
110 $info{$table}{type
}=$2;
111 $info{$table}{charset
}=$3;
113 elsif (/^ (\w+) $datatype$typeval$typeval2{0,3},?$/) {
114 $info{$table}{column
}{$1} = $2;
116 elsif (/^ ($indextype)(?: (\w+))? \(([\w, \(\)]+)\),?$/) {
117 $info{$table}{lc $1.'_name'} = $2 ?
$2 : '';
118 $info{$table}{lc $1.'pk_target'} = $3;
121 die "Cannot parse line $. of $oldfile:\n$_\n";
129 } ## end of parse_sql
131 for my $oldfile (@old) {
133 ## Begin non-standard indent
135 ## MySQL sanity checks
136 for my $table (sort keys %{$old{$oldfile}}) {
137 my $t = $old{$oldfile}{$table};
138 if (($oldfile =~ /5/ and $t->{engine
} ne 'ENGINE')
140 ($oldfile !~ /5/ and $t->{engine
} ne 'TYPE')) {
141 die "Invalid engine for $oldfile: $t->{engine}\n" unless $t->{name
} eq 'profiling';
143 my $charset = $t->{charset
} || '';
144 if ($oldfile !~ /binary/ and $charset eq 'binary') {
145 die "Invalid charset for $oldfile: $charset\n";
149 my $dtype = join '|' => qw(
150 SMALLINT INTEGER BIGINT NUMERIC SERIAL
156 $dtype = qr{($dtype)};
158 my ($infunction,$inview,$inrule) = (0,0,0);
161 next if /^\s*\-\-/ or /^\s*$/;
162 s/\s*\-\- [\w ']+$//;
163 next if /^BEGIN;/ or /^SET / or /^COMMIT;/;
164 next if /^CREATE SEQUENCE/;
165 next if /^CREATE(?: UNIQUE)? INDEX/;
166 next if /^CREATE FUNCTION/;
167 next if /^CREATE TRIGGER/ or /^ FOR EACH ROW/;
168 next if /^INSERT INTO/ or /^ VALUES \(/;
169 next if /^ALTER TABLE/;
173 $infunction = $infunction ?
0 : 1;
178 next if /^CREATE VIEW/ and $inview = 1;
180 /;$/ and $inview = 0;
184 next if /^CREATE RULE/ and $inrule = 1;
186 /;$/ and $inrule = 0;
190 if (/^CREATE TABLE "?(\w+)"? \($/) {
192 $new{$table}{name
}=$table;
196 elsif (/^ (\w+) +$dtype/) {
197 $new{$table}{column
}{$1} = $2;
200 die "Cannot parse line $. of $new:\n$_\n";
205 for my $t (sort keys %{$old{$oldfile}}) {
206 if (!exists $new{$t} and !exists $ok{OLD
}{$t}) {
207 print "Table not in $new: $t\n";
210 next if exists $ok{OLD
}{$t} and !$ok{OLD
}{$t};
211 my $newt = exists $ok{OLD
}{$t} ?
$ok{OLD
}{$t} : $t;
212 my $oldcol = $old{$oldfile}{$t}{column
};
213 my $newcol = $new{$newt}{column
};
214 for my $c (keys %$oldcol) {
215 if (!exists $newcol->{$c}) {
216 print "Column $t.$c not in $new\n";
220 for my $c (keys %$newcol) {
221 if (!exists $oldcol->{$c}) {
222 print "Column $t.$c not in $oldfile\n";
228 for (sort keys %new) {
229 if (!exists $old{$oldfile}{$_} and !exists $ok{NEW
}{$_}) {
230 print "Not in $oldfile: $_\n";
236 } ## end each file to be parsed
241 OLD
: searchindex
## We use tsearch2 directly on the page table instead
242 RENAME
: user mwuser
## Reserved word causing lots of problems
243 RENAME
: text pagecontent
## Reserved word
244 NEW
: mediawiki_version
## Just us, for now
245 XFILE
: ../archives/patch
-profiling
.sql