Skip to content

Commit

Permalink
Merge pull request #107 from rolandshoemaker/aware-initables
Browse files Browse the repository at this point in the history
Move InitTables and have it check for table existence before creation
  • Loading branch information
jsha committed Apr 23, 2015
2 parents ba622d4 + b63c9f3 commit 6c8f6a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 1 addition & 2 deletions cmd/boulder/main.go
Expand Up @@ -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)

Expand Down
14 changes: 10 additions & 4 deletions sa/storage-authority.go
Expand Up @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit 6c8f6a2

Please sign in to comment.