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

multi parent relationship for changes #3180

Conversation

samuelstroschein
Copy link
Member

@samuelstroschein samuelstroschein commented Oct 18, 2024

Closes opral/lix-sdk#98

Changes

  • adds change_edges table to model multi parent relationships

Additional information

  • adds TODOS to branch related logic that does not affect the data structure (solving this now is a waste of time if branches changes the behaviour)

Copy link

changeset-bot bot commented Oct 18, 2024

⚠️ No Changeset found

Latest commit: a5dfd3d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

},
{
}),
expect.objectContaining({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the tests to expect.objectContaining to reduce the refactor effort in the future.

FOREIGN KEY(parent_id) REFERENCES change(id),
FOREIGN KEY(child_id) REFERENCES change(id),
-- Prevent self referencing edges
CHECK (parent_id != child_id)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know CHECK before. Very cool. SQLite now verifies that edges are not self-referencing. A unit test has been written as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall we used this to validate the id of the entity type. So if you try to insert an change id (here postfixed with the c) "415f1f62-2017-4761-9ece-519c1e5e45e3-c" into a snapshot you can fail early

Comment on lines 40 to 51
const parent = await lix.db
.selectFrom("change")
.innerJoin("snapshot", "snapshot.id", "change.snapshot_id")
.selectAll("change")
.select("snapshot.value")
.where("change.id", "=", change.parent_id)
.executeTakeFirstOrThrow();

const { rowIndex, columnIndex } = parent.value as unknown as Cell;
(parsed.data as any)[rowIndex][columnIndex] = "";
// if the row is empty after deleting the cell, remove it
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Querying the snapshot is not needed anymore if the entity_id exists on the change itself 😎

Comment on lines +19 to +20
// TODO https://github.com/opral/lix-sdk/issues/105
// .where(isInSimulatedCurrentBranch)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the TODOS that should be tackled after the branch milestone.

  • branching will influence the logic
  • working on this now is a waste of time

Comment on lines +76 to +81
if (parentEdges.length > 1) {
// https://github.com/opral/inlang-sdk/issues/134
throw new Error(
"Unimplemented. Multiple parents not supported until the branch feature exists.",
);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the TODOS that should be tackled after the branch milestone.

branching will influence the logic
working on this now is a waste of time

Copy link
Contributor

@martin-lysk martin-lysk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WIP review - will to look deeper into the helper queries

FOREIGN KEY(parent_id) REFERENCES change(id),
FOREIGN KEY(child_id) REFERENCES change(id),
-- Prevent self referencing edges
CHECK (parent_id != child_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall we used this to validate the id of the entity type. So if you try to insert an change id (here postfixed with the c) "415f1f62-2017-4761-9ece-519c1e5e45e3-c" into a snapshot you can fail early

lix/packages/sdk/src/database/initDb.test.ts Outdated Show resolved Hide resolved
lix/packages/sdk/src/database/applySchema.ts Show resolved Hide resolved
@samuelstroschein samuelstroschein merged commit e399964 into lix-integration Oct 18, 2024
2 checks passed
@samuelstroschein samuelstroschein deleted the lixdk-191-multi-parent-relationship-for-changes branch October 18, 2024 15:23
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants