mirror of
https://github.com/mholt/timeliner.git
synced 2025-12-30 17:30:22 -06:00
Keep relationships unique
Bidirectional is not part of the unique constraints because I don't think it's relevant when checking for uniqueness.
This commit is contained in:
8
db.go
8
db.go
@@ -116,11 +116,15 @@ CREATE TABLE IF NOT EXISTS "relationships" (
|
||||
"to_person_id" INTEGER,
|
||||
"to_item_id" INTEGER,
|
||||
"directed" BOOLEAN, -- if false, the edge goes both ways
|
||||
"label" TEXT,
|
||||
"label" TEXT NOT NULL,
|
||||
FOREIGN KEY ("from_item_id") REFERENCES "items"("id") ON DELETE CASCADE,
|
||||
FOREIGN KEY ("to_item_id") REFERENCES "items"("id") ON DELETE CASCADE,
|
||||
FOREIGN KEY ("from_person_id") REFERENCES "persons"("id") ON DELETE CASCADE,
|
||||
FOREIGN KEY ("to_person_id") REFERENCES "persons"("id") ON DELETE CASCADE
|
||||
FOREIGN KEY ("to_person_id") REFERENCES "persons"("id") ON DELETE CASCADE,
|
||||
UNIQUE ("from_item_id", "to_item_id", "label"),
|
||||
UNIQUE ("from_person_id", "to_person_id", "label"),
|
||||
UNIQUE ("from_item_id", "to_person_id", "label"),
|
||||
UNIQUE ("from_person_id", "to_item_id", "label")
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "collections" (
|
||||
|
||||
@@ -109,7 +109,7 @@ func (wc *WrappedClient) processItemGraph(ig *ItemGraph, state *recursiveState)
|
||||
|
||||
// insert relations to this connected node into DB
|
||||
for _, rel := range relations {
|
||||
_, err = wc.tl.db.Exec(`INSERT INTO relationships
|
||||
_, err = wc.tl.db.Exec(`INSERT OR IGNORE INTO relationships
|
||||
(from_item_id, to_item_id, directed, label)
|
||||
VALUES (?, ?, ?, ?)`,
|
||||
igRowID, connectedIGRowID, !rel.Bidirectional, rel.Label)
|
||||
@@ -156,7 +156,7 @@ func (wc *WrappedClient) processItemGraph(ig *ItemGraph, state *recursiveState)
|
||||
}
|
||||
|
||||
// store the relation
|
||||
_, err = wc.tl.db.Exec(`INSERT INTO relationships
|
||||
_, err = wc.tl.db.Exec(`INSERT OR IGNORE INTO relationships
|
||||
(from_item_id, to_item_id, directed, label)
|
||||
VALUES (?, ?, ?, ?)`,
|
||||
fromItemRowID, toItemRowID, rr.Bidirectional, rr.Label)
|
||||
|
||||
Reference in New Issue
Block a user