// Start with the main version
const mainVersion = await lix.db
.selectFrom("version")
.where("name", "=", "main")
.selectAll()
.executeTakeFirstOrThrow();
// Create a feature branch
const featureVersion = await createVersion({
lix,
name: "feature/dark-theme",
changeSet: { id: mainVersion.change_set_id },
inherits_from_version_id: mainVersion.id
});
// Switch to the feature branch
await switchVersion({
lix,
to: featureVersion.id
});
// Make changes in the feature branch
await handleFileUpdate({
lix,
file: {
path: "/config.json",
data: new TextEncoder().encode(JSON.stringify({
theme: "dark",
// other settings...
}))
}
});
// Create a change set for the feature
const featureChangeSet = await createChangeSet({
lix,
labels: [
{ key: "type", value: "feature" },
{ key: "proposal", value: "true" },
{ key: "title", value: "Add dark theme support" },
{ key: "description", value: "This change adds dark theme support with proper contrast ratios." },
{ key: "status", value: "open" }
]
});
// Update the feature version to point to the new change set
await lix.db
.updateTable("version")
.set({
change_set_id: featureChangeSet.id
})
.where("id", "=", featureVersion.id)
.execute();
// Create a discussion thread
const thread = await lix.db
.insertInto("thread")
.values({
id: generateId(),
title: "Add dark theme support",
description: "This change adds a new dark theme option to the application settings.",
created_at: new Date().toISOString(),
change_set_id: featureChangeSet.id
})
.returningAll()
.executeTakeFirstOrThrow();
// Add the proposal target
await lix.db
.insertInto("proposal_target")
.values({
id: generateId(),
proposal_change_set_id: featureChangeSet.id,
target_version_id: mainVersion.id,
created_at: new Date().toISOString()
})
.execute();
// Reviewer adds a comment
await lix.db
.insertInto("comment")
.values({
id: generateId(),
thread_id: thread.id,
content: "Please adjust the contrast of the secondary colors.",
author: "reviewer@example.com",
created_at: new Date().toISOString()
})
.execute();
// Proposer makes the requested changes
await handleFileUpdate({
lix,
file: {
path: "/config.json",
data: new TextEncoder().encode(JSON.stringify({
theme: "dark",
contrast: "high",
// other settings...
}))
}
});
// Create a new change set for the revision
const revisionChangeSet = await createChangeSet({
lix,
parents: [{ id: featureChangeSet.id }],
labels: [
{ key: "type", value: "revision" },
{ key: "proposal", value: "true" },
{ key: "title", value: "Add dark theme support" },
{ key: "description", value: "Updated with higher contrast ratios per review feedback." },
{ key: "status", value: "in-review" }
]
});
// Update the feature version to point to the revised change set
await lix.db
.updateTable("version")
.set({
change_set_id: revisionChangeSet.id
})
.where("id", "=", featureVersion.id)
.execute();
// Proposer adds a comment about the changes
await lix.db
.insertInto("comment")
.values({
id: generateId(),
thread_id: thread.id,
content: "I've increased the contrast ratio as requested. The theme now passes WCAG AA standards.",
author: "proposer@example.com",
created_at: new Date().toISOString()
})
.execute();
// Reviewer approves
await lix.db
.insertInto("change_set_label")
.values({
id: generateId(),
entity_id: revisionChangeSet.id,
key: "approved-by",
value: "reviewer@example.com",
created_at: new Date().toISOString()
})
.execute();
// Update status to approved
await lix.db
.updateTable("change_set_label")
.set({
value: "approved"
})
.where("entity_id", "=", revisionChangeSet.id)
.where("key", "=", "status")
.execute();
// Create a merge change set
const mergeChangeSet = await createMergeChangeSet({
lix,
sources: [
{ id: mainVersion.change_set_id },
{ id: revisionChangeSet.id }
]
});
// Update the main version to point to the merge change set
await lix.db
.updateTable("version")
.set({
change_set_id: mergeChangeSet.id
})
.where("id", "=", mainVersion.id)
.execute();
// Update the proposal status
await lix.db
.updateTable("change_set_label")
.set({
value: "merged"
})
.where("entity_id", "=", revisionChangeSet.id)
.where("key", "=", "status")
.execute();
// Add a merge notification
await lix.db
.insertInto("comment")
.values({
id: generateId(),
thread_id: thread.id,
content: `Changes have been merged into the main version.`,
author: "system",
created_at: new Date().toISOString()
})
.execute();