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 open my $oldfh, "<", $old or die qq{Could
not open $old: $!\n};
14 open my $newfh, "<", $new or die qq{Could
not open $new: $!\n};
16 my $datatype = join '|' => qw(
18 tinyint int bigint real
19 tinytext mediumtext text char varchar
21 tinyblob mediumblob blob
23 $datatype .= q{|ENUM\([\"\w, ]+\)};
24 $datatype = qr{($datatype)};
26 my $typeval = qr{(\(\d+\))?};
28 my $typeval2 = qr{ unsigned| binary| NOT NULL| NULL| auto_increment| default ['\-\d\w"]+| REFERENCES .+CASCADE};
30 my $indextype = join '|' => qw(INDEX KEY FULLTEXT), "PRIMARY KEY", "UNIQUE INDEX", "UNIQUE KEY";
31 $indextype = qr{$indextype};
33 my $tabletype = qr{InnoDB|MyISAM|HEAP MAX_ROWS=\d+};
37 next if /^\s*\-\-/ or /^\s+$/;
41 if (/CREATE\s*TABLE/i) {
42 m{^CREATE TABLE /\*\$wgDBprefix\*/(\w+) \($}
43 or die qq{Invalid CREATE TABLE at line
$. of
$old\n};
45 $old{$table}{name
}=$table;
47 elsif (/^\) TYPE=($tabletype);$/) {
48 $old{$table}{type
}=$1;
50 elsif (/^ (\w+) $datatype$typeval$typeval2{0,3},?$/) {
51 $old{$table}{column
}{$1} = $2;
53 elsif (/^ ($indextype)(?: (\w+))? \(([\w, \(\)]+)\),?$/) {
54 $old{$table}{lc $1."_name"} = $2 ?
$2 : "";
55 $old{$table}{lc $1."pk_target"} = $3;
58 die "Cannot parse line $. of $old:\n$_\n";
63 $datatype = join '|' => qw(
64 SMALLINT INTEGER BIGINT NUMERIC SERIAL
70 $datatype = qr{($datatype)};
72 my ($infunction,$inview,$inrule) = (0,0,0);
74 next if /^\s*\-\-/ or /^\s*$/;
76 next if /^BEGIN;/ or /^SET / or /^COMMIT;/;
77 next if /^CREATE SEQUENCE/;
78 next if /^CREATE(?: UNIQUE)? INDEX/;
79 next if /^CREATE FUNCTION/;
80 next if /^CREATE TRIGGER/ or /^ FOR EACH ROW/;
81 next if /^INSERT INTO/ or /^ VALUES \(/;
82 next if /^ALTER TABLE/;
86 $infunction = $infunction ?
0 : 1;
91 next if /^CREATE VIEW/ and $inview = 1;
97 next if /^CREATE RULE/ and $inrule = 1;
103 if (/^CREATE TABLE "?(\w+)"? \($/) {
105 $new{$table}{name
}=$table;
109 elsif (/^ (\w+) +$datatype/) {
110 $new{$table}{column
}{$1} = $2;
113 die "Cannot parse line $. of $new:\n$_\n";
118 ## Read in known exceptions
121 next unless /^(\w+)\s*:\s*([^#]+)/;
122 my ($name,$val) = ($1,$2);
123 for (split(/\s+/ => $val)) {
129 for my $t (sort keys %old) {
130 if (!exists $new{$t} and !exists $ok{OLD
}{$t}) {
131 print "Table not in $new: $t\n";
134 next if exists $ok{OLD
}{$t};
135 my $oldcol = $old{$t}{column
};
136 my $newcol = $new{$t}{column
};
137 for my $c (keys %$oldcol) {
138 if (!exists $newcol->{$c}) {
139 print "Column $t.$c not in new\n";
143 for my $c (keys %$newcol) {
144 if (!exists $oldcol->{$c}) {
145 print "Column $t.$c not in old\n";
151 for (sort keys %new) {
152 if (!exists $old{$_} and !exists $ok{NEW
}{$_}) {
153 print "Not in $old: $_\n";
160 OLD
: searchindex
## We use tsearch2 directly on the page table instead
161 OLD
: archive
## This is a view due to the char(14) timestamp hack
162 OLD
: user text
## Reserved words, so we use something else
163 NEW
: mwuser pagecontent
## This is what we use
164 NEW
: archive2
## The real archive table
165 NEW
: mediawiki_version
## Just us, for now