xxxxxxxxxx
// Include old and new enum values
DB::statement("ALTER TABLE packages MODIFY COLUMN weight_unit ENUM('Kg.', 'Gm.', 'Grams', 'Kgs', 'Pounds')");
// Replace Kg. with Kgs
Packages::where('weight_unit', 'Kg.')->update(['weight_unit' => 'Kgs']);
// Replace Gm. with Grams
Packages::where('weight_unit', 'Gm.')->update(['weight_unit' => 'Grams']);
// Delete old values
DB::statement("ALTER TABLE packages MODIFY COLUMN weight_unit ENUM('Grams', 'Kgs', 'Pounds')");
xxxxxxxxxx
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Create new temp column
Schema::table('pages', function (Blueprint $table) {
$table->string('type_new', 32)->default("default");
});
// Copy data
DB::statement("UPDATE pages SET type_new = type");
// Drop old column
Schema::table('pages', function (Blueprint $table) {
$table->dropColumn('type');
});
// Create new column with old's name
Schema::table('pages', function (Blueprint $table) {
$table->string('type', 32)->default("default")->after("books_id");
});
// Copy data back
DB::statement("UPDATE pages SET type = type_new");
// Delete
Schema::table('pages', function (Blueprint $table) {
$table->dropColumn('type_new');
});
}