diff --git a/CHANGELOG.md b/CHANGELOG.md index 863c8a1..91e7b53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- When install refuses over a same-named table, its message now names the fix that needs no + config file, `LARANAIL_SETTINGS_TABLE_PREFIX`, and the publish command for renaming single + tables; it used to point at config keys in a file that had not been published yet. The + installation guide says the same, warns that a partly published config replaces the whole + `tables` array, and lists `sync-definitions` after `migrate`. + ## [0.1.0] - 2026-11-16 The first public release. `Added` describes the package; `Changed`, `Removed`, `Fixed` and diff --git a/docs/installation.md b/docs/installation.md index 1505be5..f9a610a 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -38,6 +38,7 @@ The service provider registers itself through package discovery. ```bash php artisan laranail::settings.install php artisan migrate +php artisan laranail::settings.sync-definitions ``` Install publishes `config/laranail/settings.php` (tag `laranail::settings-config`) and the @@ -50,6 +51,10 @@ package's one migration (tag `laranail::settings-migrations`, reads the database first, so run the migrations before the first read; until then a read raises `DriverUnavailable`. +`sync-definitions` copies the definitions declared in code and config into the definitions +table. Install runs it too, but on a fresh application the table does not exist yet, so install +says "Definitions were not synced" and the step above does it once the migration has run. + ## Default categories ```bash @@ -64,8 +69,17 @@ notifications, security) as system categories and changes nothing when run again ## When install refuses Install refuses to publish anything when a table of the same name already exists and is not -this package's (a `settings` table of your own, say). Rename the package's tables with -`tables.prefix`, `stores.settings.table`, `tables.categories` or `tables.audit` and run it again. +this package's (a `settings` table of your own, say). Nothing is published yet, so the quickest +fix needs no config file: prefix every package table from `.env` and install again. + +```bash +LARANAIL_SETTINGS_TABLE_PREFIX=laranail_ +``` + +To rename single tables instead (`stores.settings.table`, `tables.categories`, `tables.audit`), +publish the config first with `php artisan vendor:publish --tag=laranail::settings-config`, edit +it, and install again. Keep the published file whole: the package's defaults are merged one +level deep, so a file holding only part of `tables` replaces the whole `tables` array. ## Without a database diff --git a/src/Providers/SettingsServiceProvider.php b/src/Providers/SettingsServiceProvider.php index 0f4846f..a663561 100644 --- a/src/Providers/SettingsServiceProvider.php +++ b/src/Providers/SettingsServiceProvider.php @@ -225,7 +225,7 @@ private static function refuseForeignTables(InstallCommand $command): void if ($foreign !== []) { throw new InvalidConfiguration(sprintf( - 'These tables already exist and are not laranail/settings tables: %s. Set laranail.settings.tables.prefix (or stores..table, tables.categories, tables.audit) and install again.', + 'These tables already exist and are not laranail/settings tables: %s. Nothing was published. Set LARANAIL_SETTINGS_TABLE_PREFIX (for example laranail_) in .env and install again; to rename single tables instead, publish the config with `php artisan vendor:publish --tag=laranail::settings-config`, set stores..table, tables.categories or tables.audit, and install again.', implode(', ', $foreign), )); } diff --git a/tests/Feature/Database/CommandsTest.php b/tests/Feature/Database/CommandsTest.php index 057e0ae..364eb78 100644 --- a/tests/Feature/Database/CommandsTest.php +++ b/tests/Feature/Database/CommandsTest.php @@ -55,6 +55,14 @@ function settingsMigrations(): array expect(fn () => $this->artisan('laranail::settings.install')->run())->toThrow(InvalidConfiguration::class, DB::getDefaultConnection() . '.settings') ->and(settingsMigrations())->toBe([]); + // Nothing is published yet, so the message names the fix that needs no config file. + try { + $this->artisan('laranail::settings.install')->run(); + } catch (InvalidConfiguration $refusal) { + expect($refusal->getMessage())->toContain('LARANAIL_SETTINGS_TABLE_PREFIX') + ->toContain('--tag=laranail::settings-config'); + } + // The package's own tables are not foreign: installing again over them is fine. Schema::drop('settings'); useDatabase();