···2194219421952195 orm.RunMigration(conn, logger, "delete-unused-pipeline-statuses", func(tx *sql.Tx) error {
21962196 _, err := tx.Exec(`
21972197- delete from pipeline_statuses as p
21982198- where p.status = 'pending'
21992199- and exists (
22002200- select 1 from pipeline_statuses as q
22012201- where q.pipeline_knot = p.pipeline_knot
22022202- and q.pipeline_rkey = p.pipeline_rkey
22032203- and q.workflow = p.workflow
22042204- and q.status = 'pending'
22052205- and q.created < p.created
21972197+ delete from pipeline_statuses
21982198+ where status = 'pending'
21992199+ and id not in (
22002200+ select min(id)
22012201+ from pipeline_statuses
22022202+ where status = 'pending'
22032203+ group by pipeline_knot, pipeline_rkey, workflow
22062204 );
22072205 `)
22082206 return err