Index: trunk/phase3/maintenance/tests/DatabaseSqliteTest.php |
— | — | @@ -36,9 +36,9 @@ |
37 | 37 | $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" ); |
38 | 38 | |
39 | 39 | $this->assertEquals( "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " |
40 | | - . "foo_name TEXT NOT NULL DEFAULT '');", |
| 40 | + . "foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );", |
41 | 41 | $this->replaceVars( "CREATE TABLE /**/foo (foo_key int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, |
42 | | - foo_name varchar(255) binary NOT NULL DEFAULT '') ENGINE=MyISAM;" ) |
| 42 | + foo_name varchar(255) binary NOT NULL DEFAULT '', foo_int tinyint( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;" ) |
43 | 43 | ); |
44 | 44 | |
45 | 45 | $this->assertEquals( "CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );", |
— | — | @@ -49,5 +49,9 @@ |
50 | 50 | $this->replaceVars( "CREATE TABLE text ( text_foo tinytext );" ), |
51 | 51 | 'Table name changed' |
52 | 52 | ); |
| 53 | + |
| 54 | + $this->assertEquals( "ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42", |
| 55 | + $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42") |
| 56 | + ); |
53 | 57 | } |
54 | 58 | } |
\ No newline at end of file |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -518,7 +518,7 @@ |
519 | 519 | |
520 | 520 | protected function replaceVars( $s ) { |
521 | 521 | $s = parent::replaceVars( $s ); |
522 | | - if ( preg_match( '/^\s*CREATE TABLE/i', $s ) ) { |
| 522 | + if ( preg_match( '/^\s*(CREATE|ALTER) TABLE/i', $s ) ) { |
523 | 523 | // CREATE TABLE hacks to allow schema file sharing with MySQL |
524 | 524 | |
525 | 525 | // binary/varbinary column type -> blob |
— | — | @@ -526,7 +526,7 @@ |
527 | 527 | // no such thing as unsigned |
528 | 528 | $s = preg_replace( '/\b(un)?signed\b/i', '', $s ); |
529 | 529 | // INT -> INTEGER |
530 | | - $s = preg_replace( '/\b(tiny|small|medium|big|)int\b/i', 'INTEGER', $s ); |
| 530 | + $s = preg_replace( '/\b(tiny|small|medium|big|)int(\([\s\d]*\)|\b)/i', 'INTEGER', $s ); |
531 | 531 | // varchar -> TEXT |
532 | 532 | $s = preg_replace( '/\bvarchar\(\d+\)/i', 'TEXT', $s ); |
533 | 533 | // TEXT normalization |