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";
13 ## Read in exceptions and other metadata
16 next unless /^(\w+)\s*:\s*([^#]+)/;
17 my ($name,$val) = ($1,$2);
19 if ($name eq 'RENAME') {
20 die "Invalid rename\n" unless $val =~ /(\w+)\s+(\w+)/;
25 if ($name eq 'XFILE') {
29 for (split(/\s+/ => $val)) {
34 open my $newfh, "<", $new or die qq{Could
not open $new: $!\n};
36 my $datatype = join '|' => qw(
38 tinyint int bigint real float
39 tinytext mediumtext text char varchar
41 tinyblob mediumblob blob
43 $datatype .= q{|ENUM\([\"\w, ]+\)};
44 $datatype = qr{($datatype)};
46 my $typeval = qr{(\(\d+\))?};
48 my $typeval2 = qr{ unsigned| binary| NOT NULL| NULL| auto_increment| default ['\-\d\w"]+| REFERENCES .+CASCADE};
50 my $indextype = join '|' => qw(INDEX KEY FULLTEXT), "PRIMARY KEY", "UNIQUE INDEX", "UNIQUE KEY";
51 $indextype = qr{$indextype};
53 my $tabletype = qr{InnoDB|MyISAM|HEAP|HEAP MAX_ROWS=\d+};
57 open my $oldfh, "<", $old or die qq{Could
not open $old: $!\n};
60 next if /^\s*\-\-/ or /^\s+$/;
64 if (/CREATE\s*TABLE/i) {
65 m{^CREATE TABLE /\*\$wgDBprefix\*/(\w+) \($}
66 or die qq{Invalid CREATE TABLE at line
$. of
$old\n};
68 $old{$table}{name
}=$table;
70 elsif (/^\) TYPE=($tabletype);$/) {
71 $old{$table}{type
}=$1;
73 elsif (/^ (\w+) $datatype$typeval$typeval2{0,3},?$/) {
74 $old{$table}{column
}{$1} = $2;
76 elsif (/^ ($indextype)(?: (\w+))? \(([\w, \(\)]+)\),?$/) {
77 $old{$table}{lc $1."_name"} = $2 ?
$2 : "";
78 $old{$table}{lc $1."pk_target"} = $3;
81 die "Cannot parse line $. of $old:\n$_\n";
87 $datatype = join '|' => qw(
88 SMALLINT INTEGER BIGINT NUMERIC SERIAL
94 $datatype = qr{($datatype)};
96 my ($infunction,$inview,$inrule) = (0,0,0);
98 next if /^\s*\-\-/ or /^\s*$/;
100 next if /^BEGIN;/ or /^SET / or /^COMMIT;/;
101 next if /^CREATE SEQUENCE/;
102 next if /^CREATE(?: UNIQUE)? INDEX/;
103 next if /^CREATE FUNCTION/;
104 next if /^CREATE TRIGGER/ or /^ FOR EACH ROW/;
105 next if /^INSERT INTO/ or /^ VALUES \(/;
106 next if /^ALTER TABLE/;
110 $infunction = $infunction ?
0 : 1;
115 next if /^CREATE VIEW/ and $inview = 1;
117 /;$/ and $inview = 0;
121 next if /^CREATE RULE/ and $inrule = 1;
123 /;$/ and $inrule = 0;
127 if (/^CREATE TABLE "?(\w+)"? \($/) {
129 $new{$table}{name
}=$table;
133 elsif (/^ (\w+) +$datatype/) {
134 $new{$table}{column
}{$1} = $2;
137 die "Cannot parse line $. of $new:\n$_\n";
143 for my $t (sort keys %old) {
144 if (!exists $new{$t} and !exists $ok{OLD
}{$t}) {
145 print "Table not in $new: $t\n";
148 next if exists $ok{OLD
}{$t} and !$ok{OLD
}{$t};
149 my $newt = exists $ok{OLD
}{$t} ?
$ok{OLD
}{$t} : $t;
150 my $oldcol = $old{$t}{column
};
151 my $newcol = $new{$newt}{column
};
152 for my $c (keys %$oldcol) {
153 if (!exists $newcol->{$c}) {
154 print "Column $t.$c not in new\n";
158 for my $c (keys %$newcol) {
159 if (!exists $oldcol->{$c}) {
160 print "Column $t.$c not in old\n";
166 for (sort keys %new) {
167 if (!exists $old{$_} and !exists $ok{NEW
}{$_}) {
168 print "Not in old: $_\n";
175 OLD
: searchindex
## We use tsearch2 directly on the page table instead
176 OLD
: archive
## This is a view due to the char(14) timestamp hack
177 RENAME
: user mwuser
## Reserved word causing lots of problems
178 RENAME
: text pagecontent
## Reserved word
179 NEW
: archive2
## The real archive table
180 NEW
: mediawiki_version
## Just us, for now
181 XFILE
: ../archives/patch
-profiling
.sql