Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview/db: fix stray stars from deleted repositories

youn.dev 148a3bb8 608c2762

verified
+24
+24
appview/db/db.go
··· 1255 1255 return err 1256 1256 }) 1257 1257 1258 + // the generalize-stars-subject migration removed the foreign key constraint 1259 + // from stars, so deleting a repo no longer cascades to its stars. 1260 + // this trigger restores that behaviour at the application level. 1261 + orm.RunMigration(conn, logger, "add-star-cleanup-trigger", func(tx *sql.Tx) error { 1262 + _, err := tx.Exec(` 1263 + create trigger if not exists delete_stars_on_repo_delete 1264 + after delete on repos 1265 + begin 1266 + delete from stars where subject_at = OLD.at_uri; 1267 + end; 1268 + `) 1269 + return err 1270 + }) 1271 + 1272 + // purge stars that reference repos deleted before the trigger was added. 1273 + orm.RunMigration(conn, logger, "cleanup-orphaned-stars", func(tx *sql.Tx) error { 1274 + _, err := tx.Exec(` 1275 + delete from stars 1276 + where subject_at like 'at://%/sh.tangled.repo/%' 1277 + and subject_at not in (select at_uri from repos); 1278 + `) 1279 + return err 1280 + }) 1281 + 1258 1282 return &DB{ 1259 1283 db, 1260 1284 logger,