Skip to content

Commit

Permalink
make lix_id nano_id to increase shareability
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelstroschein committed Dec 22, 2024
1 parent f974b30 commit 91e771a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/lix-sdk/src/key-value/database-schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { sql } from "kysely";
import { expect, test } from "vitest";
import { openLixInMemory } from "../lix/open-lix-in-memory.js";
import { validate as validateUuid } from "uuid";

test("string values are accepted", async () => {
const lix = await openLixInMemory({});
Expand Down Expand Up @@ -94,7 +93,8 @@ test("using json as value should work", async () => {
});
});

test("it should default add a uuid lix_id if not exits", async () => {
// 1919T IDs needed, in order to have a 1% probability of at least one collision.
test("it should default add nano_id(18) for the lix_id if not exits", async () => {
const lix = await openLixInMemory({});

const result = await lix.db
Expand All @@ -103,7 +103,7 @@ test("it should default add a uuid lix_id if not exits", async () => {
.selectAll()
.executeTakeFirstOrThrow();

expect(validateUuid(result.value)).toBe(true);
expect(result.value).toHaveLength(18);
});

test("default value for lix_sync to reduce conditional logic (the key is always set)", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/lix-sdk/src/key-value/database-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function applyKeyValueDatabaseSchema(
) STRICT;
INSERT OR IGNORE INTO key_value (key, value)
VALUES ('lix_id', uuid_v4());
VALUES ('lix_id', nano_id(18));
-- default value for lix sync to false
-- if not exist to remove conditional logic
Expand Down

0 comments on commit 91e771a

Please sign in to comment.