Skip to content

chore: add created_at/updated_at to packages-db schemas for Tinybird sync#4178

Merged
joanagmaia merged 7 commits into
mainfrom
chore/update-packages-schemas-for-tinybird
Jun 9, 2026
Merged

chore: add created_at/updated_at to packages-db schemas for Tinybird sync#4178
joanagmaia merged 7 commits into
mainfrom
chore/update-packages-schemas-for-tinybird

Conversation

@joanagmaia

@joanagmaia joanagmaia commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a migration (V1780600000__add_created_updated_at.sql) to add created_at / updated_at audit columns to all packages-db tables that need them, enabling Tinybird watermark-based sync.
  • Updates all INSERT/UPSERT queries across packages_worker and data-access-layer to populate the new columns.
  • Excludes tables that already have equivalent timestamp columns (e.g. package_name_history, audit logs, state-machine tables).

Notes

  • repos already has created_at (stores the GitHub repo creation date). last_synced_at is nullable (not set until the GitHub enricher runs), so updated_at is added as the non-nullable Tinybird watermark; last_synced_at is kept as a separate enrichment-freshness signal.
  • packages, versions, repo_docker: last_synced_at is NOT NULL DEFAULT NOW() and already serves as updated_at — only created_at is added.
  • package_repos: verified_at is NOT NULL DEFAULT NOW() and already serves as updated_at — only created_at is added.
  • Partitioned tables (versions, package_dependencies, downloads_daily, downloads_last_30d): PostgreSQL 12+ propagates new columns to all child partitions automatically.

🤖 Generated with Claude Code


Note

Medium Risk
Wide schema migration on large partitioned tables plus many write paths; Maven maintainer email handling changed alongside timestamp columns.

Overview
Adds created_at / updated_at on packages-db tables (via V1780600000__add_created_updated_at.sql) so Tinybird can watermark incremental sync, with documented exceptions where existing timestamps already play that role (last_synced_at, verified_at, log/state tables).

Ingestion and DAL now set the new columns on insert/upsert across deps.dev merges (packages, versions, deps, advisories, package_repos), npm/Maven/OSV paths, downloads, funding links, maintainers, and repo enrichment (updated_at on GitHub bulk updates and skip marks).

Maven maintainer upserts are aligned with npm by writing email instead of email_hash in upsertMaintainer / runMavenEnrichmentLoop (no schema change in this migration).

Reviewed by Cursor Bugbot for commit b435ad6. Bugbot is set up for automated code reviews on this repo. Configure here.

…sync

Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
Copilot AI review requested due to automatic review settings June 8, 2026 16:11
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@joanagmaia joanagmaia requested review from epipav and themarolt June 8, 2026 16:13
@joanagmaia joanagmaia assigned mbani01 and unassigned mbani01 Jun 8, 2026
@joanagmaia joanagmaia requested review from mbani01 and ulemons June 8, 2026 16:13
Comment thread services/libs/data-access-layer/src/packages/downloadsLast30d.ts
Comment thread services/apps/packages_worker/src/deps-dev/activities/rankPackagesUniverse.ts Outdated

Copilot AI left a comment

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.

Pull request overview

This PR adds created_at / updated_at audit timestamps across the packages-db schema so Tinybird can use timestamp watermarks for incremental sync, and updates the main write paths (packages_worker + DAL) to populate/bump these columns.

Changes:

  • Add Flyway migration V1780600000__add_created_updated_at.sql to introduce created_at / updated_at (and updated_at only for repos).
  • Update DAL INSERT/UPSERT queries to write created_at / updated_at and bump updated_at on conflict updates.
  • Update packages_worker deps.dev ingestion and repo enrichment SQL to set/bump updated_at.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
services/libs/data-access-layer/src/packages/versions.ts Adds created_at/updated_at to npm versions upsert and bumps updated_at on conflict.
services/libs/data-access-layer/src/packages/repos.ts Adds created_at/updated_at to package_repos upsert and bumps updated_at on conflict.
services/libs/data-access-layer/src/packages/packages.ts Adds created_at/updated_at to npm package upsert and bumps updated_at on conflict.
services/libs/data-access-layer/src/packages/osv.ts Adds created_at/updated_at to OSV advisory-related inserts/upserts and bumps updated_at on conflict.
services/libs/data-access-layer/src/packages/maintainers.ts Adds created_at/updated_at to maintainers + package_maintainers writes and bumps updated_at on conflict.
services/libs/data-access-layer/src/packages/fundingLinks.ts Adds created_at/updated_at to funding link insert path.
services/libs/data-access-layer/src/packages/downloadsLast30d.ts Adds created_at/updated_at to last-30d downloads upsert and bumps updated_at on conflict.
services/libs/data-access-layer/src/packages/downloadsDaily.ts Adds created_at/updated_at to daily downloads insert path.
services/apps/packages_worker/src/enricher/updateEnrichedRepos.ts Bumps repos.updated_at when enrichment updates or when marking repos skipped.
services/apps/packages_worker/src/deps-dev/workflows/ingestVersions.ts Adds created_at/updated_at to deps.dev versions merge inserts.
services/apps/packages_worker/src/deps-dev/workflows/ingestRepos.ts Adds updated_at to deps.dev repos inserts; adds created_at/updated_at to package_repos inserts.
services/apps/packages_worker/src/deps-dev/workflows/ingestPackages.ts Adds created_at/updated_at to deps.dev packages merge inserts.
services/apps/packages_worker/src/deps-dev/workflows/ingestDependencies.ts Adds created_at/updated_at to deps.dev dependencies merge inserts.
services/apps/packages_worker/src/deps-dev/workflows/ingestAdvisories.ts Adds created_at/updated_at to deps.dev advisories/advisory_packages/affected_ranges inserts.
services/apps/packages_worker/src/deps-dev/activities/rankPackagesUniverse.ts Adds created_at/updated_at to packages_universe repopulation insert.
backend/src/osspckgs/migrations/V1780600000__add_created_updated_at.sql Adds audit timestamps to packages-db tables for Tinybird watermarking.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +25
ALTER TABLE packages_universe
ADD COLUMN IF NOT EXISTS created_at timestamptz NOT NULL DEFAULT NOW(),
ADD COLUMN IF NOT EXISTS updated_at timestamptz NOT NULL DEFAULT NOW();

ALTER TABLE packages
ADD COLUMN IF NOT EXISTS created_at timestamptz NOT NULL DEFAULT NOW(),
ADD COLUMN IF NOT EXISTS updated_at timestamptz NOT NULL DEFAULT NOW();
…ists

Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
Comment thread backend/src/osspckgs/migrations/V1780600000__add_created_updated_at.sql Outdated
…ding deprecation)

Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
Copilot AI review requested due to automatic review settings June 8, 2026 16:42

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Comment on lines +24 to +29
ALTER TABLE packages
ADD COLUMN IF NOT EXISTS created_at timestamptz NOT NULL DEFAULT NOW();

ALTER TABLE package_funding_links
ADD COLUMN IF NOT EXISTS created_at timestamptz NOT NULL DEFAULT NOW(),
ADD COLUMN IF NOT EXISTS updated_at timestamptz NOT NULL DEFAULT NOW();
Comment thread services/libs/data-access-layer/src/packages/osv.ts
mbani01
mbani01 previously approved these changes Jun 8, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 04da2d3. Configure here.

Comment thread services/libs/data-access-layer/src/packages/maintainers.ts
Copilot AI review requested due to automatic review settings June 9, 2026 09:30

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Comment thread backend/src/osspckgs/migrations/V1780600000__add_created_updated_at.sql Outdated
Comment on lines +24 to +26
ALTER TABLE packages
ADD COLUMN IF NOT EXISTS created_at timestamptz NOT NULL DEFAULT NOW();

Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
@joanagmaia joanagmaia force-pushed the chore/update-packages-schemas-for-tinybird branch from 80a7fd1 to 27f5aa2 Compare June 9, 2026 10:23
@joanagmaia joanagmaia requested a review from mbani01 June 9, 2026 10:32
Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
Copilot AI review requested due to automatic review settings June 9, 2026 10:51

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Comment on lines +26 to +30
ALTER TABLE repos
ADD COLUMN IF NOT EXISTS updated_at timestamptz NOT NULL DEFAULT NOW();

ALTER TABLE packages
ADD COLUMN IF NOT EXISTS created_at timestamptz NOT NULL DEFAULT NOW();
Comment on lines 25 to 29
ON CONFLICT (ecosystem, username) DO UPDATE SET
display_name = COALESCE(EXCLUDED.display_name, maintainers.display_name),
email = COALESCE(EXCLUDED.email, maintainers.email)
email = COALESCE(EXCLUDED.email, maintainers.email),
updated_at = EXCLUDED.updated_at
RETURNING display_name, email
Comment on lines 22 to +26
ON CONFLICT (ecosystem, username) DO UPDATE SET
display_name = COALESCE(EXCLUDED.display_name, maintainers.display_name),
url = COALESCE(EXCLUDED.url, maintainers.url),
email_hash = COALESCE(EXCLUDED.email_hash, maintainers.email_hash)
RETURNING id, display_name, url, email_hash
email = COALESCE(EXCLUDED.email, maintainers.email),
updated_at = NOW()
themarolt
themarolt previously approved these changes Jun 9, 2026
Signed-off-by: Joana Maia <jmaia@contractor.linuxfoundation.org>
@joanagmaia joanagmaia merged commit 661161e into main Jun 9, 2026
15 checks passed
@joanagmaia joanagmaia deleted the chore/update-packages-schemas-for-tinybird branch June 9, 2026 11:30
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.

4 participants