Commit fb6f7163 authored by Sietse Ringers's avatar Sietse Ringers

feat: polish revocation db

parent 8338f81d
......@@ -62,6 +62,18 @@ func StartRevocationServer(t *testing.T) {
//dbtype, dbstr := "postgres", "host=127.0.0.1 port=5432 user=testuser dbname=test password='testpassword' sslmode=disable"
dbtype, dbstr := "mysql", "testuser:testpassword@tcp(127.0.0.1)/test"
// Connect to database and clear records from previous test runs
g, err := gorm.Open(dbtype, dbstr)
require.NoError(t, err)
require.NoError(t, g.DropTableIfExists((*irma.EventRecord)(nil)).Error)
require.NoError(t, g.DropTableIfExists((*irma.AccumulatorRecord)(nil)).Error)
require.NoError(t, g.DropTableIfExists((*irma.IssuanceRecord)(nil)).Error)
require.NoError(t, g.AutoMigrate((*irma.EventRecord)(nil)).Error)
require.NoError(t, g.AutoMigrate((*irma.AccumulatorRecord)(nil)).Error)
require.NoError(t, g.AutoMigrate((*irma.IssuanceRecord)(nil)).Error)
require.NoError(t, g.Close())
cred := irma.NewCredentialTypeIdentifier("irma-demo.MijnOverheid.root")
settings := map[irma.CredentialTypeIdentifier]*irma.RevocationSetting{
cred: {Mode: irma.RevocationModeServer},
......@@ -84,17 +96,6 @@ func StartRevocationServer(t *testing.T) {
RevocationDBType: dbtype,
}
// Connect to database and clear records from previous test runs
g, err := gorm.Open(dbtype, conf.RevocationDBConnStr)
require.NoError(t, err)
require.NoError(t, g.DropTableIfExists((*irma.EventRecord)(nil)).Error)
require.NoError(t, g.DropTableIfExists((*irma.AccumulatorRecord)(nil)).Error)
require.NoError(t, g.DropTableIfExists((*irma.IssuanceRecord)(nil)).Error)
require.NoError(t, g.AutoMigrate((*irma.EventRecord)(nil)).Error)
require.NoError(t, g.AutoMigrate((*irma.AccumulatorRecord)(nil)).Error)
require.NoError(t, g.AutoMigrate((*irma.IssuanceRecord)(nil)).Error)
require.NoError(t, g.Close())
// Enable revocation for our credential type
sk, err := irmaconf.Revocation.Keys.PrivateKeyLatest(cred.IssuerIdentifier())
require.NoError(t, err)
......
......@@ -108,9 +108,11 @@ func (s sqlRevStorage) Save(o interface{}) error {
}
func (s sqlRevStorage) Last(dest interface{}, query interface{}, args ...interface{}) error {
return s.gorm.
Where(query, args...).
Last(dest).Error
db := s.gorm
if query != nil {
db = db.Where(query, args...)
}
return db.Last(dest).Error
}
func (s sqlRevStorage) Exists(typ interface{}, query interface{}, args ...interface{}) (bool, error) {
......@@ -119,8 +121,8 @@ func (s sqlRevStorage) Exists(typ interface{}, query interface{}, args ...interf
if query != nil {
db = db.Where(query, args...)
}
db.Count(&c)
return c > 0, s.gorm.Error
db = db.Count(&c)
return c > 0, db.Error
}
func (s sqlRevStorage) From(dest interface{}, query interface{}, args ...interface{}) error {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment