Skip to content

Conversation

@skyfallwastaken
Copy link
Member

@skyfallwastaken skyfallwastaken commented Feb 2, 2026

Should - in theory at least - lead to some good perf wins?

There's a migration doc we'd need to follow after too

(please please please make a backup before merging this)

Copilot AI review requested due to automatic review settings February 2, 2026 20:29
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 a database normalization migration for heartbeat data by introducing lookup tables (LUTs) for dimensions and removing the raw_data JSONB column to improve performance.

Changes:

  • Creates 8 lookup tables for heartbeat dimensions (languages, categories, editors, operating systems, user agents, projects, branches, machines)
  • Adds foreign key columns to the heartbeats table with corresponding indexes
  • Implements a dual-write system via feature flags to populate both old string columns and new FK columns during migration
  • Provides backfill job and rake tasks to populate FK columns for existing heartbeats

Reviewed changes

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

Show a summary per file
File Description
db/migrate/20260202194401_create_heartbeat_lookup_tables.rb Creates the 8 lookup tables with unique indexes
db/migrate/20260202194406_add_lookup_foreign_keys_to_heartbeats.rb Adds FK columns and indexes to heartbeats table
db/migrate/20260202194410_add_foreign_key_constraints_to_heartbeats.rb Adds unvalidated foreign key constraints
db/schema.rb Reflects all database schema changes including new tables, columns, and indexes
app/models/heartbeats/*.rb Defines model classes for all lookup tables
app/models/concerns/heartbeat_dimension_resolver.rb Implements dimension resolution logic for both single records and batch operations
app/models/heartbeat.rb Integrates dimension resolver concern
app/jobs/backfill_heartbeat_dimensions_job.rb Background job to backfill FK columns for existing heartbeats
app/jobs/migrate_user_from_hackatime_job.rb Updated to conditionally skip raw_data and use batch dimension resolution
app/services/heartbeat_import_service.rb Updated to conditionally skip raw_data and use batch dimension resolution
lib/tasks/backfill_heartbeat_dimensions.rake Rake tasks to enqueue backfill jobs and check progress
docs/heartbeat_normalization_migration.md Migration guide with step-by-step instructions

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

skyfallwastaken and others added 2 commits February 2, 2026 20:33
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@3kh0 3kh0 requested review from 3kh0 and maxwofford February 2, 2026 20:33
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