-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3186 from opral/lixdk-161-introduce-concept-of-ch…
…ange-sets add: change sets
- Loading branch information
Showing
8 changed files
with
260 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { test, expect } from "vitest"; | ||
import { openLixInMemory } from "../open/openLixInMemory.js"; | ||
import { createChangeSet } from "./create-change-set.js"; | ||
|
||
test("creating a change set should succeed", async () => { | ||
const lix = await openLixInMemory({}); | ||
|
||
const mockChanges = await lix.db | ||
.insertInto("change") | ||
.values([ | ||
{ | ||
type: "file", | ||
entity_id: "value1", | ||
file_id: "mock", | ||
plugin_key: "mock-plugin", | ||
snapshot_id: "sn1", | ||
}, | ||
{ | ||
type: "file", | ||
entity_id: "value2", | ||
file_id: "mock", | ||
plugin_key: "mock-plugin", | ||
snapshot_id: "sn2", | ||
}, | ||
]) | ||
.returningAll() | ||
.execute(); | ||
|
||
const changeSet = await createChangeSet({ | ||
lix, | ||
changeIds: mockChanges.map((change) => change.id), | ||
}); | ||
|
||
const changeSetMembers = await lix.db | ||
.selectFrom("change_set_item") | ||
.selectAll() | ||
.where("change_set_id", "=", changeSet.id) | ||
.execute(); | ||
|
||
expect(changeSetMembers.map((member) => member.change_id)).toEqual( | ||
expect.arrayContaining([mockChanges[0]?.id, mockChanges[1]?.id]), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { ChangeSet } from "../database/schema.js"; | ||
import type { Lix } from "../types.js"; | ||
|
||
export async function createChangeSet(args: { | ||
lix: Lix; | ||
changeIds: string[]; | ||
}): Promise<ChangeSet> { | ||
return await args.lix.db.transaction().execute(async (trx) => { | ||
const changeSet = await trx | ||
.insertInto("change_set") | ||
.defaultValues() | ||
.returningAll() | ||
.executeTakeFirstOrThrow(); | ||
|
||
for (const changeId of args.changeIds) { | ||
await trx | ||
.insertInto("change_set_item") | ||
.values({ | ||
change_id: changeId, | ||
change_set_id: changeSet.id, | ||
}) | ||
.execute(); | ||
} | ||
return changeSet; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters