Created
October 17, 2021 17:11
-
-
Save isopropylcyanide/bf56c4bd583412b599d63c9e2bb4043a to your computer and use it in GitHub Desktop.
Patch for protected banner status
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
diff --git a/main.go b/main.go | |
index 3d28cfa..ad7a3c2 100644 | |
--- a/main.go | |
+++ b/main.go | |
@@ -1,6 +1,7 @@ | |
package main | |
import ( | |
+ "database/sql" | |
"time" | |
"github.com/segmentio/ksuid" | |
@@ -20,6 +21,7 @@ type Banner struct { | |
ContentID string `gorm:"uniqueIndex:unique_live_banner_idx,priority=1,length:20"` | |
BannerStatus string `gorm:"uniqueIndex:unique_live_banner_idx,priority=2,length:20"` | |
IngestionStatus string `gorm:"uniqueIndex:unique_live_banner_idx,priority=3,length:20"` | |
+ ProtectedStatus sql.NullBool `gorm:"uniqueIndex:unique_live_banner_idx,priority=4"` | |
Name string | |
CreatedAt time.Time | |
UpdatedAt time.Time | |
@@ -31,12 +33,20 @@ func NewBanner(contentId, bannerStatus, ingestionStatus string) *Banner { | |
ContentID: contentId, | |
BannerStatus: bannerStatus, | |
IngestionStatus: ingestionStatus, | |
+ ProtectedStatus: sql.NullBool{}, | |
Name: babbler.Babble(), | |
CreatedAt: time.Now(), | |
UpdatedAt: time.Now(), | |
} | |
} | |
+func (b *Banner) BeforeCreate(*gorm.DB) (err error) { | |
+ if b.BannerStatus == b.IngestionStatus && b.BannerStatus == "LIVE" { | |
+ b.ProtectedStatus = sql.NullBool{Bool: true, Valid: true} | |
+ } | |
+ return | |
+} | |
+ | |
func main() { | |
db := setup() | |
defer cleanup(db) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment