Skip to content

Commit efb55c9

Browse files
committed
feat(verifier): update repository/postgres.go
1 parent 804f2be commit efb55c9

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

‎services/verifier/repository/postgres.go‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@ type PostgresDB struct {
1717
TableName string
1818
}
1919

20+
// postgresManifestLog mirrors model.ManifestLog but widens Version to int64,
21+
// since Postgres stores it as bigint while other stores keep using int.
22+
type postgresManifestLog struct {
23+
ID string `json:"id"`
24+
Version int64 `json:"version"`
25+
CreatedAt time.Time `json:"created_at"`
26+
SignatureValid bool `json:"signature_valid"`
27+
Status string `json:"status"`
28+
}
29+
30+
func newPostgresManifestLog(log model.ManifestLog) postgresManifestLog {
31+
return postgresManifestLog{
32+
ID: log.ID,
33+
Version: int64(log.Version),
34+
CreatedAt: log.CreatedAt,
35+
SignatureValid: log.SignatureValid,
36+
Status: log.Status,
37+
}
38+
}
39+
40+
func (l postgresManifestLog) toModel() model.ManifestLog {
41+
return model.ManifestLog{
42+
ID: l.ID,
43+
Version: int(l.Version),
44+
CreatedAt: l.CreatedAt,
45+
SignatureValid: l.SignatureValid,
46+
Status: l.Status,
47+
}
48+
}
49+
2050
func NewPostgresDB(cfg config.Config) (*PostgresDB, error) {
2151
db, err := connectPostgres(cfg.PGDB)
2252
if err != nil {
@@ -103,16 +133,17 @@ func (d *PostgresDB) UpdateSubscriptions(subs []model.Subscription) error {
103133
}
104134

105135
func (d *PostgresDB) GetLatestManifestLog() (model.ManifestLog, error) {
106-
var logEntry model.ManifestLog
136+
var logEntry postgresManifestLog
107137
err := d.Client.Table("manifest_logs").Order("version DESC").First(&logEntry).Error
108138
if err != nil {
109139
return model.ManifestLog{Version: 0}, nil
110140
}
111-
return logEntry, nil
141+
return logEntry.toModel(), nil
112142
}
113143

114144
func (d *PostgresDB) AddManifestLog(log model.ManifestLog) error {
115-
err := d.Client.Table("manifest_logs").Create(&log).Error
145+
entry := newPostgresManifestLog(log)
146+
err := d.Client.Table("manifest_logs").Create(&entry).Error
116147
if err != nil {
117148
return err
118149
}
@@ -121,7 +152,7 @@ func (d *PostgresDB) AddManifestLog(log model.ManifestLog) error {
121152

122153
func (d *PostgresDB) CleanupManifestLogs() error {
123154
expirationTime := time.Now().AddDate(0, 0, -7)
124-
err := d.Client.Table("manifest_logs").Where("created_at < ?", expirationTime).Delete(&model.ManifestLog{}).Error
155+
err := d.Client.Table("manifest_logs").Where("created_at < ?", expirationTime).Delete(&postgresManifestLog{}).Error
125156
if err != nil {
126157
return err
127158
}

0 commit comments

Comments
 (0)