简体   繁体   中英

How to rollback plugin's migration in OctoberCMS?

I has created plugin with one migration. My version.yaml is

1.0.1: First version of user
1.0.2:
    - Added new fields to User model
    - alter_table_users_add_contact_fields.php

My updates directory contains one migration file alter_table_users_add_contact_fields.php .

<?php

namespace Mnv\Reminder\Updates;

use Schema;
use October\Rain\Database\Updates\Migration;

class CreateTableNewsRead extends Migration
{
    protected $table = 'mnv_news_read';

    public function up()
    {
        Schema::create($this->table, function($table)
        {
            $table->engine = 'InnoDB';
            $table->increments('id');

            $table->integer('news_id');
            $table->foreign('news_id')->references('id')->on('rainlab_blog_posts')->onUpdate('cascade')->onDelete('cascade');

            $table->integer('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');

            $table->timestamp('read_at');

            $table->index([
                'news_id',
                'user_id',
            ]);

            $table->index([
                'user_id',
                'news_id',
            ]);
        });
    }

    public function down()
    {
        Schema::dropIfExists($this->table);
    }
}

I has successfully ran this migration using console command php artisan october:up .

But now I want to rollback this migration. As I see there is no informatino about this migration in table migrations . So I cant rollback this migration usins command php artisan migrate:rollback .

I found that information about plugin version contains in table system_plugin_versions . I has manually deleted my table mnv_news_read and manually deleted correspond records from system_plugin_versions and system_plugin_history tables.

drop table mnv_news_read;
delete from system_plugin_history where code = 'Mnv.Reminder';
delete from system_plugin_versions where code = 'Mnv.Reminder';

After that I tryed to run php artisan october:up again. It completed successfully.

My question is how to rollback plugin's migration correctly?

One way of rolling back migrations is via the builder plugin in admin control panel (make sure to install this plugin first if you have not already).

  1. Select the builder plugin menu (from top of the page)
  2. Select your plugin (by clicking on the arrow '>' button)
  3. From left side menu, select Versions
  4. Select the version you want to rollback
  5. Click on the Rollback version button

根据文档,您可以在控制台中运行命令:

php artisan plugin:rollback AuthorName.PluginName 1.2.3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM