@@ -141,16 +141,24 @@ def distinct_tags(self, database):
141141 database ,
142142 """
143143 SELECT DISTINCT
144- id as "Original Tag ID",
145- original_tag as "Original Tag Name",
146- original_type as "Original Tag Type",
147- original_parent as "Original Parent Tag",
148- ao3_tag_fandom as "Related Fandom",
149- ao3_tag as "Recommended AO3 Tag",
150- ao3_tag_type as "Recommended AO3 Type",
151- ao3_tag_category as "Recommended AO3 Category",
152- original_description as "Original Description",
153- '' as "TW Notes" FROM tags
144+ t.id as "Original Tag ID",
145+ t.original_tag as "Original Tag Name",
146+ t.original_type as "Original Tag Type",
147+ t.original_parent as "Original Parent Tag",
148+ t.ao3_tag_fandom as "Related Fandom",
149+ t.ao3_tag as "Recommended AO3 Tag",
150+ t.ao3_tag_type as "Recommended AO3 Type",
151+ t.ao3_tag_category as "Recommended AO3 Category",
152+ t.original_description as "Original Description",
153+ '' as "TW Notes",
154+ CASE
155+ WHEN EXISTS (
156+ SELECT 1 FROM item_tags it
157+ WHERE it.tag_id = t.id AND it.item_type = 'story'
158+ ) THEN "Yes"
159+ ELSE "No"
160+ END AS "Used in Archive?"
161+ FROM tags t
154162 """ ,
155163 )
156164
@@ -206,7 +214,7 @@ def update_tag_row(self, row: dict):
206214 new_tag_id = sql_dict [0 ]["LAST_INSERT_ID()" ]
207215 # get all associated items from item_tags
208216 items = self .sql .execute_dict (
209- f"""SELECT item_id, item_type
217+ f"""SELECT item_id, item_type
210218 FROM item_tags WHERE tag_id = { row ['Original Tag ID' ]} """
211219 )
212220
0 commit comments