polish code
diff --git a/data.go b/data.go
index f2ea8a4..c2b3ecf 100644
--- a/data.go
+++ b/data.go
@@ -7,6 +7,7 @@
"encoding/json"
"github.com/30x/apid-core"
+ "strings"
)
var (
@@ -96,20 +97,27 @@
return nil
}
-func AlterTable(db apid.DB) error {
- _, err := db.Exec(`
- ALTER TABLE edgex_deployment ADD COLUMN bundle_uri text;
- ALTER TABLE edgex_deployment ADD COLUMN local_bundle_uri text;
- ALTER TABLE edgex_deployment ADD COLUMN bundle_checksum text;
- ALTER TABLE edgex_deployment ADD COLUMN bundle_checksum_type text;
- ALTER TABLE edgex_deployment ADD COLUMN deploy_status string;
- ALTER TABLE edgex_deployment ADD COLUMN deploy_error_code int;
- ALTER TABLE edgex_deployment ADD COLUMN deploy_error_message text;
- `)
- if err != nil {
- return err
+func alterTable(db apid.DB) error {
+ queries := []string{
+ "ALTER TABLE edgex_deployment ADD COLUMN bundle_uri text;",
+ "ALTER TABLE edgex_deployment ADD COLUMN local_bundle_uri text;",
+ "ALTER TABLE edgex_deployment ADD COLUMN bundle_checksum text;",
+ "ALTER TABLE edgex_deployment ADD COLUMN bundle_checksum_type text;",
+ "ALTER TABLE edgex_deployment ADD COLUMN deploy_status string;",
+ "ALTER TABLE edgex_deployment ADD COLUMN deploy_error_code int;",
+ "ALTER TABLE edgex_deployment ADD COLUMN deploy_error_message text;",
}
+ for _, query := range queries {
+ _, err := db.Exec(query)
+ if err != nil {
+ if strings.Contains(err.Error(), "duplicate column name") {
+ log.Warnf("AlterTable warning: %s", err)
+ } else {
+ return err
+ }
+ }
+ }
log.Debug("Database table altered.")
return nil
}
diff --git a/listener.go b/listener.go
index 5f1d50f..8a4f017 100644
--- a/listener.go
+++ b/listener.go
@@ -9,7 +9,6 @@
"github.com/30x/apid-core"
"github.com/apigee-labs/transicator/common"
- "strings"
)
const (
@@ -56,13 +55,9 @@
}
// alter table
- err = AlterTable(db)
+ err = alterTable(db)
if err != nil {
- if !strings.Contains(err.Error(), "duplicate") {
- log.Panicf("Alter table failed: %v", err)
- } else {
- log.Info("start with local sqlite DB")
- }
+ log.Panicf("Alter table failed: %v", err)
}
// ensure that no new database updates are made on old database
dbMux.Lock()