Skip to content

Conversation

@mrkaye97
Copy link
Contributor

@mrkaye97 mrkaye97 commented Aug 29, 2025

Description

Adding a migration to partition the core lookup table, similar to the one for the OLAP one. Basic steps are:

  1. Create the new partitioned table and its partitions + a trigger to insert into it
  2. Backfill the old data
  3. Cut over

It's a bit different than with Timescale since we need to create the partitions manually. I was thinking it'd make sense to just have one big partition for all the old data, which will all get dropped in one shot after a week or so, but we could also loop through and create many. Definitely makes me nervous to need the three steps in this one since it's really not easily rerunnable / reversible and it's in the OSS

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

@vercel
Copy link

vercel bot commented Aug 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hatchet-docs Ready Ready Preview Comment Sep 3, 2025 5:09pm
hatchet-v0-docs Ready Ready Preview Comment Sep 3, 2025 5:09pm

Copy link
Contributor

Copilot AI left a comment

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 implements table partitioning for the core lookup table (v1_lookup_table) to improve performance and enable efficient data management. The migration follows a standard pattern: create a new partitioned table, backfill data, and cut over to the new structure.

Key changes:

  • Modifies the primary key to include inserted_at for partition compatibility
  • Creates a partitioned version of the lookup table with weekly range partitions
  • Updates trigger functions to work with the new composite primary key

Reviewed Changes

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

File Description
sql/schema/v1-core.sql Updates table schema and trigger functions to use composite primary key (external_id, inserted_at)
cmd/hatchet-migrate/migrate/migrations/20250829173445_v1_0_41.sql Implements the complete migration with partitioned table creation, data backfill, and cutover logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 25 to 27
SELECT '19700101' INTO startDateStr;
SELECT TO_CHAR(date_trunc('week', (NOW() - INTERVAL '8 days')::DATE), 'YYYYMMDD') INTO endDateStr;
SELECT LOWER(FORMAT('%s_%s', targetTableName, startDateStr)) INTO newTableName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to confirm, anything older than 8 days goes into the same partition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah this was my version of "from the beginning of time until last week" just to make sure we catch everything

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.

3 participants