Repository navigation
feat: implement timezone-aware timestamps for projections - #32
Conversation
WalkthroughThe changes introduce timezone-aware timestamps for Ecto projections by converting the ProjectionVersion schema from naive datetime microseconds to UTC datetime microseconds. Two new migration helper modules are provided for greenfield and upgrade scenarios, and existing migrations are refactored to delegate to these helpers. Changes
Sequence DiagramsequenceDiagram
participant Old as Migration (Old)
participant New as Migration Helper (V01/V02)
participant DB as Database
rect rgb(240, 248, 255)
Note over Old,New: Greenfield Setup
Old->>New: up() delegation
New->>DB: CREATE projection_versions with timestamptz
end
rect rgb(255, 250, 240)
Note over Old,New: Existing Installation Upgrade
Old->>New: V02.up() delegation
New->>DB: ALTER TABLE projection_versions<br/>MODIFY timestamps to timestamptz
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
d35719d to
53cf945
Compare
53cf945 to
6ecc8ef
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
guides/explanations/fork-differences.md (1)
104-148: Docs for timezone-aware timestamps are accurate; consider mentioning:prefixThe new section correctly describes the switch to
timestamptz, the:utc_datetime_usecschema change, and the V01/V02 helper usage. To make multi-schema setups more discoverable, consider adding a short note that both helpers accept a:prefixoption (e.g.V01CreateProjectionVersionsTable.up(prefix: "projections")), mirroring the code inCommanded.Projections.Ecto.Migrations.V01CreateProjectionVersionsTable.lib/commanded/projections/ecto/migrations/v02_upgrade_timestamps_to_timezone.ex (1)
38-45: Verify database timezone configuration before running this migration.When PostgreSQL converts
timestamptotimestamptz, it interprets existing timestamp values in the database's timezone setting. Ensure your database timezone is set to UTC (or matches the timezone used when storing the original timestamps) to avoid unexpected timestamp shifts.You can verify your database timezone with:
#!/bin/bash # Check PostgreSQL timezone configuration # Replace with your actual database connection details psql -U postgres -d your_database -c "SHOW timezone;"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
guides/explanations/fork-differences.md(1 hunks)lib/commanded/projections/ecto.ex(1 hunks)lib/commanded/projections/ecto/migrations/v01_create_projection_versions_table.ex(1 hunks)lib/commanded/projections/ecto/migrations/v02_upgrade_timestamps_to_timezone.ex(1 hunks)priv/repo/migrations/20170609113553_create_projection_versions.exs(1 hunks)priv/repo/migrations/20170929080308_create_projection_version_with_prefix.exs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
priv/repo/migrations/20170929080308_create_projection_version_with_prefix.exs (2)
lib/commanded/projections/ecto/migrations/v01_create_projection_versions_table.ex (2)
up(38-47)down(49-52)lib/commanded/projections/ecto/migrations/v02_upgrade_timestamps_to_timezone.ex (2)
up(38-45)down(47-54)
lib/commanded/projections/ecto/migrations/v01_create_projection_versions_table.ex (1)
lib/commanded/projections/ecto/migrations/v02_upgrade_timestamps_to_timezone.ex (2)
up(38-45)down(47-54)
lib/commanded/projections/ecto/migrations/v02_upgrade_timestamps_to_timezone.ex (1)
lib/commanded/projections/ecto/migrations/v01_create_projection_versions_table.ex (2)
up(38-47)down(49-52)
priv/repo/migrations/20170609113553_create_projection_versions.exs (1)
lib/commanded/projections/ecto/migrations/v01_create_projection_versions_table.ex (2)
up(38-47)down(49-52)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Quality Assurance (1.18.x, 27)
- GitHub Check: Cursor Bugbot
🔇 Additional comments (5)
lib/commanded/projections/ecto.ex (1)
574-578: ProjectionVersion timestamps now correctly use UTC-aware typeChanging
ProjectionVersiontotimestamps(type: :utc_datetime_usec)matches the newtimestamptzcolumns from V01/V02 and is the right choice for timezone-aware projections. Just make sure consumers run the upgrade migration before deploying this schema change to avoid type mismatches on existing databases.priv/repo/migrations/20170929080308_create_projection_version_with_prefix.exs (1)
2-13: Delegating prefixed migration to V01 keeps behavior and centralizes DDLSwitching this migration to call
V01CreateProjectionVersionsTable.up/down(prefix: "test")preserves the existing prefix behavior while reusing the shared projection_versions DDL. This keeps the schema definition in one place and reduces drift risk between migrations.lib/commanded/projections/ecto/migrations/v01_create_projection_versions_table.ex (1)
1-54: Well-factored, prefix-aware V01 migration moduleThe guarded V01 migration cleanly encapsulates
projection_versionsDDL with optional:prefixand timezone-awaretimestamptztimestamps. Centralizing this logic for reuse (and documenting usage in the moduledoc) should make future projection schema evolution and multi-schema setups much easier to manage.priv/repo/migrations/20170609113553_create_projection_versions.exs (1)
2-12: Migration now correctly delegates to versioned V01 up/downHaving this migration call
V01CreateProjectionVersionsTable.up/0and.down/0centralizes the table definition and ensures it stays consistent with the versioned migration module. The switch from an inlinechange/0to explicit up/down is appropriate given the versioned helpers.lib/commanded/projections/ecto/migrations/v02_upgrade_timestamps_to_timezone.ex (1)
1-56: LGTM! Well-structured migration with comprehensive documentation.The migration correctly upgrades timestamp columns to timezone-aware types using Ecto's
alter/modifypattern. The implementation is consistent with V01's structure, properly reversible, and includes clear usage examples with prefix support.
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
6ecc8ef to
821f65f
Compare
Note
Make projection timestamps timezone-aware and add migration helpers, updating schema, migrations, tests, and docs.
ProjectionVersionschema to usetimestamps(type: :utc_datetime_usec).Commanded.Projections.Ecto.Migrations.V01CreateProjectionVersionsTableandV02UpgradeTimestampsToTimezone(createsprojection_versionswith:timestamptz; upgrades existinginserted_at/updated_at).:prefix), switch to explicitup/0anddown/0.test/test_helper.exs.guides/explanations/fork-differences.mddetailing the change with usage examples.Written by Cursor Bugbot for commit 821f65f. This will update automatically on new commits. Configure here.