You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 16, 2021. It is now read-only.
But making generated columns non-nullable provides robust and flexible constraints.
Example
Goals
We have members table and plans table
members.role takes one of ownerguestsubscriber
members.plan_id has value only when members.role is subscriber
We also need to sort members in ownerguestsubscriber order.
Code
$table
->unsignedTinyInteger('sort_priority')
->storedAsNotNull(" CASE WHEN role = 'owner' AND plan_id IS NULL THEN 1 WHEN role = 'guest' AND plan_id IS NULL THEN 2 WHEN role = 'subscriber' AND plan_id IS NOT NULL THEN 3 ELSE NULL END")
->index();
members.sort_priority allows us making fast sorting ORDER BY sort_priority, id ensuring strong consistency.
Currently
->storedAs()and->virtualAs()always make them nullable.https://github.com/laravel/framework/blob/1cbb54e9da52d66bc09e181c34520df283bf46cd/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php#L892-L897
But making generated columns non-nullable provides robust and flexible constraints.
Example
Goals
memberstable andplanstablemembers.roletakes one ofownerguestsubscribermembers.plan_idhas value only whenmembers.roleissubscriberownerguestsubscriberorder.Code
members.sort_priorityallows us making fast sortingORDER BY sort_priority, idensuring strong consistency.