rainlab / builder-plugin

Visual development tool for October CMS
Other
171 stars 61 forks source link

Feature request: Migrations for update columns #361

Closed snipiba closed 2 years ago

snipiba commented 2 years ago

Currently changing database field generate migration file, where original field was dropped (dropColumn) and new column is created. This will drop all data, thats will be fail from more point of view...

Update please to use $table->renameColumn instead.

In UP: Schema::table('table_name', function(Blueprint $table) { $table->renameColumn('old_name', 'new_name'); });

In DOWN: Schema::table('table_name', function(Blueprint $table) { $table->renameColumn('new_name', 'old_name'); });

daftspunk commented 2 years ago

Hi @snipiba

We may need more information on this one. Renaming a column uses renameColumn already:

<?php namespace October\Test\Updates;

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

class BuilderTableUpdateOctoberTestMeta extends Migration
{
    public function up()
    {
        Schema::table('october_test_meta', function($table)
        {
            $table->renameColumn('robot_follow', 'robot_follow2');
        });
    }

    public function down()
    {
        Schema::table('october_test_meta', function($table)
        {
            $table->renameColumn('robot_follow2', 'robot_follow');
        });
    }
}