-
Notifications
You must be signed in to change notification settings - Fork 99
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
refactor: add entity id #3170
refactor: add entity id #3170
Conversation
|
.select([ | ||
"change.id", | ||
"change.author", | ||
"change.created_at", | ||
"change.snapshot_id", | ||
"change.parent_id", | ||
"change.entity_id", | ||
"change.type", | ||
"change.file_id", | ||
"change.plugin_key", | ||
"snapshot.value as value", | ||
"change.meta", | ||
"change.commit_id", | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required because an .innerJoin("snapshot", "snapshot.id", "change.snapshot_id") select all overshadows the change.id with the snapshot.id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh god what a beast - this combined with flaky run envs in test (importing from dist...) Sounds like fun.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into the code - seems there are a couple more places where this is still a problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can use some bits in the uuid v7 to encode the entity type (like id of a change vs id of a snapshot) - In a former project we used some of the machine id bits in snowflake to signal the type of the id. This allowed us to runtime assert correct entities early based on passed id's - saved us hours, if not days of debugging and post mortems.
Not the solution - and I need into uuid v7 but to outline what I have in mind:
If every id of a change must end with a C
40e97286-9b78-4a35-8fb1-0036bdfbbf7C
Every id of a snapshot ends with an S
40e97286-9b78-4a35-8fb1-0036bdfbbf7S
We could assert in a function like getLeafChange that the id is an expected one:
getLeafChange(change) {
if (!change.id.endsWith('C')) {
throw new WrongObjectTypePassedError("The Id passed is not the id of a change")
}
....
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double checked kysely we can make use selectAll with 'change' as parameter and and an explicit select
.select([ | |
"change.id", | |
"change.author", | |
"change.created_at", | |
"change.snapshot_id", | |
"change.parent_id", | |
"change.entity_id", | |
"change.type", | |
"change.file_id", | |
"change.plugin_key", | |
"snapshot.value as value", | |
"change.meta", | |
"change.commit_id", | |
]) | |
+ .selectAll('change') | |
+ .select('snapshot.value') |
which is translated to:
SELECT
"change".*,
"snapshot"."value"
I will commit on this pr and fix the other places where we make use of innerjoin as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow I was looking for select('change.*')
. I didn't think about using selectAll('change')
. Nice.
const changes = await lix.db | ||
.selectFrom("change") | ||
.innerJoin("snapshot", "snapshot.id", "change.snapshot_id") | ||
.selectAll() | ||
.execute(); | ||
|
||
// console.log(await lix.db.selectFrom("queue").selectAll().execute()); | ||
|
||
expect(changes).toEqual([ | ||
{ | ||
id: changes[0]?.id, | ||
author: "Test User", | ||
created_at: changes[0]?.created_at, | ||
snapshot_id: changes[0]?.snapshot_id, | ||
parent_id: null, | ||
type: "text", | ||
file_id: "test", | ||
plugin_key: "mock-plugin", | ||
value: { | ||
id: "test", | ||
text: "inserted text", | ||
}, | ||
meta: null, | ||
commit_id: null, | ||
}, | ||
]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The discussion test tested the change queue :D redundant
}); | ||
|
||
if (previousCommittedDiff?.length === 0) { | ||
const previousSnapshot = await trx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice: The snapshot can now be queried on demand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we remove the lix.commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to remove it in another PR. One step at a time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was just about that one line in the test (as you where cleaning up the discussion tests as well - but not important)
// console.log({ args }); | ||
for (const plugin of args.plugins) { | ||
// glob expressions are expressed relative without leading / but path has leading / | ||
if (!minimatch(normalizePath(args.after.path), "/" + plugin.glob)) { | ||
break; | ||
} | ||
|
||
const diffs = await plugin.diff!.file!({ | ||
const diffs = await plugin.diff?.file?.({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the diff function optional for plugins? I would prefer to fail here - while we should check for undefined with a nice error message instead of the ! I would rather fail early instead of returning - no change silently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will impement that in https://linear.app/opral/issue/LIXDK-107/plugindifffileortype-plugindetectchanges
|
||
for (const plugin of args.plugins) { | ||
// glob expressions are expressed relative without leading / but path has leading / | ||
if (!minimatch(normalizePath(args.after.path), "/" + plugin.glob)) { | ||
break; | ||
} | ||
|
||
const diffs = await plugin.diff!.file!({ | ||
const diffs = await plugin.diff?.file?.({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see previous comment about failling instead of optional chaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will impement this in https://linear.app/opral/issue/LIXDK-107/plugindifffileortype-plugindetectchanges
author: args.currentAuthor, | ||
parent_id: previousChange?.id, | ||
snapshot_id: snapshotId, | ||
snapshot_id: snapshot.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
way better/cleaner than the (await ...).id
Closes opral/lix-sdk#94
Changes
entity_id
to a change& { id: string}
requirement from snapshots