Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move InitTables and have it check for table existence before creation #107

Merged
merged 6 commits into from Apr 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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