golang.org/x/build@v0.0.0-20240506185731-218518f32b70/internal/relui/migrations/20220621201140_add_approved_at_to_tasks.up.sql (about)

     1  -- Copyright 2022 The Go Authors. All rights reserved.
     2  -- Use of this source code is governed by a BSD-style
     3  -- license that can be found in the LICENSE file.
     4  
     5  BEGIN;
     6  
     7  ALTER TABLE tasks
     8      ADD COLUMN approved_at timestamp WITH TIME ZONE NULL;
     9  
    10  WITH approved_tasks AS (
    11      SELECT workflow_id, task_name, max(created_at) AS created_at
    12      FROM task_logs
    13      WHERE body = 'USER-APPROVED'
    14      GROUP BY workflow_id, task_name
    15  )
    16  
    17  UPDATE tasks
    18  SET approved_at = approved_tasks.created_at
    19  FROM approved_tasks
    20  WHERE tasks.workflow_id = approved_tasks.workflow_id
    21    AND tasks.name = approved_tasks.task_name;
    22  
    23  COMMIT;