Skip to content

Timestamp Configs for FlatPostgresCollection#274

Open
suddendust wants to merge 23 commits intohypertrace:mainfrom
suddendust:pg_writes_timestampConfig
Open

Timestamp Configs for FlatPostgresCollection#274
suddendust wants to merge 23 commits intohypertrace:mainfrom
suddendust:pg_writes_timestampConfig

Conversation

@suddendust
Copy link
Contributor

@suddendust suddendust commented Feb 9, 2026

Config-Driven Timestamp Fields for Flat Collections

Summary

Adds auto-managed createdTime and lastUpdateTime fields for flat PostgreSQL collections, configurable via PostgresClient custom parameters.

Changes

  • Config-driven timestamps: Timestamp column names specified via JSON config:
postgres {
  collectionConfigs {
    myTestFlat {
      timestampFields {
        created = "createdTime"
        lastUpdated = "lastUpdateTime"
      }
    }
  }
}
  • Type-aware conversion: Looks up column type from schema and converts appropriately (BIGINT → epoch millis, TIMESTAMPTZjava.sql.Timestamp, etc.)
  • Upsert behavior: createdTime preserved on updates, lastUpdateTime always updated
  • Graceful degradation: Logs warning if config missing; no exception, columns remain NULL

Testing

  • testTimestampsOnCreate - Validates both fields populated on create
  • testTimestampsOnUpsert - Validates createdTime preserved, lastUpdateTime updated
  • testNoExceptionWhenTimestampConfigMissing - Validates graceful handling when config absent.

For upserts, here's an example query that is created:

INSERT INTO "entities_api_shadow" ("attributes.apiType", "attributes.pattern", "key", "entityName", "tenantId", "attributes.isAuthenticated", "attributes.serviceId", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT ("key") DO UPDATE SET "attributes.apiType" = EXCLUDED."attributes.apiType", "attributes.pattern" = EXCLUDED."attributes.pattern", "entityName" = EXCLUDED."entityName", "tenantId" = EXCLUDED."tenantId", "attributes.isAuthenticated" = EXCLUDED."attributes.isAuthenticated", "attributes.serviceId" = EXCLUDED."attributes.serviceId", "updated_at" = EXCLUDED."updated_at" RETURNING (xmax = 0) AS is_insert

Callout

Note that there is no way to define a global timestamp config and override it at a per-collection level. The reason I have excluded this in this PR is because a proper config override framework requires a bit more thought - For example, how we merge global properties with local overrides. That would increase the scope of this PR and I feel it's better taken care of in a separate PR.

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 82.82828% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.94%. Comparing base (cfc9c08) to head (2ca08dd).

Files with missing lines Patch % Lines
...documentstore/postgres/FlatPostgresCollection.java 84.31% 3 Missing and 5 partials ⚠️
...config/TypesafeConfigDatastoreConfigExtractor.java 86.20% 3 Missing and 1 partial ⚠️
...tstore/model/config/postgres/CollectionConfig.java 50.00% 2 Missing ⚠️
...odel/config/postgres/PostgresConnectionConfig.java 50.00% 0 Missing and 2 partials ⚠️
...e/model/config/postgres/TimestampFieldsConfig.java 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #274      +/-   ##
============================================
- Coverage     81.01%   80.94%   -0.08%     
- Complexity     1446     1467      +21     
============================================
  Files           241      243       +2     
  Lines          6979     7074      +95     
  Branches        648      662      +14     
============================================
+ Hits           5654     5726      +72     
- Misses          907      923      +16     
- Partials        418      425       +7     
Flag Coverage Δ
integration 80.94% <82.82%> (-0.08%) ⬇️
unit 54.94% <60.60%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@puneet-traceable
Copy link

This will be doable at what level? Per table ?

@suddendust
Copy link
Contributor Author

This will be doable at what level? Per table ?

@puneet-traceable Added this at collection level.

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.

2 participants