You've already forked golang-saas-starter-kit
mirror of
https://github.com/raseels-repos/golang-saas-starter-kit.git
synced 2025-08-08 22:36:41 +02:00
try to fix broken schema migration for accounts table
This commit is contained in:
@ -616,7 +616,7 @@ so each job is dependant on the previous or run jobs for each target environment
|
||||
|
||||
A build tool called [devops](https://gitlab.com/geeks-accelerator/oss/saas-starter-kit/tree/master/tools/devops) has
|
||||
been included apart of this project. _Devops_ handles creating AWS resources and deploying your services with minimal
|
||||
additional configuration. You can customizing any of the configuration in the code. While AWS is already a core part of
|
||||
additional configuration. You can customize any of the configuration in the code. While AWS is already a core part of
|
||||
the saas-starter-kit, keeping the deployment in GoLang limits the scope of additional technologies required to get your
|
||||
project successfully up and running. If you understand Golang, then you will be a master at devops with this tool.
|
||||
|
||||
|
@ -249,7 +249,7 @@ the install instructions for Go](http://golang.org/doc/install.html).
|
||||
|
||||
To install _cicd_, simply run:
|
||||
```
|
||||
$ go get geeks-accelerator/oss/saas-starter-kit/build/cicd
|
||||
$ go get -v geeks-accelerator/oss/saas-starter-kit/build/cicd
|
||||
```
|
||||
|
||||
Make sure your `PATH` includes the `$GOPATH/bin` directory so your commands can
|
||||
|
@ -59,6 +59,9 @@ func migrationList(ctx context.Context, db *sqlx.DB, log *log.Logger, isUnittest
|
||||
{
|
||||
ID: "20190522-01c",
|
||||
Migrate: func(tx *sql.Tx) error {
|
||||
if err := dropTypeIfExists(tx, "account_status_t"); err != nil {
|
||||
return err
|
||||
}
|
||||
q1 := `CREATE TYPE account_status_t as enum('active','pending','disabled')`
|
||||
if _, err := tx.Exec(q1); err != nil && !errorIsAlreadyExists(err) {
|
||||
return errors.WithMessagef(err, "Query failed %s", q1)
|
||||
@ -89,7 +92,7 @@ func migrationList(ctx context.Context, db *sqlx.DB, log *log.Logger, isUnittest
|
||||
return nil
|
||||
},
|
||||
Rollback: func(tx *sql.Tx) error {
|
||||
q1 := `DROP TYPE account_status_t`
|
||||
q1 := `DROP TYPE IF EXISTS account_status_t`
|
||||
if _, err := tx.Exec(q1); err != nil {
|
||||
return errors.WithMessagef(err, "Query failed %s", q1)
|
||||
}
|
||||
@ -105,11 +108,17 @@ func migrationList(ctx context.Context, db *sqlx.DB, log *log.Logger, isUnittest
|
||||
{
|
||||
ID: "20190522-01e",
|
||||
Migrate: func(tx *sql.Tx) error {
|
||||
if err := dropTypeIfExists(tx, "user_account_role_t"); err != nil {
|
||||
return err
|
||||
}
|
||||
q1 := `CREATE TYPE user_account_role_t as enum('admin', 'user')`
|
||||
if _, err := tx.Exec(q1); err != nil && !errorIsAlreadyExists(err) {
|
||||
return errors.WithMessagef(err, "Query failed %s", q1)
|
||||
}
|
||||
|
||||
if err := dropTypeIfExists(tx, "user_account_status_t"); err != nil {
|
||||
return err
|
||||
}
|
||||
q2 := `CREATE TYPE user_account_status_t as enum('active', 'invited','disabled')`
|
||||
if _, err := tx.Exec(q2); err != nil && !errorIsAlreadyExists(err) {
|
||||
return errors.WithMessagef(err, "Query failed %s", q2)
|
||||
@ -139,7 +148,7 @@ func migrationList(ctx context.Context, db *sqlx.DB, log *log.Logger, isUnittest
|
||||
return errors.WithMessagef(err, "Query failed %s", q1)
|
||||
}
|
||||
|
||||
q2 := `DROP TYPE userr_account_status_t`
|
||||
q2 := `DROP TYPE user_account_status_t`
|
||||
if _, err := tx.Exec(q2); err != nil {
|
||||
return errors.WithMessagef(err, "Query failed %s", q2)
|
||||
}
|
||||
@ -156,6 +165,10 @@ func migrationList(ctx context.Context, db *sqlx.DB, log *log.Logger, isUnittest
|
||||
{
|
||||
ID: "20190622-01",
|
||||
Migrate: func(tx *sql.Tx) error {
|
||||
if err := dropTypeIfExists(tx, "project_status_t"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
q1 := `CREATE TYPE project_status_t as enum('active','disabled')`
|
||||
if _, err := tx.Exec(q1); err != nil && !errorIsAlreadyExists(err) {
|
||||
return errors.WithMessagef(err, "Query failed %s", q1)
|
||||
@ -669,10 +682,19 @@ func migrationList(ctx context.Context, db *sqlx.DB, log *log.Logger, isUnittest
|
||||
}
|
||||
}
|
||||
|
||||
// dropTypeIfExists executes drop type.
|
||||
func dropTypeIfExists(tx *sql.Tx, name string) error {
|
||||
q := "DROP TYPE IF EXISTS" + name
|
||||
if _, err := tx.Exec(q); err != nil && !errorIsAlreadyExists(err) {
|
||||
return errors.WithMessagef(err, "Query failed %s", q)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// errorIsAlreadyExists checks an error message for the error "already exists"
|
||||
func errorIsAlreadyExists(err error) bool {
|
||||
if strings.Contains(err.Error(), "already exists") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user