-
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.
feat: add schema sql generated optionally
- better logging support - possibility to migrate using schema.sql (for fresh installs) - dump the schema via amigo schema - dump the schema via migrate/rollback cmd (-d flag) - update documentation
- Loading branch information
1 parent
631d00b
commit 037e60e
Showing
30 changed files
with
880 additions
and
580 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
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,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
|
||
"github.com/alexisvisco/amigo/pkg/amigo" | ||
"github.com/alexisvisco/amigo/pkg/utils" | ||
"github.com/alexisvisco/amigo/pkg/utils/events" | ||
"github.com/alexisvisco/amigo/pkg/utils/logger" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var schemaCmd = &cobra.Command{ | ||
Use: "schema", | ||
Short: "Dump the schema of the database using appropriate tool", | ||
Long: `Dump the schema of the database using appropriate tool. | ||
Supported databases: | ||
- postgres with pg_dump`, | ||
Run: wrapCobraFunc(func(cmd *cobra.Command, am amigo.Amigo, args []string) error { | ||
if err := cmdCtx.ValidateDSN(); err != nil { | ||
return err | ||
} | ||
|
||
return dumpSchema(am) | ||
}), | ||
} | ||
|
||
func dumpSchema(am amigo.Amigo) error { | ||
file, err := utils.CreateOrOpenFile(cmdCtx.SchemaOutPath) | ||
if err != nil { | ||
return fmt.Errorf("unable to open/create file: %w", err) | ||
} | ||
|
||
defer file.Close() | ||
|
||
err = am.DumpSchema(file, false) | ||
if err != nil { | ||
return fmt.Errorf("unable to dump schema: %w", err) | ||
} | ||
|
||
logger.Info(events.FileModifiedEvent{FileName: path.Join(cmdCtx.SchemaOutPath)}) | ||
return nil | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(schemaCmd) | ||
} |
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.