Remove unused revision repository
This commit is contained in:
+48
-44
@@ -5,12 +5,11 @@ import { eq } from "drizzle-orm";
|
||||
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
||||
import {
|
||||
createDatabaseContext,
|
||||
type AppDatabase,
|
||||
type DatabaseContext,
|
||||
} from "../src/db/database-context.js";
|
||||
import {
|
||||
ProjectRevisionConflictError,
|
||||
ProjectRevisionRepository,
|
||||
} from "../src/db/repositories/project-revision.repository.js";
|
||||
import { ProjectRevisionConflictError } from "../src/domain/errors/project-revision-conflict.error.js";
|
||||
import { appendProjectRevision } from "../src/db/repositories/project-revision.persistence.js";
|
||||
import { ProjectSnapshotRepository } from "../src/db/repositories/project-snapshot.repository.js";
|
||||
import { projectChangeSets } from "../src/db/schema/project-change-sets.js";
|
||||
import { projectRevisions } from "../src/db/schema/project-revisions.js";
|
||||
@@ -27,40 +26,50 @@ function createTestDatabase(): DatabaseContext {
|
||||
}
|
||||
|
||||
function appendTestRevision(
|
||||
repository: ProjectRevisionRepository,
|
||||
database: AppDatabase,
|
||||
expectedRevision: number
|
||||
) {
|
||||
return repository.append({
|
||||
projectId: "project-1",
|
||||
expectedRevision,
|
||||
source: "user",
|
||||
description: "Stromkreis bearbeiten",
|
||||
actorId: "test-user",
|
||||
forward: {
|
||||
schemaVersion: 1,
|
||||
type: "circuit.update",
|
||||
payload: { circuitId: "circuit-1", displayName: "Neu" },
|
||||
},
|
||||
inverse: {
|
||||
schemaVersion: 1,
|
||||
type: "circuit.update",
|
||||
payload: { circuitId: "circuit-1", displayName: "Alt" },
|
||||
},
|
||||
});
|
||||
return database.transaction((tx) =>
|
||||
appendProjectRevision(tx, {
|
||||
projectId: "project-1",
|
||||
expectedRevision,
|
||||
source: "user",
|
||||
description: "Stromkreis bearbeiten",
|
||||
actorId: "test-user",
|
||||
forward: {
|
||||
schemaVersion: 1,
|
||||
type: "circuit.update",
|
||||
payload: { circuitId: "circuit-1", displayName: "Neu" },
|
||||
},
|
||||
inverse: {
|
||||
schemaVersion: 1,
|
||||
type: "circuit.update",
|
||||
payload: { circuitId: "circuit-1", displayName: "Alt" },
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
describe("project revision repository", () => {
|
||||
function getCurrentRevision(database: AppDatabase, projectId: string) {
|
||||
return (
|
||||
database
|
||||
.select({ currentRevision: projects.currentRevision })
|
||||
.from(projects)
|
||||
.where(eq(projects.id, projectId))
|
||||
.get()?.currentRevision ?? null
|
||||
);
|
||||
}
|
||||
|
||||
describe("project revision persistence", () => {
|
||||
it("appends immutable revision metadata and payloads with a monotonic number", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const repository = new ProjectRevisionRepository(context.db);
|
||||
|
||||
assert.equal(repository.getCurrentRevision("project-1"), 0);
|
||||
const appended = appendTestRevision(repository, 0);
|
||||
assert.equal(getCurrentRevision(context.db, "project-1"), 0);
|
||||
const appended = appendTestRevision(context.db, 0);
|
||||
|
||||
assert.equal(appended.projectId, "project-1");
|
||||
assert.equal(appended.revisionNumber, 1);
|
||||
assert.equal(repository.getCurrentRevision("project-1"), 1);
|
||||
assert.equal(getCurrentRevision(context.db, "project-1"), 1);
|
||||
|
||||
const revision = context.db
|
||||
.select()
|
||||
@@ -105,9 +114,9 @@ describe("project revision repository", () => {
|
||||
}),
|
||||
});
|
||||
|
||||
const next = appendTestRevision(repository, 1);
|
||||
const next = appendTestRevision(context.db, 1);
|
||||
assert.equal(next.revisionNumber, 2);
|
||||
assert.equal(repository.getCurrentRevision("project-1"), 2);
|
||||
assert.equal(getCurrentRevision(context.db, "project-1"), 2);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
@@ -116,18 +125,17 @@ describe("project revision repository", () => {
|
||||
it("rejects a stale expected revision without writing history", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const repository = new ProjectRevisionRepository(context.db);
|
||||
appendTestRevision(repository, 0);
|
||||
appendTestRevision(context.db, 0);
|
||||
|
||||
assert.throws(
|
||||
() => appendTestRevision(repository, 0),
|
||||
() => appendTestRevision(context.db, 0),
|
||||
(error) =>
|
||||
error instanceof ProjectRevisionConflictError &&
|
||||
error.expectedRevision === 0 &&
|
||||
error.actualRevision === 1
|
||||
);
|
||||
|
||||
assert.equal(repository.getCurrentRevision("project-1"), 1);
|
||||
assert.equal(getCurrentRevision(context.db, "project-1"), 1);
|
||||
assert.equal(context.db.select().from(projectRevisions).all().length, 1);
|
||||
assert.equal(context.db.select().from(projectChangeSets).all().length, 1);
|
||||
} finally {
|
||||
@@ -145,14 +153,12 @@ describe("project revision repository", () => {
|
||||
SELECT RAISE(ABORT, 'forced change-set failure');
|
||||
END;
|
||||
`);
|
||||
const repository = new ProjectRevisionRepository(context.db);
|
||||
|
||||
assert.throws(
|
||||
() => appendTestRevision(repository, 0),
|
||||
() => appendTestRevision(context.db, 0),
|
||||
/forced change-set failure/
|
||||
);
|
||||
|
||||
assert.equal(repository.getCurrentRevision("project-1"), 0);
|
||||
assert.equal(getCurrentRevision(context.db, "project-1"), 0);
|
||||
assert.equal(context.db.select().from(projectRevisions).all().length, 0);
|
||||
assert.equal(context.db.select().from(projectChangeSets).all().length, 0);
|
||||
} finally {
|
||||
@@ -163,7 +169,6 @@ describe("project revision repository", () => {
|
||||
it("captures and retains automatic snapshots without deleting named snapshots", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const revisions = new ProjectRevisionRepository(context.db);
|
||||
const snapshots = new ProjectSnapshotRepository(context.db);
|
||||
const named = snapshots.createNamed({
|
||||
projectId: "project-1",
|
||||
@@ -177,7 +182,7 @@ describe("project revision repository", () => {
|
||||
expectedRevision < 325;
|
||||
expectedRevision += 1
|
||||
) {
|
||||
appendTestRevision(revisions, expectedRevision);
|
||||
appendTestRevision(context.db, expectedRevision);
|
||||
}
|
||||
|
||||
const stored = context.db
|
||||
@@ -234,13 +239,12 @@ describe("project revision repository", () => {
|
||||
it("rolls back revision 25 when automatic snapshot persistence fails", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const repository = new ProjectRevisionRepository(context.db);
|
||||
for (
|
||||
let expectedRevision = 0;
|
||||
expectedRevision < 24;
|
||||
expectedRevision += 1
|
||||
) {
|
||||
appendTestRevision(repository, expectedRevision);
|
||||
appendTestRevision(context.db, expectedRevision);
|
||||
}
|
||||
context.sqlite.exec(`
|
||||
CREATE TRIGGER fail_automatic_project_snapshot
|
||||
@@ -252,10 +256,10 @@ describe("project revision repository", () => {
|
||||
`);
|
||||
|
||||
assert.throws(
|
||||
() => appendTestRevision(repository, 24),
|
||||
() => appendTestRevision(context.db, 24),
|
||||
/forced automatic snapshot failure/
|
||||
);
|
||||
assert.equal(repository.getCurrentRevision("project-1"), 24);
|
||||
assert.equal(getCurrentRevision(context.db, "project-1"), 24);
|
||||
assert.equal(
|
||||
context.db.select().from(projectRevisions).all().length,
|
||||
24
|
||||
Reference in New Issue
Block a user