Skip to content

Create schemas and models for implementing generic policies#1177

Open
tarrow wants to merge 11 commits into
mainfrom
create-generic-policy-schemas
Open

Create schemas and models for implementing generic policies#1177
tarrow wants to merge 11 commits into
mainfrom
create-generic-policy-schemas

Conversation

@tarrow

@tarrow tarrow commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Models, Migrations and simple Tests for Policy and PolicyAcceptance.

Using built in created_at and updated_at timestamps for consistency with our other models,

Does not include Factories or Seeders. Possibility for a follow up.

Bug: T428175

@tarrow

tarrow commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@outdooracorn on your return can you take a look at b40bc27 and see if you agree with this change? I assume you very explicitly decided to try and make the built in timestamps (created_at and updated_at) non-nullable but I didn't understand why.

I did quite some research and from what I could read upstream making the built in timestamps nullable was a very explicit nearly decade old decision to handle mysql/maria.

@tarrow tarrow force-pushed the create-generic-policy-schemas branch 2 times, most recently from d820df4 to 45b9423 Compare June 24, 2026 13:17
@tarrow tarrow marked this pull request as ready for review June 24, 2026 20:31
outdooracorn and others added 8 commits June 24, 2026 21:32
We are using the built in Eqloquent timestamp method to introduce nullable timestamp
columns.

The framework seems to have discussed these issues at length[1] and determined that
this is the best setup to prevent issues with ON UPDATE CURRENT_TIMESTAMP behaviour.

[1] laravel/framework#12490
For nice to have's like Factory and Seeder we should do in a
follow-up.

Still need to come to a decision on casting the timestamps;
particularly the built in.
Run php artisan ide-helper:models --reset "App\PolicyAcceptance" "App\Policy"
@tarrow tarrow force-pushed the create-generic-policy-schemas branch from 4d83fdd to 4f36d78 Compare June 24, 2026 20:32
@tarrow tarrow requested review from AndrewKostka and dati18 June 24, 2026 20:40
Comment thread tests/PolicyAcceptanceTest.php Outdated
Comment thread tests/PolicyTest.php Outdated
Comment thread tests/PolicyTest.php Outdated
Comment thread app/Policy.php
Comment thread app/PolicyAcceptance.php Outdated
Comment thread app/PolicyAcceptance.php
Comment thread app/PolicyAcceptance.php Outdated
Comment thread tests/PolicyAcceptanceTest.php
@tarrow tarrow force-pushed the create-generic-policy-schemas branch from de0d29d to b96b645 Compare June 25, 2026 07:31
Comment thread app/Policy.php
'accepted_at' => CarbonImmutable::createFromDate(2026, 1, 1),
]
);
$this->assertNull($policyAcceptance->accepted_at);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

put the instance assertion here too is not a bad idea $this->assertInstanceOf(CarbonImmutable::class, $policyAcceptance->accepted_at);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that's not possible: null isn't an instance of CarbonImmutable

Comment thread tests/PolicyAcceptanceTest.php Outdated
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.

3 participants