From 8eff84804fdf43d4f096f5038946a9146493c1b9 Mon Sep 17 00:00:00 2001 From: Alexis Viscogliosi Date: Tue, 5 Nov 2024 09:57:10 +0100 Subject: [PATCH] refactor: change default amigo folder from .amigo to migrations/db --- cmd/context.go | 4 ++-- cmd/root.go | 9 ++------- docs/docs/02-quick-start/02-initialize.md | 5 ++--- example/pg/.amigo/config.yml | 1 - example/sqlite/.amigo/config.yml | 1 - pkg/amigoctx/ctx.go | 2 +- 6 files changed, 7 insertions(+), 15 deletions(-) diff --git a/cmd/context.go b/cmd/context.go index afa7857..af1048f 100644 --- a/cmd/context.go +++ b/cmd/context.go @@ -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 { diff --git a/cmd/root.go b/cmd/root.go index 927f1a6..be1e5ca 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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" @@ -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 @@ -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")) @@ -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") } diff --git a/docs/docs/02-quick-start/02-initialize.md b/docs/docs/02-quick-start/02-initialize.md index 48e28b3..af97bec 100644 --- a/docs/docs/02-quick-start/02-initialize.md +++ b/docs/docs/02-quick-start/02-initialize.md @@ -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: @@ -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 diff --git a/example/pg/.amigo/config.yml b/example/pg/.amigo/config.yml index 99a185a..f592cf2 100644 --- a/example/pg/.amigo/config.yml +++ b/example/pg/.amigo/config.yml @@ -1,4 +1,3 @@ -amigo-folder: .amigo debug: false dsn: postgres://postgres:postgres@localhost:6666/postgres?sslmode=disable folder: migrations diff --git a/example/sqlite/.amigo/config.yml b/example/sqlite/.amigo/config.yml index bb789a4..66a3e2a 100644 --- a/example/sqlite/.amigo/config.yml +++ b/example/sqlite/.amigo/config.yml @@ -1,4 +1,3 @@ -amigo-folder: .amigo debug: false dsn: sqlite:data.db folder: migrations diff --git a/pkg/amigoctx/ctx.go b/pkg/amigoctx/ctx.go index b89bb5a..fc94c93 100644 --- a/pkg/amigoctx/ctx.go +++ b/pkg/amigoctx/ctx.go @@ -16,7 +16,7 @@ var ( var ( DefaultSchemaVersionTable = "public.mig_schema_versions" - DefaultAmigoFolder = ".amigo" + DefaultAmigoFolder = "migrations/db" DefaultMigrationFolder = "migrations" DefaultPackagePath = "migrations" DefaultShellPath = "/bin/bash"