Add test to ensure unwated migrations are not produced
[MAILPOET-1717]
This commit is contained in:
@ -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),',
|
||||
|
@ -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() {
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user