TheDragonCode/laravel-deploy-operations

Upgrading from 2.x to 4.x fails on database migrations

tibbsa opened this issue · 1 comments

Environment

  • PHP Version: 8.1.3
  • Database Driver & Version: pgsql (Postgresql 14.5)
  • Actions Version: 4.1.0
  • Laravel Version: 9.41.0

Issue description

This likely won't impact many people at this stage, but I am in the process of upgrading from Laravel-Migration-Actions 2.x to Laravel-Actions 4.x, and ran into an issue because the BaseChangeColumn migration uses $this->config->table to determine the table name.

However, by 4.x, the configured default table name is 'actions' rather than 'migration_actions', and because of that, the changes in BaseChangeColumn are not actually applied.

The result was that while php artisan migrate appeared to work, but on the first run of php artisan actions, it did not recognize that any of the actions had already run and tried to run them again. An SQL error then arose after the first action completed, because it could not save the action name/batch number into the database since the 'migration' field no longer existed:

[previous exception] [object] (PDOException(code: 42703): SQLSTATE[42703]: Undefined column: 7 ERROR:  column \"action\" of relation \"actions\" does not exist
LINE 1: insert into \"actions\" (\"action\", \"batch\") values ($1, $2)

My solution was to add an additional migration in the app itself to make those changes -after- the rename was completed.

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::table('actions', function (Blueprint $table) {
            $table->renameColumn('migration', 'action');
            $table->unsignedInteger('batch')->change();
        });
    }
};

Steps to reproduce

php artisan migrate followed by php artisan actions after upgrading from 2.x to 4.x

First you need to upgrade to version 3 and then to version 4.

The easiest way to upgrade:

To 3 from 2:

composer require dragon-code/laravel-migration-actions:^3.0
php artisan migrate:actions:upgrade
php artisan migrate

To 4 from 3:

composer remove dragon-code/laravel-migration-actions
composer require dragon-code/laravel-actions:^4.0
php artisan actions:upgrade
php artisan migrate

I have corrected a flaw in the upgrade documentation: https://actions.dragon-code.pro/prologue/upgrade-guide/