Skip to content

Commit

Permalink
be: add is run to migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ganiszulfa committed Mar 11, 2023
1 parent 34ba81b commit 0fa2c9e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# BACKEND

## Local Development

### DB

```
docker run --name pg -e POSTGRES_PASSWORD=postgres -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_DB=concise -d postgres
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var CreateMetadataTableSQLUp = `

func (m *Migrators) createMetadataTable() {
key := "CreateMetadataTable"
err := runMigration(m, CreateMetadataTableSQLUp, key)
_, err := runMigration(m, CreateMetadataTableSQLUp, key)
if err != nil {
panic(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var CreatePostsTableSQLUp = `

func (m *Migrators) createPostsTable() {
key := "CreatePostsTable"
err := runMigration(m, CreatePostsTableSQLUp, key)
_, err := runMigration(m, CreatePostsTableSQLUp, key)
if err != nil {
panic(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/ganiszulfa/concise/backend/pkg/generate"
"github.com/sirupsen/logrus"
)

var InitMetadataSQLUp = `
Expand All @@ -20,8 +21,11 @@ func (m *Migrators) initMetadata() {
key := "InitMetadata"
pwd := generate.RandAlphabetsLowerCase(24)
sql := fmt.Sprintf(InitMetadataSQLUp, pwd)
err := runMigration(m, sql, key)
isRun, err := runMigration(m, sql, key)
if err != nil {
panic(err)
}
if isRun {
logrus.Infof("Your user password is %s", pwd)
}
}
4 changes: 3 additions & 1 deletion backend/internal/models/migrations/migrations_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func create(m *Migrators, key string) (err error) {
return
}

func runMigration(m *Migrators, sql, key string) (err error) {
func runMigration(m *Migrators, sql, key string) (isRun bool, err error) {

if isExist(m, key) {
return
Expand All @@ -56,5 +56,7 @@ func runMigration(m *Migrators, sql, key string) (err error) {
if err := create(m, key); err != nil {
panic(err)
}

isRun = true
return
}

0 comments on commit 0fa2c9e

Please sign in to comment.