/** * @param string $s * @return string */ protected function replaceVars($s) { $s = parent::replaceVars($s); if (preg_match('/^\\s*(CREATE|ALTER) TABLE/i', $s)) { // CREATE TABLE hacks to allow schema file sharing with MySQL // binary/varbinary column type -> blob $s = preg_replace('/\\b(var)?binary(\\(\\d+\\))/i', 'BLOB', $s); // no such thing as unsigned $s = preg_replace('/\\b(un)?signed\\b/i', '', $s); // INT -> INTEGER $s = preg_replace('/\\b(tiny|small|medium|big|)int(\\s*\\(\\s*\\d+\\s*\\)|\\b)/i', 'INTEGER', $s); // floating point types -> REAL $s = preg_replace('/\\b(float|double(\\s+precision)?)(\\s*\\(\\s*\\d+\\s*(,\\s*\\d+\\s*)?\\)|\\b)/i', 'REAL', $s); // varchar -> TEXT $s = preg_replace('/\\b(var)?char\\s*\\(.*?\\)/i', 'TEXT', $s); // TEXT normalization $s = preg_replace('/\\b(tiny|medium|long)text\\b/i', 'TEXT', $s); // BLOB normalization $s = preg_replace('/\\b(tiny|small|medium|long|)blob\\b/i', 'BLOB', $s); // BOOL -> INTEGER $s = preg_replace('/\\bbool(ean)?\\b/i', 'INTEGER', $s); // DATETIME -> TEXT $s = preg_replace('/\\b(datetime|timestamp)\\b/i', 'TEXT', $s); // No ENUM type $s = preg_replace('/\\benum\\s*\\([^)]*\\)/i', 'TEXT', $s); // binary collation type -> nothing $s = preg_replace('/\\bbinary\\b/i', '', $s); // auto_increment -> autoincrement $s = preg_replace('/\\bauto_increment\\b/i', 'AUTOINCREMENT', $s); // No explicit options $s = preg_replace('/\\)[^);]*(;?)\\s*$/', ')\\1', $s); // AUTOINCREMENT should immedidately follow PRIMARY KEY $s = preg_replace('/primary key (.*?) autoincrement/i', 'PRIMARY KEY AUTOINCREMENT $1', $s); } elseif (preg_match('/^\\s*CREATE (\\s*(?:UNIQUE|FULLTEXT)\\s+)?INDEX/i', $s)) { // No truncated indexes $s = preg_replace('/\\(\\d+\\)/', '', $s); // No FULLTEXT $s = preg_replace('/\\bfulltext\\b/i', '', $s); } elseif (preg_match('/^\\s*DROP INDEX/i', $s)) { // DROP INDEX is database-wide, not table-specific, so no ON <table> clause. $s = preg_replace('/\\sON\\s+[^\\s]*/i', '', $s); } elseif (preg_match('/^\\s*INSERT IGNORE\\b/i', $s)) { // INSERT IGNORE --> INSERT OR IGNORE $s = preg_replace('/^\\s*INSERT IGNORE\\b/i', 'INSERT OR IGNORE', $s); } return $s; }
/** * Postgres specific version of replaceVars. * Calls the parent version in Database.php * * @param string $ins SQL string, read from a stream (usually tables.sql) * @return string SQL string */ protected function replaceVars($ins) { $ins = parent::replaceVars($ins); if ($this->numericVersion >= 8.300000000000001) { // Thanks for not providing backwards-compatibility, 8.3 $ins = preg_replace("/to_tsvector\\s*\\(\\s*'default'\\s*,/", 'to_tsvector(', $ins); } if ($this->numericVersion <= 8.1) { // Our minimum version $ins = str_replace('USING gin', 'USING gist', $ins); } return $ins; }
protected function replaceVars($s) { $s = parent::replaceVars($s); if (preg_match('/^\\s*CREATE TABLE/i', $s)) { // CREATE TABLE hacks to allow schema file sharing with MySQL // binary/varbinary column type -> blob $s = preg_replace('/\\b(var)?binary(\\(\\d+\\))/i', 'blob\\1', $s); // no such thing as unsigned $s = preg_replace('/\\bunsigned\\b/i', '', $s); // INT -> INTEGER for primary keys $s = preg_replacE('/\\bint\\b/i', 'integer', $s); // No ENUM type $s = preg_replace('/enum\\([^)]*\\)/i', 'blob', $s); // binary collation type -> nothing $s = preg_replace('/\\bbinary\\b/i', '', $s); // auto_increment -> autoincrement $s = preg_replace('/\\bauto_increment\\b/i', 'autoincrement', $s); // No explicit options $s = preg_replace('/\\)[^)]*$/', ')', $s); } elseif (preg_match('/^\\s*CREATE (\\s*(?:UNIQUE|FULLTEXT)\\s+)?INDEX/i', $s)) { // No truncated indexes $s = preg_replace('/\\(\\d+\\)/', '', $s); // No FULLTEXT $s = preg_replace('/\\bfulltext\\b/i', '', $s); } return $s; }