Skip to content

Commit 6d4819b

Browse files
committedOct 12, 2019
fix(sqlite): enable foreign keys for sqlite
1 parent 8ffce09 commit 6d4819b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎pkg/sqlite/load.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewSQLLiteLoader(outFilename string) (*SQLLoader, error) {
3535
CREATE TABLE IF NOT EXISTS package (
3636
name TEXT PRIMARY KEY,
3737
default_channel TEXT,
38-
FOREIGN KEY(default_channel) REFERENCES channel(name)
38+
FOREIGN KEY(name, default_channel) REFERENCES channel(package_name,name)
3939
);
4040
CREATE TABLE IF NOT EXISTS channel (
4141
name TEXT,
@@ -53,9 +53,7 @@ func NewSQLLiteLoader(outFilename string) (*SQLLoader, error) {
5353
replaces INTEGER,
5454
depth INTEGER,
5555
FOREIGN KEY(replaces) REFERENCES channel_entry(entry_id) DEFERRABLE INITIALLY DEFERRED,
56-
FOREIGN KEY(channel_name) REFERENCES channel(name),
57-
FOREIGN KEY(package_name) REFERENCES channel(package_name),
58-
FOREIGN KEY(operatorbundle_name) REFERENCES operatorbundle(name)
56+
FOREIGN KEY(channel_name, package_name) REFERENCES channel(name, package_name)
5957
);
6058
CREATE TABLE IF NOT EXISTS api (
6159
group_name TEXT,
@@ -74,6 +72,10 @@ func NewSQLLiteLoader(outFilename string) (*SQLLoader, error) {
7472
);
7573
`
7674

75+
if _, err := db.Exec("PRAGMA foreign_keys = ON", nil); err != nil {
76+
return nil, err
77+
}
78+
7779
if _, err = db.Exec(createTable); err != nil {
7880
return nil, err
7981
}

0 commit comments

Comments
 (0)