diff --git a/packages/lix-sdk/docs/20-concepts/40-change-tag.md b/packages/lix-sdk/docs/20-concepts/40-change-tag.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/lix-sdk/docs/20-concepts/40-tag.md b/packages/lix-sdk/docs/20-concepts/40-tag.md new file mode 100644 index 0000000000..564c4e64d9 --- /dev/null +++ b/packages/lix-sdk/docs/20-concepts/40-tag.md @@ -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. + diff --git a/packages/lix-sdk/src/database/applySchema.ts b/packages/lix-sdk/src/database/applySchema.ts index 8c430f60bc..60addd9f47 100644 --- a/packages/lix-sdk/src/database/applySchema.ts +++ b/packages/lix-sdk/src/database/applySchema.ts @@ -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 @@ -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'); `; } diff --git a/packages/lix-sdk/src/database/initDb.test.ts b/packages/lix-sdk/src/database/initDb.test.ts index d7cc1b5334..b214c6915c 100644 --- a/packages/lix-sdk/src/database/initDb.test.ts +++ b/packages/lix-sdk/src/database/initDb.test.ts @@ -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", + }); }); \ No newline at end of file diff --git a/packages/lix-sdk/src/database/schema.ts b/packages/lix-sdk/src/database/schema.ts index f173c05e87..ae9ef200e5 100644 --- a/packages/lix-sdk/src/database/schema.ts +++ b/packages/lix-sdk/src/database/schema.ts @@ -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; @@ -156,3 +158,21 @@ type CommentTable = { created_at: Generated; body: string; }; + +// ----- tags ----- + +export type Tag = Selectable; +export type NewTag = Insertable; +export type TagUpdate = Updateable; +type TagTable = { + id: Generated; + name: string; +}; + +export type ChangeSetTag = Selectable; +export type NewChangeSetTag = Insertable; +export type ChangeSetTagUpdate = Updateable; +type ChangeSetTagTable = { + change_set_id: string; + tag_id: string; +}; \ No newline at end of file