wn-builder-plugin icon indicating copy to clipboard operation
wn-builder-plugin copied to clipboard

Newly created fields on the model - not correctly increase number of class name migration file

Open dimti opened this issue 3 years ago • 3 comments

Strange behaviour - if i created new field in database - on first this actions on the table - that is okay. But next field - have 2 number - as suffix of migration class name and colissing with previous migration class name

image

dimti avatar Nov 26 '22 16:11 dimti

Number inscreases in that code block: classes/MigrationModel.php::makeScriptFileNameUnique

And this use snake-case separator between base file name and suffix number:

    public function makeScriptFileNameUnique()
    {
        $updatesPath = $this->getPluginUpdatesPath();
        $baseFileName = $fileName = $this->scriptFileName;

        $counter = 2;
        while (File::isFile($updatesPath.'/'.$fileName.'.php')) {
            $fileName = $baseFileName.'_'.$counter;
            $counter++;
        }

        return $this->scriptFileName = $fileName;
    }

But in currently class and in method assignFileName used Str::snake helper for assigned file name for migration - and that uses from migrations part of wn-builder.

In Migration Model save method - strangelly activate reassign file name for existing migration. I turn off this behaviour

From:

        if (!strlen($this->scriptFileName) || !$this->isNewModel()) {
            $this->assignFileName();
        }

To:

        if (!strlen($this->scriptFileName) || $this->isNewModel()) {
            $this->assignFileName();
        }

if that is acceptable solution - please give me call backout about pr.

https://github.com/dimti/wn-builder-plugin/commit/b1c4e3fa30b7165f78f7122fe45821f3997000d0

dimti avatar Nov 26 '22 17:11 dimti

Personally I'd like to see us switch to using the anonymous class migration method that we now use in the core scaffolds: https://github.com/wintercms/winter/blob/develop/modules/system/console/scaffold/migration/migration.create.stub; although that would necessitate a new major version to indicate that we only support Laravel 9 / Winter v1.2 going forward.

LukeTowers avatar Nov 29 '22 19:11 LukeTowers

I verified this patch, and works as expected... Great development!

SledgehammerPL avatar Dec 20 '22 21:12 SledgehammerPL

This should be fixed in the next release.

bennothommo avatar Sep 09 '24 07:09 bennothommo