Merge pull request #107 from rolandshoemaker/aware-initables

Move InitTables and have it check for table existence before creation
This commit is contained in:
jsha 2015-04-23 14:35:38 -07:00
commit 6c8f6a26a7
2 changed files with 11 additions and 6 deletions

View File

@ -72,8 +72,7 @@ func main() {
wfe := wfe.NewWebFrontEndImpl(auditlogger)
sa, err := sa.NewSQLStorageAuthority(auditlogger, c.SA.DBDriver, c.SA.DBName)
cmd.FailOnError(err, "Unable to create SA")
err = sa.InitTables()
cmd.FailOnError(err, "Unable to initialize SA")
ra := ra.NewRegistrationAuthorityImpl(auditlogger)
va := va.NewValidationAuthorityImpl(auditlogger, c.CA.TestMode)

View File

@ -46,6 +46,12 @@ func NewSQLStorageAuthority(logger *blog.AuditLogger, driver string, name string
log: logger,
bucket: make(map[string]interface{}),
}
err = ssa.InitTables()
if err != nil {
return
}
return
}
@ -56,28 +62,28 @@ func (ssa *SQLStorageAuthority) InitTables() (err error) {
}
// Create registrations table
_, err = tx.Exec("CREATE TABLE registrations (id TEXT, thumbprint TEXT, value TEXT);")
_, err = tx.Exec("CREATE TABLE IF NOT EXISTS registrations (id TEXT, thumbprint TEXT, value TEXT);")
if err != nil {
tx.Rollback()
return
}
// Create pending authorizations table
_, err = tx.Exec("CREATE TABLE pending_authz (id TEXT, value BLOB);")
_, err = tx.Exec("CREATE TABLE IF NOT EXISTS pending_authz (id TEXT, value BLOB);")
if err != nil {
tx.Rollback()
return
}
// Create finalized authorizations table
_, err = tx.Exec("CREATE TABLE authz (sequence INTEGER, id TEXT, digest TEXT, value BLOB);")
_, err = tx.Exec("CREATE TABLE IF NOT EXISTS authz (sequence INTEGER, id TEXT, digest TEXT, value BLOB);")
if err != nil {
tx.Rollback()
return
}
// Create certificates table
_, err = tx.Exec("CREATE TABLE certificates (serial string, digest TEXT, value BLOB);")
_, err = tx.Exec("CREATE TABLE IF NOT EXISTS certificates (serial STRING, digest TEXT, value BLOB);")
if err != nil {
tx.Rollback()
return