This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

corymillz40435183
corymillz40435183

I extended the user's plugin going by how it is done and it works ok. Now i want to add new fields using the same plugin i created for the extension by adding this as an additional file in the updates folder

<?php namespace Corymillz\Store\Updates;

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

class AddNewFeilds extends Migration
{

    public function up()
    {
        Schema::table('users', function($table)
        {

            $table->string('store_title_font')->nullable();
             $table->string('store_title_font_color')->nullable();
            $table->string('store_description_font')->nullable();
            $table->string('store_description_font_color')->nullable();
            $table->string('background_size')->nullable();

        });
    }

    public function down()
{
    Schema::table('users', function($table) {
        $table->dropColumn([
            'store_title_font',
            'store_title_font_color',
            'store_description_font',
            'store_description_font_color',
            'background_size',

        ]);
    });
} 

}

What i am not clear about or scared to try is what happens when i run php artisan plugin:refresh. Will first table be dropped and rebuilt with the data saved in it deleted? or is there a different way of adding new fields to the already extended fields.

Last updated

mjauvin
mjauvin

You can use php artisan october:up to run plugin migrations without losing data.

neilcarpenter
neilcarpenter

If you ran plugin:refresh on your plugin, it would run the down() method in your migration, this would delete the data.

It would then run the up() method when rebuilding the database and re-create the columns. But they would be empty. (Unless you specified some default value for them)

You could skip the dropColumn() in your down method if you wanted to save the data in them.

You'd have to check with the columns exist in your up() method though other it would fail with an error columns already exist.

There is a method on the Schema class that allows you to check this.

Schema::hasColumn('table_name', 'column_name');

An alternative thing you could do is temporarily save the data from those columns somewhere, either in a temp table on your database or some sqllite database or something.

Then get it out of there to populate the users table once it's been updated in the up() method.

Then empty/delete the temp data once it's finished.

Last updated

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.