Skip to content

Replace the migration stubs with one migration; add seeds, models and tenancy - #7

Merged
imanimanyara merged 3 commits into
mainfrom
refactor/single-migration-seeds-tenancy
Nov 10, 2026
Merged

imanimanyara merged 3 commits into
mainfrom
refactor/single-migration-seeds-tenancy

Conversation

@imanimanyara

Copy link
Copy Markdown
Member

Summary

  • One migration instead of four stubs. database/migrations/create_laranail_settings_tables.php creates categories, the optional definitions table, every recorded database store's values table and the audit table, in that order, and down() drops them in reverse. A store on its own connection gets that connection's categories and audit tables. Every schema switch still comes from the recorded schema file. Table definitions stay inline in the migration: no builder class. install publishes it as before, and migrations published from the old stubs keep working.
  • make-store writes one file per store: a copy of the migration with $only (and, with --connection, $pinnedConnection) rewritten. It keeps the existing refusal of a store that already has a migration, the input validation, shape recording and the printed config entry.
  • Default seeds. DefaultCategoriesSeeder (in database/seeders) is registered with the host's db:seed through package-tools, with foreign-key checks kept on. It creates general, appearance, localisation, mail, notifications and security as system categories, writing through the settings API as the system actor so the changes are audited. It is idempotent and configurable with seed.enabled, seed.stores and seed.categories.
  • Models and factories. Setting, SettingCategory, SettingDefinition and SettingAuditEntry follow the recorded shape and tenancy. Their factories need no Faker. The engine stays on the query builder.
  • Tenancy. tenancy.mode takes none, column or database. TenantDiscriminator has a null default and closure adapters for stancl/tenancy and spatie/laravel-multitenancy, both detected with class_exists and listed under suggest only. Column mode adds a tenant column that leads the unique keys, and values, categories, the audit trail and the models are filtered on it. Preloaded records are kept per tenant in every mode. The switch matrix now covers 177 pairs with 10 shapes; the full product is 1,152.
  • A separate commit fixes a flaky step-up verification test (a clock read twice across a second boundary under coverage).

Testing

  • vendor/bin/pest: 447 passed. Coverage 96.9% (floor 90). PHPStan at max level: no errors. Rector and Pint are clean, and composer validate --strict passes.
  • Each new guard was proven red: unscoped values, unscoped categories, a preload not keyed by tenant, a non-idempotent seeder, foreign-key checks off, a down() that leaves the audit table, an identity index without the tenant.
  • MySQL 8.4 and PostgreSQL 17 run in CI (database group).

Follow-up (existing, not introduced here)

With definitions.table on, a store on a non-default connection reads definitions from its own connection, where that table does not exist.

The boundary cases build "exactly 300 seconds ago" from one clock reading and the verifier
reads the clock again; on a slow run (coverage under Xdebug) a second passes between the two
and the 300-second case lands on 301.
…nancy

One migration, database/migrations/create_laranail_settings_tables.php, replaces the four
stubs. It creates categories, the optional definitions table, every recorded database store's
values table (a store on its own connection gets that connection's categories and audit) and
the audit table, in that order, and drops them in reverse. Table definitions stay inline in the
migration. make-store writes one copy of it pinned to the new store and connection.

DefaultCategoriesSeeder creates the seed.categories set as system categories through the
settings API, registered with the host's db:seed with foreign keys still checked; idempotent
by slug and off with seed.enabled.

Eloquent models (Setting, SettingCategory, SettingDefinition, SettingAuditEntry) and
factories follow the recorded shape for tests, seeding and admin screens; the engine stays on
the query builder.

Tenancy: tenancy.mode none, column or database, and a TenantDiscriminator with stancl/tenancy
and spatie/laravel-multitenancy adapters detected with class_exists. Column mode adds a tenant
column leading the unique keys and filters values, categories, the audit trail and the models
on it. Preloaded records are kept per tenant in every mode. The schema-switch matrix gains
the tenancy factor: 10 shapes for 177 pairs, 1,152 in the full product.
Copilot AI balanced review requested due to automatic review settings November 10, 2026 00:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@imanimanyara
imanimanyara merged commit 342b87e into main Nov 10, 2026
15 checks passed
@imanimanyara
imanimanyara deleted the refactor/single-migration-seeds-tenancy branch November 11, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants