Skip to content

Commit

Permalink
Env adjustments and env behavior changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bayucandra committed Nov 16, 2019
1 parent 8649fe9 commit 29a9afd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

Following is steps to seed the database:

- Copy and rename template **.env.example** to **.env**
- Adjust **.env** accordingly
- Configuration setting

Mainly, configuration is passed trough Environment variables. There are 2 option regarding this matter:

1. By **.env** file. You can copy and rename template **.env.example** to **.env**. Or by **.env-custom** then pass it by : `go-seed-pg .env-custom`
2. Directly configure Environment variables in your OS ( helpful for CI/CD things ). If you using linux or OSX, should be something like `export VAR_NAME=value`. Please check list of variables need to sets at .env-example

- Adjust **.env** or **environment variables** ( depend on **Configuration setting** you choose) accordingly
- `SOURCE_DATA` inside **.env** is path of your data seed which contain CSV exported data from PostgreSQL table
- So, create a directory based on your `SOURCE_DATA` variable
- Sort the table based on relationship dependencies
Expand Down
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ import (

func main() {

if ( os.Getenv("GO_ENV") == "development" ) {
if os.Getenv("GO_ENV") == "development" || os.Getenv("GO_ENV") == "test" {
log.SetFlags(log.LstdFlags | log.Lshortfile)
}

err := loadEnv(".env")
envFile := ".env"

if len(os.Args) > 1 {
envFile = os.Args[1]
}

err := loadEnv( envFile)

if err != nil {
log.Fatal(err)
log.Println("Not loading .env var")
}

_, err = checkEnv()
Expand Down

0 comments on commit 29a9afd

Please sign in to comment.