diff --git a/appview/db/db.go b/appview/db/db.go index 39689e42..7427ed83 100644 --- a/appview/db/db.go +++ b/appview/db/db.go @@ -2194,15 +2194,13 @@ func Make(ctx context.Context, dbPath string) (*DB, error) { orm.RunMigration(conn, logger, "delete-unused-pipeline-statuses", func(tx *sql.Tx) error { _, err := tx.Exec(` - delete from pipeline_statuses as p - where p.status = 'pending' - and exists ( - select 1 from pipeline_statuses as q - where q.pipeline_knot = p.pipeline_knot - and q.pipeline_rkey = p.pipeline_rkey - and q.workflow = p.workflow - and q.status = 'pending' - and q.created < p.created + delete from pipeline_statuses + where status = 'pending' + and id not in ( + select min(id) + from pipeline_statuses + where status = 'pending' + group by pipeline_knot, pipeline_rkey, workflow ); `) return err