puts "Destroying dependencies for superseded editions"

dependencies_for_superseded_editions = EditionDependency.includes(:edition).all.select {|ed| ed.edition.superseded? }
EditionDependency.where(id: dependencies_for_superseded_editions.map(&:id)).destroy_all

puts "Done."

Destroy dependencies for superseded editions
Destroy dependencies for superseded editions

https://trello.com/c/ibAvwvH7
https://trello.com/c/oYy2udbc

edition's dependencies are extracted when it is published,
and are destroyed when they're superseded. these 2 callbacks
were split across 2 PRs. there was a considerable gap between
the deploy times of the PRs of the 2 stories above. as a result,
edition's dependencies were created on publish, but not destroyed
when they were superseded.

this data migration fixes the invalid data that was created in
the meantime. from Preview:

> EditionDependency.all.map {|ed| ed.edition.state}.inject(Hash.new(0)) {|h, e| h[e] += 1; h}
=> {published=>176, superseded=>61}

as a result of running this data migration, the 61(+) dependency
records of superseded editions should get destroyed.
