@@ -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+
2050func 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
105135func (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
114144func (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
122153func (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