Skip to content

Commit 0eed4ae

Browse files
author
Alexandre
committed
Merge pull request #3 from jrivron/master
add dynamic changelog table
2 parents 277e9dc + 0a04e5c commit 0eed4ae

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

Migrator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public function getLocaleList() {
546546
*
547547
*/
548548
public function getDbList() {
549-
$sqlResult = $this->getDb()->query('SELECT * FROM changelog ORDER BY id');
549+
$sqlResult = $this->getDb()->query('SELECT * FROM ' .$config['changelog'] .' ORDER BY id');
550550

551551
$migrationList = array();
552552
foreach ($sqlResult as $row) {
@@ -644,7 +644,7 @@ private function up(Migration $migration) {
644644

645645
// insert into changelog
646646
$this->getDb()->exec(
647-
"INSERT INTO changelog (id, applied_at, description, version) VALUES ("
647+
"INSERT INTO " .$config['changelog'] ." (id, applied_at, description, version) VALUES ("
648648
. $migration->getId() . ", '"
649649
. $date . "', '"
650650
. $migration->getDescription() . "', '"
@@ -694,7 +694,7 @@ private function down(Migration $migration) {
694694

695695
// insert into changelog
696696
$this->getDb()->exec(
697-
"DELETE FROM changelog WHERE id = " . $migration->getId()
697+
"DELETE FROM " .$config['changelog'] ." WHERE id = " . $migration->getId()
698698
);
699699

700700
if ($sqlReturnCode != '0') {

tests/MigrateTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ class MigrateTest extends PHPUnit_Framework_TestCase
99
private static $db;
1010
private static $dbName;
1111
private static $migrationPath;
12+
private static $changelog;
1213

1314
public static function setUpBeforeClass() {
1415
self::$dbName = dirname(__FILE__) . '/test.sqlite';
1516
unlink(self::$dbName);
17+
18+
self::$changelog = 'mychangelog';
1619

1720
self::$db = new PDO('sqlite:' . self::$dbName, '', '');
1821
self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
19-
self::$db->exec("create table changelog (
22+
self::$db->exec("create table " .self::$changelog ."(
2023
id numeric(20,0),
2124
applied_at character varying(25),
2225
version character varying(25),
@@ -56,9 +59,9 @@ public function testGetLocaleList() {
5659
* @Test
5760
*/
5861
public function testGetDbList() {
59-
self::$db->query("INSERT INTO changelog (id, applied_at, description) VALUES (20100101, '2010-01-01', 'description 1')");
60-
self::$db->query("INSERT INTO changelog (id, applied_at, description) VALUES (20100102, '2010-01-02', 'description 2')");
61-
self::$db->query("INSERT INTO changelog (id, applied_at, description) VALUES (20100103, '2010-01-03', 'description 3')");
62+
self::$db->query("INSERT INTO " .self::$changelog ." (id, applied_at, description) VALUES (20100101, '2010-01-01', 'description 1')");
63+
self::$db->query("INSERT INTO " .self::$changelog ." (id, applied_at, description) VALUES (20100102, '2010-01-02', 'description 2')");
64+
self::$db->query("INSERT INTO " .self::$changelog ." (id, applied_at, description) VALUES (20100103, '2010-01-03', 'description 3')");
6265

6366
$expected = array(
6467
'20100101' => new Migration('20100101', '2010-01-01', 'description 1', '20100101_description_1.sql', true),
@@ -71,7 +74,7 @@ public function testGetDbList() {
7174

7275
$migrationList = $migrator->getDbList();
7376

74-
self::$db->query("DELETE FROM changelog");
77+
self::$db->query("DELETE FROM " .self::$changelog );
7578

7679
$this->assertEquals($expected, $migrationList);
7780

@@ -90,10 +93,10 @@ public function testGetMigrationList() {
9093
touch(self::$migrationPath . "/20100104_description_2.sql");
9194
touch(self::$migrationPath . "/20100105_description_3.sql");
9295

93-
self::$db->query("INSERT INTO changelog (id, applied_at, description) VALUES (20100100, '2009-12-30', 'description 0')");
94-
self::$db->query("INSERT INTO changelog (id, applied_at, description) VALUES (20100103, '2010-01-01', 'description 1')");
95-
self::$db->query("INSERT INTO changelog (id, applied_at, description) VALUES (20100104, '2010-01-02', 'description 2')");
96-
self::$db->query("INSERT INTO changelog (id, applied_at, description) VALUES (20100105, '2010-01-03', 'description 3')");
96+
self::$db->query("INSERT INTO " .self::$changelog ." (id, applied_at, description) VALUES (20100100, '2009-12-30', 'description 0')");
97+
self::$db->query("INSERT INTO " .self::$changelog ." (id, applied_at, description) VALUES (20100103, '2010-01-01', 'description 1')");
98+
self::$db->query("INSERT INTO " .self::$changelog ." (id, applied_at, description) VALUES (20100104, '2010-01-02', 'description 2')");
99+
self::$db->query("INSERT INTO " .self::$changelog ." (id, applied_at, description) VALUES (20100105, '2010-01-03', 'description 3')");
97100

98101
$expected = array(
99102
'20100100' => new Migration('20100100', '2009-12-30', 'description 0', '20100100_description_0.sql', true),
@@ -108,7 +111,7 @@ public function testGetMigrationList() {
108111
$migrator->setDb(self::$db);
109112
$migrationList = $migrator->getMigrationList();
110113

111-
self::$db->query("DELETE FROM changelog");
114+
self::$db->query("DELETE FROM " .self::$changelog );
112115

113116
unlink(self::$migrationPath . "/20100101_add_table_1.sql");
114117
unlink(self::$migrationPath . "/20100102_add_table_2.sql");

0 commit comments

Comments
 (0)