Add test to ensure unwated migrations are not produced

[MAILPOET-1717]
This commit is contained in:
Jan Jakeš
2019-01-30 14:00:12 +01:00
parent fc4f0a2851
commit 5495e4c2eb
2 changed files with 16 additions and 9 deletions

View File

@ -51,13 +51,12 @@ class Migrator {
function up() {
global $wpdb;
$_this = $this;
$migrate = function($model) use($_this) {
$output = [];
foreach($this->models as $model) {
$modelMethod = Helpers::underscoreToCamelCase($model);
dbDelta($_this->$modelMethod());
};
array_map($migrate, $this->models);
$output = array_merge(dbDelta($this->$modelMethod()), $output);
}
return $output;
}
function down() {
@ -137,8 +136,8 @@ class Migrator {
'id int(11) unsigned NOT NULL AUTO_INCREMENT,',
'newsletter_id int(11) unsigned NOT NULL,',
'task_id int(11) unsigned NOT NULL,',
'created_at TIMESTAMP NULL,',
'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'created_at timestamp NULL,',
'updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
'PRIMARY KEY (id),',
'UNIQUE KEY newsletter_id_task_id (newsletter_id, task_id),',
'KEY task_id (task_id)',
@ -151,7 +150,7 @@ class Migrator {
'task_id int(11) unsigned NOT NULL,',
'subscriber_id int(11) unsigned NOT NULL,',
'processed int(1) NOT NULL,',
'failed SMALLINT(1) NOT NULL DEFAULT 0,',
'failed smallint(1) NOT NULL DEFAULT 0,',
'error text NULL,',
'created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,',
'PRIMARY KEY (task_id, subscriber_id),',

View File

@ -14,6 +14,14 @@ class MigratorTest extends \MailPoetTest {
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() {
}
}