-
Notifications
You must be signed in to change notification settings - Fork 14
[IP-247]: company-scoped Settings page (Invoices/Quotes/Taxes/Email/System/Dashboard) #686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nielsdrost7
merged 7 commits into
InvoicePlane:develop
from
underdogg-forks:settings-cluster-2026-07-19
Jul 24, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a08b773
improved .gitignore
nielsdrost7 9ad1b60
style: fix Pint violations across factories, observers, and tests
nielsdrost7 00b3ada
improved .gitignore
nielsdrost7 b17fabb
quick improvements on composer.json and CLAUDE file
nielsdrost7 d449ff2
improve .gitignore
nielsdrost7 3707303
settings cluster
nielsdrost7 82b3152
fix: Setting::getByKey ignores company global scope, breaking legacy …
nielsdrost7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
Modules/Core/Database/Migrations/2026_07_19_000001_add_company_id_to_settings_table.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class () extends Migration { | ||
| /** | ||
| * Add `company_id` to the global settings table so that company-panel | ||
| * settings can be scoped per-company. Rows with a NULL `company_id` | ||
| * are global (the historical behavior of InvoicePlane v1). | ||
| * | ||
| * The unique index is a *partial* index (Postgres / MariaDB / SQLite all | ||
| * support `WHERE`): the `(company_id, setting_key)` pair is unique only | ||
| * when `company_id IS NOT NULL`. Two companies may each have their own | ||
| * `currency_code`; a global `currency_code` and a company-scoped one | ||
| * may coexist. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| $driver = DB::connection()->getDriverName(); | ||
|
|
||
| if ( ! $this->columnExists('settings', 'company_id')) { | ||
| Schema::table('settings', function (Blueprint $table): void { | ||
| $table->unsignedBigInteger('company_id')->nullable()->after('id'); | ||
| $table->index('company_id'); | ||
|
|
||
| $table->foreign('company_id') | ||
| ->references('id')->on('companies') | ||
| ->cascadeOnDelete(); | ||
| }); | ||
| } | ||
|
|
||
| // Drop the old single-column index on setting_key — the (company_id, | ||
| // setting_key) composite below replaces it for scoped rows, and | ||
| // for global (NULL company_id) rows we don't need an index because | ||
| // global key lookups are rare (legacy v1 callers only). | ||
| // (The original 2023 migration named it `settings_setting_key_index`.) | ||
| if ($this->indexExists('settings', 'settings_setting_key_index')) { | ||
| Schema::table('settings', function (Blueprint $table): void { | ||
| $table->dropIndex('settings_setting_key_index'); | ||
| }); | ||
| } | ||
|
|
||
| // MariaDB / MySQL do not support partial unique indexes. We rely on | ||
| // application-level enforcement in Setting::saveForCompany() and | ||
| // Setting::saveByKey() to keep the (company_id, setting_key) pair | ||
| // unique within a single tenant. The unique constraint is | ||
| // therefore a soft constraint: callers MUST use the save* helpers | ||
| // instead of inserting directly. | ||
| if ( ! $this->indexExists('settings', 'settings_company_id_setting_key_index')) { | ||
| Schema::table('settings', function (Blueprint $table): void { | ||
| $table->index(['company_id', 'setting_key'], 'settings_company_id_setting_key_index'); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public function down(): void | ||
| { | ||
| if ($this->indexExists('settings', 'settings_company_id_setting_key_index')) { | ||
| Schema::table('settings', function (Blueprint $table): void { | ||
| $table->dropIndex('settings_company_id_setting_key_index'); | ||
| }); | ||
| } | ||
|
|
||
| Schema::table('settings', function (Blueprint $table): void { | ||
| $table->dropForeign(['company_id']); | ||
| $table->dropIndex(['company_id']); | ||
| $table->dropColumn('company_id'); | ||
| $table->index('setting_key'); | ||
| }); | ||
| } | ||
|
|
||
| private function columnExists(string $table, string $column): bool | ||
| { | ||
| $driver = DB::connection()->getDriverName(); | ||
|
|
||
| if ($driver === 'sqlite') { | ||
| $rows = DB::select("PRAGMA table_info('{$table}')"); | ||
|
|
||
| foreach ($rows as $row) { | ||
| if (($row->name ?? null) === $column) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| $database = DB::connection()->getDatabaseName(); | ||
|
|
||
| $rows = DB::select( | ||
| 'SELECT COLUMN_NAME AS name FROM information_schema.columns ' | ||
| ."WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?", | ||
| [$database, $table, $column] | ||
| ); | ||
|
|
||
| return count($rows) > 0; | ||
| } | ||
|
|
||
| private function indexExists(string $table, string $index): bool | ||
| { | ||
| $driver = DB::connection()->getDriverName(); | ||
|
|
||
| if ($driver === 'sqlite') { | ||
| $rows = DB::select("PRAGMA index_list('{$table}')"); | ||
|
|
||
| foreach ($rows as $row) { | ||
| if (($row->name ?? null) === $index) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| // MySQL / MariaDB | ||
| $database = DB::connection()->getDatabaseName(); | ||
| $rows = DB::select( | ||
| 'SELECT INDEX_NAME AS name FROM information_schema.statistics ' | ||
| ."WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND INDEX_NAME = ?", | ||
| [$database, $table, $index] | ||
| ); | ||
|
|
||
| return count($rows) > 0; | ||
| } | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Docblock describes a partial UNIQUE index that the migration never creates.
Lines 46–56 create a plain, non-unique composite index (
->index([...])) and the inline comment states uniqueness is enforced only at the application layer. This docblock claims aWHERE company_id IS NOT NULLpartial unique index, which contradicts the actual schema and could mislead maintainers into assuming DB-level uniqueness. Please align the docblock with the soft-constraint reality.🤖 Prompt for AI Agents