Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lixdk-158-introduce-change-tags-to-filter-history-and-replace-the #3191

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
14 changes: 14 additions & 0 deletions packages/lix-sdk/docs/20-concepts/40-tag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tag

## Purpose

Categorize and organize data in a way that is meaningful to the user.

## Description

A tag is a label that can be applied to a change set. Tags can be used to categorize change sets, filter change sets, and search for change sets.

## Examples

- Tag a change set as confirmed e.g. the changes in the set should not be changed anymore.

18 changes: 18 additions & 0 deletions packages/lix-sdk/src/database/applySchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ export async function applySchema(args: { sqlite: SqliteDatabase }) {
FOREIGN KEY(change_id) REFERENCES change(id)
) strict;

-- tags on change sets
CREATE TABLE IF NOT EXISTS change_set_tag (
change_set_id TEXT NOT NULL,
tag_id TEXT NOT NULL,

UNIQUE(change_set_id, tag_id),
FOREIGN KEY(change_set_id) REFERENCES change_set(id),
FOREIGN KEY(tag_id) REFERENCES tag(id)
) strict;


-- discussions

Expand All @@ -117,5 +127,13 @@ export async function applySchema(args: { sqlite: SqliteDatabase }) {
FOREIGN KEY(discussion_id) REFERENCES discussion(id)
) strict;

-- tags

CREATE TABLE IF NOT EXISTS tag (
id TEXT PRIMARY KEY DEFAULT (uuid_v4()),
name TEXT NOT NULL UNIQUE -- e.g., 'confirmed', 'reviewed'
) strict;

INSERT OR IGNORE INTO tag (name) VALUES ('confirmed');
`;
}
18 changes: 18 additions & 0 deletions packages/lix-sdk/src/database/initDb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,22 @@ test("creating multiple discussions for one change set should be possible", asyn
.execute();

expect(discussions).toHaveLength(2);
});


test("the confirmed tag should be created if it doesn't exist", async () => {
const sqlite = await createInMemoryDatabase({
readOnly: false,
});
const db = initDb({ sqlite });

const tag = await db
.selectFrom("tag")
.selectAll()
.where("name", "=", "confirmed")
.executeTakeFirst();

expect(tag).toMatchObject({
name: "confirmed",
});
});
22 changes: 21 additions & 1 deletion packages/lix-sdk/src/database/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export type LixDatabaseSchema = {
change_graph_edge: ChangeGraphEdgeTable;
conflict: ConflictTable;
snapshot: SnapshotTable;
tag: TagTable;

// change set
change_set: ChangeSetTable;
change_set_item: ChangeSetItem;
change_set_item: ChangeSetItemTable;
change_set_tag: ChangeSetTagTable;

// discussion
discussion: DiscussionTable;
Expand Down Expand Up @@ -156,3 +158,21 @@ type CommentTable = {
created_at: Generated<string>;
body: string;
};

// ----- tags -----

export type Tag = Selectable<TagTable>;
export type NewTag = Insertable<TagTable>;
export type TagUpdate = Updateable<TagTable>;
type TagTable = {
id: Generated<string>;
name: string;
};

export type ChangeSetTag = Selectable<ChangeSetTagTable>;
export type NewChangeSetTag = Insertable<ChangeSetTagTable>;
export type ChangeSetTagUpdate = Updateable<ChangeSetTagTable>;
type ChangeSetTagTable = {
change_set_id: string;
tag_id: string;
};
Loading