Skip to content

feat: DB Migrations - #1661

Open
andypols wants to merge 4 commits into
finos:mainfrom
qube-rt:feat/db-migrations
Open

feat: DB Migrations#1661
andypols wants to merge 4 commits into
finos:mainfrom
qube-rt:feat/db-migrations

Conversation

@andypols

Copy link
Copy Markdown
Contributor

Description

This PR provides adds DB migrations. #1656 adds dateCreated and lastModified to repository records to support sorting or repository by date. This cannot be used without a corresponding migration of existing data.

Each migration is tracked by its own unique ID, rather than relying on a single global “current database version”. This means two branches can add separate migrations and be merged in either order. When both reach main, GitProxy checks the complete registry and runs whichever migration IDs have not yet been applied.

This gives us:

  • a clear history of data changes
  • one shared implementation across database backends
  • a record of which changes have already run
  • safe restart behaviour after a partial migration
  • optional rollback support
  • a consistent pattern for future schema and data changes

Example migration

For example a migration for #1656 could be implemented like this.

import type { Repo } from '../types';
import type { Migration } from './index';

export const addRepoDates: Migration = {
  id: '20260722-add-repo-dates',
  up: async (sink) => { 
    const repos = await sink.getRepos(); 
    for (const repo of repos) {
      if (repo.dateCreated && repo.lastModified) { 
        continue; 
      }

      const dateCreated =
        repo.dateCreated ?? (await sink.deriveCreatedAt(repo._id)) ?? new Date().toISOString();

      await sink.updateRepo({
          ...repo, 
          dateCreated, 
          lastModified: repo.lastModified ?? dateCreated, 
      });
    } 
  }, 
};

andypols added 4 commits July 28, 2026 14:53
Signed-off-by: Andrew Pols <andrew.pols@qube-rt.com>
Signed-off-by: Andrew Pols <andrew.pols@qube-rt.com>
Signed-off-by: Andrew Pols <andrew.pols@qube-rt.com>
Signed-off-by: Andrew Pols <andrew.pols@qube-rt.com>
@andypols
andypols requested a review from a team as a code owner July 28, 2026 19:29
@netlify

netlify Bot commented Jul 28, 2026

Copy link
Copy Markdown

Deploy Preview for endearing-brigadeiros-63f9d0 canceled.

Name Link
🔨 Latest commit 3759c31
🔍 Latest deploy log https://app.netlify.com/projects/endearing-brigadeiros-63f9d0/deploys/6a6903390e8de80008fe9999

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant