Add test to ensure unwated migrations are not produced
[MAILPOET-1717]
This commit is contained in:
@ -51,13 +51,12 @@ class Migrator {
|
|||||||
function up() {
|
function up() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$_this = $this;
|
$output = [];
|
||||||
$migrate = function($model) use($_this) {
|
foreach($this->models as $model) {
|
||||||
$modelMethod = Helpers::underscoreToCamelCase($model);
|
$modelMethod = Helpers::underscoreToCamelCase($model);
|
||||||
dbDelta($_this->$modelMethod());
|
$output = array_merge(dbDelta($this->$modelMethod()), $output);
|
||||||
};
|
}
|
||||||
|
return $output;
|
||||||
array_map($migrate, $this->models);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function down() {
|
function down() {
|
||||||
@ -137,8 +136,8 @@ class Migrator {
|
|||||||
'id int(11) unsigned NOT NULL AUTO_INCREMENT,',
|
'id int(11) unsigned NOT NULL AUTO_INCREMENT,',
|
||||||
'newsletter_id int(11) unsigned NOT NULL,',
|
'newsletter_id int(11) unsigned NOT NULL,',
|
||||||
'task_id int(11) unsigned NOT NULL,',
|
'task_id int(11) unsigned NOT NULL,',
|
||||||
'created_at TIMESTAMP NULL,',
|
'created_at timestamp NULL,',
|
||||||
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
'updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (id),',
|
'PRIMARY KEY (id),',
|
||||||
'UNIQUE KEY newsletter_id_task_id (newsletter_id, task_id),',
|
'UNIQUE KEY newsletter_id_task_id (newsletter_id, task_id),',
|
||||||
'KEY task_id (task_id)',
|
'KEY task_id (task_id)',
|
||||||
@ -151,7 +150,7 @@ class Migrator {
|
|||||||
'task_id int(11) unsigned NOT NULL,',
|
'task_id int(11) unsigned NOT NULL,',
|
||||||
'subscriber_id int(11) unsigned NOT NULL,',
|
'subscriber_id int(11) unsigned NOT NULL,',
|
||||||
'processed int(1) NOT NULL,',
|
'processed int(1) NOT NULL,',
|
||||||
'failed SMALLINT(1) NOT NULL DEFAULT 0,',
|
'failed smallint(1) NOT NULL DEFAULT 0,',
|
||||||
'error text NULL,',
|
'error text NULL,',
|
||||||
'created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,',
|
'created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,',
|
||||||
'PRIMARY KEY (task_id, subscriber_id),',
|
'PRIMARY KEY (task_id, subscriber_id),',
|
||||||
|
@ -14,6 +14,14 @@ class MigratorTest extends \MailPoetTest {
|
|||||||
expect($subscriber_sql)->contains($expected_table);
|
expect($subscriber_sql)->contains($expected_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItDoesNotMigrateWhenDatabaseIsUpToDate() {
|
||||||
|
$changes = $this->migrator->up();
|
||||||
|
$this->assertEmpty(
|
||||||
|
$changes,
|
||||||
|
"Expected no migrations. However, the following changes are planned:\n\t" . implode($changes, "\n\t")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user