-
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
2162263
commit 51f4ba9
Showing
4 changed files
with
46 additions
and
7 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: 33 additions & 0 deletions
33
migrations/202407131920_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 column to request_events table | ||
var _202407131920_add_response_state_to_request_events = &gormigrate.Migration{ | ||
ID: "202407131920_add_response_state_to_request_events", | ||
Migrate: func(tx *gorm.DB) error { | ||
if err := tx.Exec("ALTER TABLE request_events ADD COLUMN response_received BOOLEAN DEFAULT FALSE").Error; err != nil { | ||
return err | ||
} | ||
|
||
// Update response_received to TRUE if there is a corresponding row in response_events | ||
if err := tx.Exec(` | ||
UPDATE request_events | ||
SET response_received = TRUE | ||
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").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