Repository navigation
Require a created_at when creating a record with a created_at column - #557
Open
erikrozendaal wants to merge 2 commits into
Open
erikrozendaal wants to merge 2 commits into
erikrozendaal wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Empty created_at strings bypass validation in bulk creation and replay, allowing NULL or replay-dependent timestamps instead of consistently rejecting missing values.
1 open issue
What changed in this PR
This PR makes projection creation more deterministic by requiring created_at for records whose tables have that column, rather than filling it with the current time.
Changes:
- Adds shared validation and updates both persistors to enforce it, including timestamps supplied by creation blocks.
- Updates timestamp expectations and existing test fixtures.
- Documents the breaking change and updates projector examples.
| File | Description |
|---|---|
spec/lib/sequent/core/persistors/replay_optimized_postgres_persistor_spec.rb |
Supplies explicit timestamps in replay test fixtures. |
spec/lib/sequent/core/persistors/persistor_values_spec.rb |
Tests missing timestamps and block-provided timestamps. |
spec/lib/sequent/core/persistors/persistor_defaults_spec.rb |
Supplies timestamps while testing other column defaults. |
spec/lib/sequent/core/persistors/active_record_persistor_spec.rb |
Adds a timestamp to the batch-update fixture. |
lib/sequent/core/persistors/replay_optimized_postgres_persistor.rb |
Validates creation timestamps and removes the current-time argument default. |
lib/sequent/core/persistors/persistor.rb |
Defines the shared timestamp validator and error. |
lib/sequent/core/persistors/active_record_persistor.rb |
Validates single and bulk creation and handles block-set timestamps. |
docs/docs/concepts/projector.md |
Explains the requirement and updates creation examples. |
CHANGELOG.md |
Documents the breaking timestamp behavior. |
Review effort: Balanced
erikrozendaal
marked this pull request as ready for review
November 4, 2026 11:07
Without a created_at, the persistors used the current time for created_at and updated_at, so a record got other timestamps every time its events were replayed. Creating such a record without a created_at, after the values and the block are applied, now fails with a MissingCreatedAtError, in the ActiveRecordPersistor and the ReplayOptimizedPostgresPersistor alike. A created_at set by the block is also used as updated_at, like one given in the values. create_or_update_record no longer defaults its created_at to the current time.
create_records and the ReplayOptimizedPostgresPersistor checked the given value, so created_at: '' passed and stored NULL or the database default. The check now uses the value cast to the type of the column, like the ActiveRecordPersistor's create_record effectively did.
erikrozendaal
force-pushed
the
improvement/require-created-at
branch
from
November 4, 2026 18:57
1a60d97 to
ccd1592
Compare
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

A projection should be the same however often its events are replayed. Records created without a
created_atbroke this: the persistors filled in the current time forcreated_atandupdated_at, so every replay gave such records other timestamps, and code that reads these timestamps as the time something happened got other answers after a replay.Creating a record whose table has a
created_atcolumn now requires acreated_at, usually thecreated_atof the event, which is also used asupdated_atunless that is given. Without one, all persistors fail instead of using the current time. This is a breaking change for projectors that relied on the current time, described in the changelog, and goes together with #556, which keepsupdated_atstable for records updated using a block.