/** * Drop database represented by the model. * * @param Model $model * * @since 1.1.0 * * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**> */ public function deleteModel($model) { // first remove any automatically created models /** @var $relationField ManyToManyField */ foreach ($model->meta->localManyToMany as $name => $relationField) { if ($relationField->relation->through->meta->autoCreated) { $this->deleteModel($relationField->relation->through); } } $this->schemaManager->dropTable($model->meta->dbTable); }
/** * @param AbstractSchemaManager $schemaM * @param Schema $schema * * @since 1.1.0 * * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**> */ public function createTable($schemaM, $schema) { if ($schemaM->tablesExist('artists')) { $schemaM->dropTable('artists'); } if ($schemaM->tablesExist('user')) { $schemaM->dropTable('user'); } echo 'Tables :: '; $UTable = $schema->createTable('user'); $UTable->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]); $UTable->addColumn('name', 'string', ['length' => 60]); $UTable->setPrimaryKey(['id']); $myTable = $schema->createTable('artists'); $myTable->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]); $myTable->addColumn('user_id', 'integer', ['unsigned' => true]); $myTable->addColumn('name', 'string', ['length' => 60]); $myTable->setPrimaryKey(['id']); $myTable->addForeignKeyConstraint($UTable, array('user_id'), array('id'), array('onUpdate' => 'CASCADE')); $schemaM->createTable($UTable); $schemaM->createTable($myTable); }
/** * Executes the changes. */ public function executeChanges() { $platform = $this->db->getDatabasePlatform(); if (!empty($this->dropTables)) { foreach ($this->dropTables as $t) { $this->sm->dropTable($this->prefix . $t); } } $sql = $this->schema->toSql($platform); if (!empty($sql)) { foreach ($sql as $s) { $this->db->executeUpdate($s); } } //reset schema $this->schema = new Schema([], [], $this->sm->createSchemaConfig()); $this->dropTables = $this->addTables = []; }
/** * {@inheritdoc} */ public function dropTable($name) { $this->tryMethod('dropAutoincrement', $name); parent::dropTable($name); }
/** * @see AbstractSchemaManager::dropTable */ public function dropTable($table) { $this->manager->dropTable($this->replacePrefix($table)); }
public function tearDown() { foreach ($this->_sm->listTableNames() as $tableName) { $this->_sm->dropTable($tableName); } }