-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51f4ba9
commit d3c7daa
Showing
5 changed files
with
43 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
migrations/202407131920_add_response_state_to_request_events.go
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
migrations/202407171220_add_response_state_to_request_events.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package migrations | ||
|
||
import ( | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// Add response_received_at column to request_events table | ||
var _202407171220_add_response_received_at_to_request_events = &gormigrate.Migration{ | ||
ID: "202407171220_add_response_received_at_to_request_events", | ||
Migrate: func(tx *gorm.DB) error { | ||
if err := tx.Exec("ALTER TABLE request_events ADD COLUMN response_received_at TIMESTAMP DEFAULT '0001-01-01 00:00:00+00'").Error; err != nil { | ||
return err | ||
} | ||
|
||
// Update response_received_at if there is a corresponding row in response_events | ||
if err := tx.Exec(` | ||
UPDATE request_events re | ||
SET response_received_at = (SELECT created_at FROM response_events WHERE request_id = re.id) | ||
WHERE id IN (SELECT request_id FROM response_events WHERE request_id IS NOT NULL) | ||
`).Error; err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
if err := tx.Exec("ALTER TABLE request_events DROP COLUMN response_received_at").Error; err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters