r47869 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47868‎ | r47869 | r47870 >
Date:17:29, 27 February 2009
Author:greg
Status:ok
Tags:
Comment:
Quick fixes for new format of tables.sql
Modified paths:
  • /trunk/phase3/maintenance/postgres/compare_schemas.pl (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/postgres/compare_schemas.pl
@@ -9,7 +9,7 @@
1010 use Data::Dumper;
1111 use Cwd;
1212
13 -check_valid_sql();
 13+#check_valid_sql();
1414
1515 my @old = ('../tables.sql');
1616 my $new = 'tables.sql';
@@ -48,7 +48,7 @@
4949
5050 my $typeval = qr{(\(\d+\))?};
5151
52 -my $typeval2 = qr{ signed| unsigned| binary| NOT NULL| NULL| auto_increment| default ['\-\d\w"]+| REFERENCES .+CASCADE};
 52+my $typeval2 = qr{ signed| unsigned| binary| NOT NULL| NULL| PRIMARY KEY| AUTO_INCREMENT| default ['\-\d\w"]+| REFERENCES .+CASCADE};
5353
5454 my $indextype = join '|' => qw(INDEX KEY FULLTEXT), 'PRIMARY KEY', 'UNIQUE INDEX', 'UNIQUE KEY';
5555 $indextype = qr{$indextype};
@@ -96,9 +96,15 @@
9797 chomp;
9898
9999 if (/CREATE\s*TABLE/i) {
100 - m{^CREATE TABLE /\*\$wgDBprefix\*/(\w+) \($}
101 - or die qq{Invalid CREATE TABLE at line $. of $oldfile\n};
102 - $table = $1;
 100+ if (m{^CREATE TABLE /\*_\*/(\w+) \($}) {
 101+ $table = $1;
 102+ }
 103+ elsif (m{^CREATE TABLE /\*\$wgDBprefix\*/(\w+) \($}) {
 104+ $table = $1;
 105+ }
 106+ else {
 107+ die qq{Invalid CREATE TABLE at line $. of $oldfile\n};
 108+ }
103109 $info{$table}{name}=$table;
104110 }
105111 elsif (m{^\) /\*\$wgDBTableOptions\*/}) {
@@ -114,15 +120,15 @@
115121 $info{$table}{type}=$2;
116122 $info{$table}{charset}=$3;
117123 }
118 - elsif (/^ (\w+) $datatype$typeval$typeval2{0,3},?$/) {
 124+ elsif (/^ (\w+) $datatype$typeval$typeval2{0,4},?$/) {
119125 $info{$table}{column}{$1} = $2;
120126 my $extra = $3 || '';
121127 $info{$table}{columnfull}{$1} = "$2$extra";
122128 }
123 - elsif (/^ ($indextype)(?: (\w+))? \(([\w, \(\)]+)\),?$/) {
124 - $info{$table}{lc $1.'_name'} = $2 ? $2 : '';
125 - $info{$table}{lc $1.'pk_target'} = $3;
 129+ elsif (m{^ UNIQUE KEY (\w+) \((.+?)\)}) {
126130 }
 131+ elsif (m{^CREATE (?:UNIQUE )?(?:FULLTEXT )?INDEX /\*i\*/(\w+) ON /\*_\*/(\w+) \((.+?)\);}) {
 132+ }
127133 else {
128134 die "Cannot parse line $. of $oldfile:\n$_\n";
129135 }
@@ -301,6 +307,7 @@
302308
303309 ## Simple text-only strings:
304310 ar_flags tinyblob TEXT
 311+ct_params blob TEXT
305312 fa_minor_mime varbinary(32) TEXT
306313 fa_storage_group varbinary(16) TEXT # Just 'deleted' for now, should stay plain text
307314 fa_storage_key varbinary(64) TEXT # sha1 plus text extension
@@ -331,6 +338,7 @@
332339 qci_type varbinary(32) TEXT
333340 rc_params blob TEXT
334341 rlc_to_blob blob TEXT
 342+ts_tags blob TEXT
335343 ug_group varbinary(16) TEXT
336344 user_email_token binary(32) TEXT
337345 user_ip varbinary(40) TEXT
@@ -497,6 +505,8 @@
498506
499507 my $file = shift;
500508 open my $fh, '<', $file or die qq{Could not open "$file": $!\n};
 509+ my $lastline = '';
 510+ my $inarray = 0;
501511 while (<$fh>) {
502512 if (/FORCE INDEX/ and $file !~ /Database\w*\.php/) {
503513 warn "Found FORCE INDEX string at line $. of $file\n";
@@ -513,6 +523,29 @@
514524 if (/\bGROUP\s+BY\s*\d\b/i and $file !~ /Database\w*\.php/) {
515525 warn "Found GROUP BY # at line $. of $file\n";
516526 }
 527+ if (/wfGetDB\s*\(\s+\)/io) {
 528+ warn "wfGETDB is missing parameters at line $. of $file\n";
 529+ }
 530+ if (/=\s*array\s*\(\s*$/) {
 531+ $inarray = 1;
 532+ next;
 533+ }
 534+ if ($inarray) {
 535+ if (/\s*\);\s*$/) {
 536+ $inarray = 0;
 537+ next;
 538+ }
 539+ next if ! /\w/ or /array\(\s*$/ or /^\s*#/ or m{^\s*//};
 540+ if (! /,/) {
 541+ my $nextline = <$fh>;
 542+ last if ! defined $nextline;
 543+ if ($nextline =~ /^\s*\)[;,]/) {
 544+ $inarray = 0;
 545+ next;
 546+ }
 547+ #warn "Array is missing a comma? Line $. of $file\n";
 548+ }
 549+ }
517550 }
518551 close $fh or die qq{Could not close "$file": $!\n};
519552 return;

Status & tagging log