Esempio n. 1
0
 protected function dropColumn()
 {
     $restore = $this->getRestoreFileName();
     if (Sabel_Db_Migration_Manager::isUpgrade()) {
         if (is_file($restore)) {
             unlink($restore);
         }
         $columns = $this->getReader()->readDropColumn()->getColumns();
         $schema = $this->getSchema()->getTable($this->tblName);
         $sColumns = $schema->getColumns();
         $writer = new Sabel_Db_Migration_Writer($restore);
         $writer->writeColumns($schema, $columns);
         $writer->close();
         foreach ($columns as $column) {
             if (isset($sColumns[$column])) {
                 unset($sColumns[$column]);
             } else {
                 $warning = "column '{$column}' does not exist. (SKIP)";
                 Sabel_Console::warning($warning);
             }
         }
         $this->dropColumnsAndRemakeTable($sColumns, $schema);
     } else {
         $columns = $this->getReader($restore)->readAddColumn()->getColumns();
         $this->execAddColumn($columns);
     }
 }
Esempio n. 2
0
 public function execute()
 {
     if (Sabel_Db_Migration_Manager::isUpgrade()) {
         $queries = $this->upgradeQueries;
     } else {
         $queries = $this->downgradeQueries;
     }
     $stmt = Sabel_Db_Migration_Manager::getStatement();
     foreach ($queries as $query) {
         $stmt->setQuery($query)->execute();
     }
 }
Esempio n. 3
0
 protected function addColumn()
 {
     $columns = $this->getReader()->readAddColumn()->getColumns();
     if (Sabel_Db_Migration_Manager::isUpgrade()) {
         $this->execAddColumn($columns);
     } else {
         $tblName = convert_to_tablename($this->mdlName);
         $quotedTblName = $this->quoteIdentifier($tblName);
         foreach ($columns as $column) {
             $this->dropDefaultConstraint($tblName, $column->name);
             $colName = $this->quoteIdentifier($column->name);
             $this->executeQuery("ALTER TABLE {$tblName} DROP COLUMN {$colName}");
         }
     }
 }
Esempio n. 4
0
 protected function drop()
 {
     $restore = $this->getRestoreFileName();
     if (Sabel_Db_Migration_Manager::isUpgrade()) {
         if (is_file($restore)) {
             unlink($restore);
         }
         $schema = $this->getSchema()->getTable($this->tblName);
         $writer = new Sabel_Db_Migration_Writer($restore);
         $writer->writeTable($schema)->close();
         $this->executeQuery("DROP TABLE " . $this->quoteIdentifier($this->tblName));
         $this->dropSequence($schema->getSequenceColumn());
     } else {
         $this->createTable($restore);
     }
 }
Esempio n. 5
0
 public function drop()
 {
     if (Sabel_Db_Migration_Manager::isUpgrade()) {
         $restore = $this->getRestoreFileName();
         if (is_file($restore)) {
             unlink($restore);
         }
         $schema = $this->getSchema();
         $tblSchema = $schema->getTable($this->tblName);
         $engine = $schema->getTableEngine($this->tblName);
         $writer = new Sabel_Db_Migration_Writer($restore);
         $writer->writeTable($tblSchema);
         $writer->write('$create->options("engine", "' . $engine . '");');
         $writer->write(PHP_EOL)->close();
         $this->executeQuery("DROP TABLE " . $this->quoteIdentifier($this->tblName));
     } else {
         $this->createTable($this->getRestoreFileName());
     }
 }
Esempio n. 6
0
 protected function changeColumn()
 {
     $schema = $this->getSchema()->getTable($this->tblName);
     $restore = $this->getRestoreFileName();
     if (Sabel_Db_Migration_Manager::isUpgrade()) {
         if (is_file($restore)) {
             unlink($restore);
         }
         $names = array();
         $columns = $this->getReader()->readChangeColumn()->getColumns();
         foreach ($columns as $column) {
             $names[] = $column->name;
         }
         $writer = new Sabel_Db_Migration_Writer($restore);
         $writer->writeColumns($schema, $names, '$change')->close();
         $this->changeColumnUpgrade($columns, $schema);
     } else {
         $columns = $this->getReader($restore)->readChangeColumn()->getColumns();
         $this->changeColumnDowngrade($columns, $schema);
     }
 }