Skip to content

feat(schema): createdAt/updatedAt on every domain entity (P4-K)#84

Merged
CryptoJones merged 1 commit into
masterfrom
feat/timestamps
May 18, 2026
Merged

feat(schema): createdAt/updatedAt on every domain entity (P4-K)#84
CryptoJones merged 1 commit into
masterfrom
feat/timestamps

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Part of architect audit issue #73 — iteration P4-K.

Summary

  • Migration adds createdAt/updatedAt TIMESTAMPTZ columns to 18 tables.
  • All 18 models flip timestamps: falsetrue so Sequelize maintains the columns automatically.
  • IdempotencyKey is excluded (it already has its own ikCreatedAt/ikExpiresAt).
  • Existing rows backfilled to now() via column default; operators carrying legacy Atbash SQL Server timestamps can patch real values post-migration.

Test plan

  • tests/unit/timestamps.test.js (36 cases): every model has timestamps:true + createdAt/updatedAt attrs.
  • Full suite: 401 pass / 4 skip (was 365/4).

This code proudly made in Nebraska. GO BIG RED! 🌽 https://xkcd.com/2347/

Architect audit P4-K. Add `createdAt`/`updatedAt` TIMESTAMPTZ columns
to 18 tables and flip every model from `timestamps: false` to
`timestamps: true` so Sequelize auto-populates them on every write.

Why
- Auditability: every row carries creation + last-modification time
  without each controller maintaining it by hand.
- Sync clients: third-party integrations get a reliable "what's
  changed since T" boundary for delta-pull workflows.
- Observability: ad-hoc analytics on "new customers per day", etc.,
  trivially work off `createdAt` rather than a row counter.

Coverage
- 18 tables touched: ApiKey, ApiMaster, BillingType, Company,
  Customer, CustomerPayment, InventoryItem, InventoryTransactions,
  Invoice, InvoiceJob, Job, ProductEntry, PurchaseOrderHeaders,
  PurchaseOrderLines, PurchaseOrderVendors, TimeEntry, VersionInfo,
  Worker.
- IdempotencyKey is INTENTIONALLY excluded — it already manages its
  own `ikCreatedAt` / `ikExpiresAt` pair and a parallel
  createdAt/updatedAt would be redundant and confusing.

Backfill
- Existing rows have no recorded history; the migration backfills
  both columns to `now()` via the column DEFAULT. Operators carrying
  legacy Atbash SQL Server timestamps can patch real values
  post-migration via a one-off UPDATE.

Down migration
- Drops the two columns from every table. No FKs reference them,
  so the rollback is straight-forward.

Tests
- New `tests/unit/timestamps.test.js` (36 cases) — every model
  asserts `options.timestamps === true` AND
  `rawAttributes.{createdAt,updatedAt}` exist.
- Full suite: 401 pass / 4 skip (was 365/4).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit b097a67 into master May 18, 2026
3 checks passed
@CryptoJones CryptoJones deleted the feat/timestamps branch May 18, 2026 05:01
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.

1 participant