Create database while initializing application
The workflow in kanister is a bit different from what we
have in k10. In k10 we call initialize after reset but not
in kanister.
That is the reason this was failing in k10, I have made the
respective changes to fix this app.
@@ -333,6 +333,25 @@ func (a *RDSAuroraMySQLDB) Initialize(context.Context) error {
}
}()
+ createDB, err := db.Prepare(fmt.Sprintf("create database if not exists %s;", a.dbName))
+ if err != nil {
+ return errors.Wrap(err, "Error creating database while initializing app")
+ }
+
+ x, err := db.Begin()
+ if err != nil {
+ return errors.Wrap(err, "Error beginning transaction to create database")
+ }
+
+ _, err = x.Stmt(createDB).Exec()
+ if err != nil {
+ return errors.Wrap(err, "Error creating database while initializing Aurora application")
+ }
+
+ if err = x.Commit(); err != nil {
+ return errors.Wrap(err, "Error committing database creation")
+ }
+
query, err := db.Prepare("CREATE TABLE pets (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);")
if err != nil {
return errors.Wrap(err, "Error preparing query")
