Default schema approaches
Paul Brown · 30/01/2024 · 1 min read
-
Schemata table has
default
column already -
Ensure only ever one 'True' in the
default
column of the table -
Every time a mode Schema model is saved -- in any part of the application -- we need to ask:
- is this going to leave us with more than one default schema? Remove previous default schema if so
- is this going to leave us with fewer the one default schemata? Don't allow the switch if so.
Solution notes
- Create/register an observer
- Have the observer tap into the 'saving' (?) method of the
Schema
model to perform the logical checks/changes outlined above. - Look at database constraints for the same -- to handle the case of mass deletion/upates. Not required (but fun!) -- check constraint permission issue; can we accomplish via unique constraints/indexes?
Differences between observers and events in Laravel
Observers are basically predefined events that happen only on Eloquent Models (creating a record, updating a record, deleting, etc). Events are generic, aren’t predefined, and can be used anywhere, not just in models.
Discussions
Login to Post Comments