-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e81d832
commit fcd0309
Showing
22 changed files
with
576 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
var cfg = New() | ||
|
||
// DB ... | ||
type DB struct { | ||
Addr string | ||
Database string | ||
Password string | ||
Port int | ||
Username string | ||
Prefix string | ||
} | ||
|
||
// Flags contains the command line flags. | ||
type Flags struct { | ||
Addr string `envconfig:"TYPHOON_ACCOUNTS_ADDR" default:":8084"` | ||
DatabaseURI string `envconfig:"TYPHOON_ACCOUNTS_DATABASE_URI" default:""` | ||
DatabaseTablePrefix string `envconfig:"TYPHOON_ACCOUNTS_DATABASE_TABLE_PREFIX" default:"typhoon_"` | ||
} | ||
|
||
// NewFlags ... | ||
func NewFlags() *Flags { | ||
return &Flags{ | ||
Addr: ":8084", | ||
DatabaseURI: "host=host.docker.internal user=example password=example dbname=example port=5432 sslmode=disable", | ||
DatabaseTablePrefix: "typhoon_", | ||
} | ||
} | ||
|
||
// New ... | ||
func New() *Config { | ||
return &Config{ | ||
Flags: NewFlags(), | ||
} | ||
} | ||
|
||
// Config ... | ||
type Config struct { | ||
Flags *Flags | ||
} | ||
|
||
// Cwd returns the current working directory. | ||
func (c *Config) Cwd() (string, error) { | ||
return os.Getwd() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cmd | ||
|
||
import ( | ||
seed "github.com/zeiss/gorm-seed" | ||
"github.com/zeiss/typhoon/internal/accounts/adapters/database" | ||
|
||
"github.com/spf13/cobra" | ||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
"gorm.io/gorm/schema" | ||
) | ||
|
||
var Migrate = &cobra.Command{ | ||
Use: "migrate", | ||
Short: "Migrate the database", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
conn, err := gorm.Open(postgres.Open(cfg.Flags.DatabaseURI), &gorm.Config{ | ||
NamingStrategy: schema.NamingStrategy{ | ||
TablePrefix: cfg.Flags.DatabaseTablePrefix, | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
store, err := seed.NewDatabase(conn, database.NewReadTx(), database.NewWriteTx()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return store.Migrate(cmd.Context()) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.