From f2378ccb34aaff0ad97743c9ff413183b2b5df32 Mon Sep 17 00:00:00 2001 From: Chris Pelzer Date: Thu, 3 Nov 2022 08:04:10 -0400 Subject: [PATCH 1/3] Implement the option to have the migrations utilize Laravels `loadMigrationsFrom` without the need to publish the migrations. Renamed the migration to work with both loadMigrationsFrom and publishing, publishing required the date/time to be part of the file to be consistent and not have new migrations, loadMigrationsFrom the date/time doesn't matter. --- README.md | 17 +++++++++++++++-- config/ckeditor-field.php | 13 +++++++++++++ ...00000_create_ckeditor_attachment_tables.php} | 0 src/CKEditor4FieldServiceProvider.php | 10 +++++++--- 4 files changed, 35 insertions(+), 5 deletions(-) rename database/migrations/{create_ckeditor_attachment_tables.php => 2022_07_25_000000_create_ckeditor_attachment_tables.php} (100%) diff --git a/README.md b/README.md index 10afff4..664f4aa 100644 --- a/README.md +++ b/README.md @@ -110,11 +110,24 @@ The `nova-ckeditor4-field` allows the use of file uploads by extending the attac ```bash php artisan vendor:publish --tag=nova-ckeditor4-field-config # Make sure the config file is published +php artisan migrate # Run the migrations +``` + +The package migrations will automatically run when running `php artisan migrate`. + +If you wish do not wish to use the [Laravel Migration](https://laravel.com/docs/9.x/packages#migrations), but publish the migration yourself to your project. +Within the published `/config/nova/ckeditor-field.php`, set the `auto_migration` to `false`. +```php + 'migrations' => [ + 'auto_migrate' => false, + ], +``` +and then publish the migration to your project. +```php php artisan vendor:publish --tag=nova-ckeditor4-field-migrations -php artisan migrate ``` -Within the published `/config/nova/ckeditor-field.php`, if you wish to not use the default `Attachment` and/or `PendingAttachment` models. You could replace with your own: +if you wish to not use the default `Attachment` and/or `PendingAttachment` models. You could replace with your own within the published `/config/nova/ckeditor-field.php`, ```php 'attachment_model' => \Waynestate\Nova\CKEditor4Field\Models\Attachment::class, 'pending_attachment_model' => \Waynestate\Nova\CKEditor4Field\Models\PendingAttachment::class, diff --git a/config/ckeditor-field.php b/config/ckeditor-field.php index f42d3ef..149b3d9 100644 --- a/config/ckeditor-field.php +++ b/config/ckeditor-field.php @@ -41,6 +41,19 @@ 'attachment_model' => \Waynestate\Nova\CKEditor4Field\Models\Attachment::class, 'pending_attachment_model' => \Waynestate\Nova\CKEditor4Field\Models\PendingAttachment::class, + /* + |-------------------------------------------------------------------------------- + | Migrations + |-------------------------------------------------------------------------------- + | + | By default, the migrations will be automatically run when using `php artisan migrate` + | If you would like to disable this, set the value to false. + | + */ + 'migrations' => [ + 'auto_migrate' => true, + ], + /* |-------------------------------------------------------------------------------- | CKEditor 4 Javascript URL diff --git a/database/migrations/create_ckeditor_attachment_tables.php b/database/migrations/2022_07_25_000000_create_ckeditor_attachment_tables.php similarity index 100% rename from database/migrations/create_ckeditor_attachment_tables.php rename to database/migrations/2022_07_25_000000_create_ckeditor_attachment_tables.php diff --git a/src/CKEditor4FieldServiceProvider.php b/src/CKEditor4FieldServiceProvider.php index 8f90ad3..2383b81 100644 --- a/src/CKEditor4FieldServiceProvider.php +++ b/src/CKEditor4FieldServiceProvider.php @@ -32,9 +32,13 @@ public function boot() __DIR__ . '/../config/ckeditor-field.php' => config_path('nova/ckeditor-field.php'), ], 'nova-ckeditor4-field-config'); - $this->publishes([ - __DIR__.'/../database/migrations/create_ckeditor_attachment_tables.php' => database_path('migrations/'.Carbon::now()->format('Y_m_d_His').'_create_ckeditor_attachment_tables.php'), - ], 'nova-ckeditor4-field-migrations'); + if(config('nova.ckeditor-field.migrations.auto_migrate', true)) { + $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + }else{ + $this->publishes([ + __DIR__ . '/../database/migrations' => database_path('migrations'), + ], 'nova-ckeditor4-field-migrations'); + } } /** From bb231da1d2792580c8534a23bb45e1dc869c63dc Mon Sep 17 00:00:00 2001 From: Chris Pelzer Date: Thu, 3 Nov 2022 10:54:55 -0400 Subject: [PATCH 2/3] add an `enable_migrations` along with the `auto_migrate` option to handle backwards compatibility or if migrations are not necessary for the project. --- README.md | 9 ++++++++ config/ckeditor-field.php | 30 ++++++++++++++++----------- src/CKEditor4FieldServiceProvider.php | 29 +++++++++++++++++++------- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 664f4aa..92e1986 100644 --- a/README.md +++ b/README.md @@ -115,10 +115,19 @@ php artisan migrate # Run the migrations The package migrations will automatically run when running `php artisan migrate`. +If you are not going to use the Files and have no need for the migrations, you can disable migrations in `config/nova/ckeditor-field.php`, set the `enable_migrations` to `false`. +```php + 'migrations' => [ + 'enable_migrations' => false, + // ... + ], +``` + If you wish do not wish to use the [Laravel Migration](https://laravel.com/docs/9.x/packages#migrations), but publish the migration yourself to your project. Within the published `/config/nova/ckeditor-field.php`, set the `auto_migration` to `false`. ```php 'migrations' => [ + 'enable_migrations' => true, 'auto_migrate' => false, ], ``` diff --git a/config/ckeditor-field.php b/config/ckeditor-field.php index 149b3d9..41043d1 100644 --- a/config/ckeditor-field.php +++ b/config/ckeditor-field.php @@ -26,6 +26,24 @@ ], ], + /* + |-------------------------------------------------------------------------------- + | Migrations + |-------------------------------------------------------------------------------- + | + | This package comes with migrations to create the tables needed to store the attachments. + | If you have no need for migrations, you can disable them by setting `enable_migrations` to false + | If you want to disable the auto migration, set this option to false. + | + | If you disable the auto migration, you can publish the migrations and run them manually as followed: + | php artisan vendor:publish --tag=nova-ckeditor4-field-migrations + | + */ + 'migrations' => [ + 'enable_migrations' => true, + 'auto_migrate' => true, + ], + /* |-------------------------------------------------------------------------------- | CKEditor Attachment Models @@ -41,18 +59,6 @@ 'attachment_model' => \Waynestate\Nova\CKEditor4Field\Models\Attachment::class, 'pending_attachment_model' => \Waynestate\Nova\CKEditor4Field\Models\PendingAttachment::class, - /* - |-------------------------------------------------------------------------------- - | Migrations - |-------------------------------------------------------------------------------- - | - | By default, the migrations will be automatically run when using `php artisan migrate` - | If you would like to disable this, set the value to false. - | - */ - 'migrations' => [ - 'auto_migrate' => true, - ], /* |-------------------------------------------------------------------------------- diff --git a/src/CKEditor4FieldServiceProvider.php b/src/CKEditor4FieldServiceProvider.php index 2383b81..2d67206 100644 --- a/src/CKEditor4FieldServiceProvider.php +++ b/src/CKEditor4FieldServiceProvider.php @@ -32,13 +32,7 @@ public function boot() __DIR__ . '/../config/ckeditor-field.php' => config_path('nova/ckeditor-field.php'), ], 'nova-ckeditor4-field-config'); - if(config('nova.ckeditor-field.migrations.auto_migrate', true)) { - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); - }else{ - $this->publishes([ - __DIR__ . '/../database/migrations' => database_path('migrations'), - ], 'nova-ckeditor4-field-migrations'); - } + $this->handleMigrations(); } /** @@ -66,4 +60,25 @@ public function register() { // } + + /** + * Handle the migration strategy. + * + * @return void + */ + protected function handleMigrations() + { + $migrations = config('nova.ckeditor-field.migrations', []); + if (empty($migrations['enable_migrations'])) { + return; + } + + if (!empty($migrations['auto_migrate'])) { + $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + } else { + $this->publishes([ + __DIR__ . '/../database/migrations' => database_path('migrations'), + ], 'nova-ckeditor4-field-migrations'); + } + } } From 4591a7731b593ca9361b069de6878542734751b1 Mon Sep 17 00:00:00 2001 From: Chris Pelzer Date: Thu, 3 Nov 2022 11:21:35 -0400 Subject: [PATCH 3/3] update the CHANGELOG.md and add a new UPGRADING.md for information on upgrading between versions --- CHANGELOG.md | 10 ++++++++++ UPGRADING.md | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 UPGRADING.md diff --git a/CHANGELOG.md b/CHANGELOG.md index e7dddae..60301af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Changed +* Renamed the migration to include a timestamp to ensure only one migration is created. +* Updated README.md + +### Added +* Added new `enable_migrations` option to the config file to allow for the disabling of the migrations. +* Added new `auto_migrate` option to the config file to allow for the disabling of the automatic running of the migrations. +* Added new UPGRADE.md for upgrade instructions. + ## [1.1.4] - 2022-11-02 ### Fixed * Add check for migrations to make sure the table doesn't exist before trying to create it. by @chrispelzer in https://github.com/waynestate/nova-ckeditor4-field/pull/68 https://github.com/waynestate/nova-ckeditor4-field/issues/67 diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 0000000..a6e8dd3 --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,21 @@ +## From v1.1.4 to v1.2.0 + +Added support for Laravel loadMigrationsFrom to allow for migrations to be handled without needing to publish them. + +Previous versions the migration was being published with the timestamp of the time of publishing which caused multiple migrations to be published. + +This update renames the migration that is published to include the timestamp from the time it was initially committed to prevent multiple migrations from being published. + +You'll also want to make sure that your published `/config/nova/ckeditor-field.php` has the new `enable_migrations` and `auto_migrate` options. +```php + 'migrations' => [ + 'enable_migrations' => true, + 'auto_migrate' => true, + ], +``` + +It is possible that you could have multiple migrations if you have previously published the migrations. +If this is the case, you will need to manually delete the migrations that were published before this update and republish the migrations. +```php +php artisan vendor:publish --tag=nova-ckeditor4-field-migrations +```