diff --git a/src/services/table_service.py b/src/services/table_service.py index 6b60b87..446972c 100644 --- a/src/services/table_service.py +++ b/src/services/table_service.py @@ -67,6 +67,15 @@ class TableService(SqliteService): "target_entry_title": link, }, ) + else: + self._execute( + "INSERT OR IGNORE INTO broken_links (source_entry_title, broken_link_title) VALUES (:source_entry_title, :broken_link_title)", + { + "source_entry_title": entry.get("title"), + "broken_link_title": link, + }, + ) + print("TB-INFO Junction tables populated") def __populate_fts_tables(self): self._execute("INSERT INTO entries_fts(entries_fts) VALUES('rebuild')") diff --git a/src/sql/create_tables.py b/src/sql/create_tables.py index 2f093a1..27863cc 100644 --- a/src/sql/create_tables.py +++ b/src/sql/create_tables.py @@ -23,6 +23,7 @@ CREATE TABLE IF NOT EXISTS backlinks ( ) """ + CREATE_ENTRIES_TAGS_TABLE = """ CREATE TABLE IF NOT EXISTS entries_tags ( entry_title TEXT, @@ -32,6 +33,15 @@ CREATE TABLE IF NOT EXISTS entries_tags ( PRIMARY KEY (entry_title, tag_name) )""" +CREATE_BROKEN_LINKS_TABLE = """ +CREATE TABLE IF NOT EXISTS broken_links ( + source_entry_title TEXT, broken_link_title TEXT, + FOREIGN KEY (source_entry_title) REFERENCES entries(title), + PRIMARY KEY (source_entry_title, broken_link_title) + ) +""" + + CREATE_ENTRIES_FTS_TABLE = """ CREATE VIRTUAL TABLE entries_fts USING fts5(title, body, content=entries, content_rowid=rowid) """ @@ -43,4 +53,5 @@ tables = [ {"name": "backlinks", "create_statement": CREATE_BACKLINKS_TABLE}, {"name": "entries_tags", "create_statement": CREATE_ENTRIES_TAGS_TABLE}, {"name": "entries_fts", "create_statement": CREATE_ENTRIES_FTS_TABLE}, + {"name": "broken_links", "create_statement": CREATE_BROKEN_LINKS_TABLE}, ]