Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): heal skipped 045 and warn on migration slot collisions #9312

ClosedImBIOS(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/9312/headopened View on GitHub

Showing 3 changed files with 124 additions and 0 deletions.

x
0 of 3 viewed, 3 left
60 additions and 0 deletionsapps/server/src/persistence/Migrations/047_EnsureProjectionProjectsAutoPull.test.tsAdded
View file
@@ -0,0 +1,60 @@
+import { assert, it } from "@effect/vitest";
+import * as Effect from "effect/Effect";
+import * as Layer from "effect/Layer";
+import * as SqlClient from "effect/unstable/sql/SqlClient";
+​
+import { runMigrations } from "../Migrations.ts";
+import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
+​
+const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layerMemory()));
+​
+layer("047_EnsureProjectionProjectsAutoPull", (it) => {
+ it.effect("heals databases whose 045 was skipped by a slot collision", () =>
+ Effect.gen(function* () {
+ const sql = yield* SqlClient.SqlClient;
+​
+ // Migrate to just before 045, then simulate a foreign line that claimed
+ // ID 45 first: the journal row exists, the column does not. The
+ // Migrator's max-ID logic then skips the real 045 forever (#8896).
+ yield* runMigrations({ toMigrationInclusive: 44 });
+ yield* sql`INSERT INTO effect_sql_migrations (migration_id, name) VALUES (45, 'SomethingElse')`;
+​
+ yield* runMigrations();
+​
+ const columns = yield* sql<{ readonly name: string; readonly notnull: number }>`
+ PRAGMA table_info(projection_projects)
+ `;
+ const autoPull = columns.find((column) => column.name === "auto_pull");
+ assert.equal(autoPull?.name, "auto_pull");
+ assert.equal(autoPull?.notnull, 1);
+​