rinvex / laravel-attributes

⚠️ [ABANDONED] Rinvex Attributable is a robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
MIT License
433 stars 104 forks source link

SOLVED: Renamed Migrations #121

Closed cord closed 4 years ago

cord commented 4 years ago

The migration files have been renamed through the version updates, so when updating the new migrations fail as the tables already exist.

Following my solution to support both updating existing installations but also new installs.

config/rinvex.attributes.php add: 'autoload_migrations' => false

to disable autoloading the package migrations as they are executed before the custom migrations.

copy all migrations from vendor/rinvex/laravel-attributes/database/migrations to your migrations folder.

create a new migration, e.g. 2000_01_01_000001_cleanUpMigrations.php

class CleanUpMigrations extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // name of rinvex.attributes migrations have changed
        $migrations = [
            '2017_01_19_040614_create_attributes_table' => '2020_01_01_000001_create_attributes_table',
            '2017_01_19_040617_create_attribute_boolean_values_table' => '2020_01_01_000003_create_attribute_boolean_values_table',
            '2017_01_19_040620_create_attribute_datetime_values_table' => '2020_01_01_000004_create_attribute_datetime_values_table',
            '2017_01_19_040622_create_attribute_integer_values_table' => '2020_01_01_000005_create_attribute_integer_values_table',
            '2017_01_19_040703_create_attribute_varchar_values_table' => '2020_01_01_000006_create_attribute_varchar_values_table',
            '2017_01_21_075238_create_attribute_entity_table' => '2020_01_01_000007_create_attribute_entity_table',
            '2017_03_30_012102_create_attribute_text_values_table' => '2020_01_01_000002_create_attribute_text_values_table',
        ];
        foreach ($migrations as $old => $new) {
            \Illuminate\Support\Facades\DB::statement("UPDATE migrations SET migration = replace(migration, '" . $old . "', '" . $new . "');");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

    }
}
Omranic commented 4 years ago

Thank you @cord I tagged this issue as "helpful" so others may refer to it later. And sorry for any inconvenience this update may caused.