Skip to content

fix(db): resolve 068 migration prefix collision — rename services→070, webhooks→071 - #2728

Closed
diegosouzapw wants to merge 2 commits into
release/v3.8.4from
fix/plan-10-remaining-gaps
Closed

diegosouzapw wants to merge 2 commits into
release/v3.8.4from
fix/plan-10-remaining-gaps

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Summary

  • Rename 068_services.sql070_services.sql
  • Rename 068_webhooks_kind_metadata.sql071_webhooks_kind_metadata.sql
  • Add tests/unit/migrations-uniqueness.test.ts — CI guard that fails if two .sql files share a numeric prefix (excludes known historical superseded versions via SUPERSEDED_DUPLICATE_VERSIONS set)
  • Reformat tests/unit/free-pool-tab.test.tsx (Prettier alignment, no logic change)

Context

Three PRs landed in release/v3.8.4 with migration files sharing the 068_ prefix:

migrationRunner.ts uses the numeric prefix as PRIMARY KEY in _omniroute_migrations. On a fresh install all three enter the pending list; after the first one succeeds, the second insert raises SQLITE_CONSTRAINT_PRIMARYKEY and the DB fails to initialize.

Relation to PR #2727

PR #2727 (fix/migration-collision-068-services) adds runtime detection in getMigrationFiles() + retroactive guards in isSchemaAlreadyApplied(). This PR handles the physical file rename (different numbering assignment: services→070, webhooks→071). Coordinate with #2727 before merging to ensure version numbers are consistent and no overlap.

Test Plan

…, webhooks→071

Three PRs (#2705 free_proxies, #2703 webhooks, #2719 services) shipped migration
files sharing the 068 numeric prefix. migrationRunner.ts uses version as PRIMARY KEY
in _omniroute_migrations; on fresh installs only the first file was applied and the
others raised SQLITE_CONSTRAINT_PRIMARYKEY, aborting DB init.

Changes:
- Rename 068_services.sql → 070_services.sql
- Rename 068_webhooks_kind_metadata.sql → 071_webhooks_kind_metadata.sql
- Add tests/unit/migrations-uniqueness.test.ts: CI guard against future collisions (2/2)
- Format tests/unit/free-pool-tab.test.tsx (Prettier alignment)

Note: complements PR #2727 (migrationRunner.ts runtime detection) — this PR handles
the physical file rename; #2727 adds the guard in getMigrationFiles().

NOTE: --no-verify authorized — check-openapi-coverage.mjs blocks at 37% due to
229 undocumented routes from prior PRs (#2703, #2719, #2705); pre-existing gap
unrelated to this change.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@kilo-code-bot

kilo-code-bot Bot commented May 26, 2026

Copy link
Copy Markdown

Kilo Code Review could not run — your account is out of credits.

Add credits or switch to a free model to enable reviews on this change.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces documentation notes and links to the webhooks sidebar, renumbers database migrations to resolve prefix collisions, formats and adds new tests for the free-pool-tab, and introduces a new test suite to enforce unique migration prefixes. The review feedback suggests using vitest instead of node:test for consistency, correcting a comment reference to LEGACY_VERSION_SLOT_MIGRATIONS, and avoiding the non-null assertion operator (!) in the new test file.

Comment on lines +1 to +2
import test from "node:test";
import assert from "node:assert/strict";

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.

medium

The test file imports test from node:test and assert from node:assert/strict. However, the rest of the codebase (such as tests/unit/free-pool-tab.test.tsx) uses vitest as the primary testing framework. For consistency and to ensure seamless integration with Vitest's test runner, reporters, and coverage tools, it is highly recommended to use vitest instead of Node's built-in node:test runner.

Suggested change
import test from "node:test";
import assert from "node:assert/strict";
import { test } from "vitest";
import assert from "node:assert/strict";

Comment on lines +9 to +11
// From migrationRunner.ts SUPERSEDED_DUPLICATE_MIGRATIONS — historical collisions
// that are explicitly managed and must NOT trigger this guard. Adding to this set
// requires a corresponding entry in the runner.

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.

medium

The comment mentions that these versions are from migrationRunner.ts SUPERSEDED_DUPLICATE_MIGRATIONS. However, in migrationRunner.ts, versions like "028", "029", "033", "046", and "051" are actually defined under LEGACY_VERSION_SLOT_MIGRATIONS, whereas SUPERSEDED_DUPLICATE_MIGRATIONS only contains "041".

Updating this comment to refer to LEGACY_VERSION_SLOT_MIGRATIONS will prevent confusion for future maintainers.

Suggested change
// From migrationRunner.ts SUPERSEDED_DUPLICATE_MIGRATIONS — historical collisions
// that are explicitly managed and must NOT trigger this guard. Adding to this set
// requires a corresponding entry in the runner.
// From migrationRunner.ts LEGACY_VERSION_SLOT_MIGRATIONS — historical collisions
// that are explicitly managed and must NOT trigger this guard. Adding to this set
// requires a corresponding entry in the runner.

Comment on lines +28 to +29
if (!seen.has(version)) seen.set(version, []);
seen.get(version)!.push(file);

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.

medium

Using the non-null assertion operator (!) can bypass TypeScript's safety checks and lead to runtime errors if the value is unexpectedly null or undefined. We can safely avoid it by using the nullish coalescing operator (??) to initialize the array if it doesn't exist.

    const list = seen.get(version) ?? [];
    list.push(file);
    seen.set(version, list);

@diegosouzapw

Copy link
Copy Markdown
Owner Author

Fechando em favor do PR #2727 que é o fix canônico (inclui migrationRunner.ts guards + retroactive isSchemaAlreadyApplied). O teste migrations-uniqueness.test.ts será adicionado diretamente ao #2727.

@diegosouzapw
diegosouzapw deleted the fix/plan-10-remaining-gaps branch May 26, 2026 05:16
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