コード例 #1
0
 /**
  * Retrieve table foreign keys definition array for create table
  *
  * @param Table $table
  * @return string[]
  */
 protected function _getForeignKeysDefinition(Table $table)
 {
     $definition = array();
     $relations = $table->getForeignKeys();
     if (!empty($relations)) {
         foreach ($relations as $fkData) {
             $onDelete = $this->_getDdlAction($fkData['ON_DELETE']);
             $onUpdate = $this->_getDdlAction($fkData['ON_UPDATE']);
             $definition[] = sprintf('  CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s) ON DELETE %s ON UPDATE %s', $this->quoteIdentifier($fkData['FK_NAME']), $this->quoteIdentifier($fkData['COLUMN_NAME']), $this->quoteIdentifier($fkData['REF_TABLE_NAME']), $this->quoteIdentifier($fkData['REF_COLUMN_NAME']), $onDelete, $onUpdate);
         }
     }
     return $definition;
 }
コード例 #2
0
 /**
  * drops all keys and then recreates them
  *
  * @param string $mode
  * @param Table $table
  * @throws \Zend_Db_Exception
  */
 private function migrateKeys($mode, Table $table)
 {
     switch ($mode) {
         case 'refresh_idx':
             foreach ($this->getIndexList($table->getName()) as $index) {
                 if ($index['KEY_NAME'] !== 'PRIMARY') {
                     $this->dropIndex($table->getName(), $index['KEY_NAME']);
                 }
             }
             foreach ($table->getIndexes() as $index) {
                 $ic = [];
                 foreach ($index['COLUMNS'] as $c) {
                     $ic[] = $c['NAME'];
                 }
                 $this->addIndex($table->getName(), $index['INDEX_NAME'], $ic, $index['TYPE']);
             }
             break;
         case 'refresh_fk':
             foreach ($this->getForeignKeys($table->getName()) as $fk) {
                 $this->dropForeignKey($table->getName(), $fk['FK_NAME']);
             }
             foreach ($table->getForeignKeys() as $fk) {
                 $this->addForeignKey($fk['FK_NAME'], $table->getName(), $fk['COLUMN_NAME'], $fk['REF_TABLE_NAME'], $fk['REF_COLUMN_NAME'], $fk['ON_DELETE'], $fk['ON_UPDATE']);
             }
             break;
     }
 }