Monorepo for Tangled tangled.org

appview/db: remove foreign key constraint between collections

Appview cannot modify the user-owned record on repository deletion

Signed-off-by: Seongmin Lee <git@boltless.me>

boltless.me dff0057d 96e24108

verified
+23
+23
appview/db/db.go
··· 1173 1173 return err 1174 1174 }) 1175 1175 1176 + // we cannot modify user-owned record on repository delete 1177 + orm.RunMigration(conn, logger, "remove-foreign-key-profile_pinned_repositories-and-repos", func(tx *sql.Tx) error { 1178 + _, err := tx.Exec(` 1179 + create table profile_pinned_repositories_new ( 1180 + did text not null, 1181 + 1182 + -- data 1183 + at_uri text not null, 1184 + 1185 + -- constraints 1186 + unique(did, at_uri), 1187 + foreign key (did) references profile(did) on delete cascade 1188 + ); 1189 + 1190 + insert into profile_pinned_repositories_new (did, at_uri) 1191 + select did, at_uri from profile_pinned_repositories; 1192 + 1193 + drop table profile_pinned_repositories; 1194 + alter table profile_pinned_repositories_new rename to profile_pinned_repositories; 1195 + `) 1196 + return err 1197 + }) 1198 + 1176 1199 return &DB{ 1177 1200 db, 1178 1201 logger,