/** * Rename this table and all of its change-tracker entries. * @param string $new_name */ public function rename($new_name) { if ($this->getDatabase()->getTable($new_name)) { throw new \Exception("Table '{$new_name}' already exists"); } $old_name = $this->getName(); $this->getDatabase()->query("RENAME TABLE `{$old_name}` TO `{$new_name}`;"); $this->getDatabase()->reset(); $new = $this->getDatabase()->getTable($new_name, false); if (!$new) { throw new \Exception("Table '{$old_name}' was not renamed to '{$new_name}'"); } $this->name = $new->getName(); $this->getDatabase()->query("UPDATE `" . ChangeTracker::changes_name() . "`" . " SET `table_name` = '{$new_name}' " . " WHERE `table_name` = '{$old_name}';"); }
/** * @testdox A record can be deleted, and it's history along with it. */ public function delete() { $testTypes = $this->db->getTable('test_types'); $changesets = $this->db->getTable(ChangeTracker::changesets_name()); // Create two, to make sure only one is deleted. $testTypes->saveRecord(array('title' => 'First Type')); $testTypes->saveRecord(array('title' => 'Second Type')); // Make sure we've got the right number of changesets (one is from the install process). $this->assertEquals(2, $testTypes->getRecordCount()); $this->assertEquals(3, $this->db->query('SELECT COUNT(*) FROM changesets')->fetchColumn()); $this->assertEquals(3, $changesets->getRecordCount()); // Delete a record, and both counts should go down by one. $testTypes->deleteRecord(2); $this->assertEquals(1, $testTypes->getRecordCount()); $this->assertEquals(2, $this->db->query('SELECT COUNT(*) FROM changesets')->fetchColumn()); $this->assertEquals(2, $changesets->getRecordCount()); }