Skip to content

Commit

Permalink
refactor: change default amigo folder from .amigo to migrations/db
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisvisco committed Nov 5, 2024
1 parent 9fd2bf0 commit 8eff848
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 15 deletions.
4 changes: 2 additions & 2 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const contextFileName = "config.yml"
var contextCmd = &cobra.Command{
Use: "context",
Short: "save flags into a context",
Long: `A context is a file inside the .amigo folder that contains the flags that you use in the command line.
Long: `A context is a file inside the amigo folder that contains the flags that you use in the command line.
Example:
amigo context --dsn "postgres://user:password@host:port/dbname?sslmode=disable"
This command will create a file .amigo/context.yaml with the content:
This command will create a file $amigo_folder/context.yaml with the content:
dsn: "postgres://user:password@host:port/dbname?sslmode=disable"
`,
Run: wrapCobraFunc(func(cmd *cobra.Command, _ amigo.Amigo, args []string) error {
Expand Down
9 changes: 2 additions & 7 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var rootCmd = &cobra.Command{
Long: `Basic usage:
First you need to create a main folder with amigo init:
will create a folder named .amigo with a context file inside to not have to pass the dsn every time.
will create a folder in migrations/db with a context file inside to not have to pass the dsn every time.
Postgres:
$ amigo context --dsn "postgres://user:password@host:port/dbname?sslmode=disable"
Expand All @@ -43,7 +43,7 @@ First you need to create a main folder with amigo init:
note: will create:
- folder named migrations with a file named migrations.go that contains the list of migrations
- a new migration to create the schema version table
- a main.go in the .amigo folder
- a main.go in the $amigo_folder
Apply migrations:
$ amigo migrate
Expand Down Expand Up @@ -114,7 +114,6 @@ func initConfig() {
}

_ = viper.BindPFlag("dsn", rootCmd.PersistentFlags().Lookup("dsn"))
_ = viper.BindPFlag("amigo-folder", rootCmd.PersistentFlags().Lookup("amigo-folder"))
_ = viper.BindPFlag("json", rootCmd.PersistentFlags().Lookup("json"))
_ = viper.BindPFlag("folder", rootCmd.PersistentFlags().Lookup("folder"))
_ = viper.BindPFlag("package", rootCmd.PersistentFlags().Lookup("package"))
Expand All @@ -137,10 +136,6 @@ func initConfig() {
cmdCtx.DSN = viper.GetString("dsn")
}

if viper.IsSet("amigo-folder") {
cmdCtx.AmigoFolderPath = viper.GetString("amigo-folder")
}

if viper.IsSet("json") {
cmdCtx.JSON = viper.GetBool("json")
}
Expand Down
5 changes: 2 additions & 3 deletions docs/docs/02-quick-start/02-initialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

To start using mig, you need to initialize it. This process creates few things:
- A `migrations` folder where you will write your migrations.
- A `.amigo` folder where mig stores its configuration and the main file to run migrations.
- A `migrations/db` folder where mig stores its configuration and the main file to run migrations.
- A migration file to setup the table that will store the migration versions.

To initialize mig, run the following command:
Expand All @@ -28,14 +28,13 @@ Note: The `--schema-version-table` flag is optional and is used to specify the t

### Configuration

A config.yml file will be created in the `.amigo` folder. You can edit it to add more configurations.
A config.yml file will be created in the $amigo_folder folder. You can edit it to add more configurations.

It contains the following fields:
```yaml
dsn: postgres://user:password@localhost:5432/dbname
folder: migrations
json: false
amigo-folder: .amigo
package: migrations
pg-dump-path: pg_dump
schema-version-table: public.mig_schema_versions
Expand Down
1 change: 0 additions & 1 deletion example/pg/.amigo/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
amigo-folder: .amigo
debug: false
dsn: postgres://postgres:postgres@localhost:6666/postgres?sslmode=disable
folder: migrations
Expand Down
1 change: 0 additions & 1 deletion example/sqlite/.amigo/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
amigo-folder: .amigo
debug: false
dsn: sqlite:data.db
folder: migrations
Expand Down
2 changes: 1 addition & 1 deletion pkg/amigoctx/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (

var (
DefaultSchemaVersionTable = "public.mig_schema_versions"
DefaultAmigoFolder = ".amigo"
DefaultAmigoFolder = "migrations/db"
DefaultMigrationFolder = "migrations"
DefaultPackagePath = "migrations"
DefaultShellPath = "/bin/bash"
Expand Down

0 comments on commit 8eff848

Please sign in to comment.