Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from schemahero/generate
Generate
- Loading branch information
Showing
2,190 changed files
with
290,768 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,30 @@ | ||
# Migrating To SchemaHero | ||
|
||
Like most of us, you probably already have a database (or several) running in production. You've invested in your current tooling and have a many database migrations. The process of converting these into YAML that can be managed with SchemaHero isn't difficult, but it's time consuming and tedious. SchemaHero has functionality that can help, if you can access a running instance of your database. | ||
|
||
Note: We recommend that you run the import tool against a local, dev instance when possible. | ||
|
||
## Schema Import | ||
|
||
To start, get the `schemahero` binary (or use the Docker container) and provide a connection string to your database: | ||
|
||
``` | ||
$ schemahero generate \ | ||
--driver postgres \ | ||
--uri postgres://user:pass@host:5432/dbname \ | ||
--dbname destired-schemahero-databasename \ | ||
--output-dir ./imported | ||
``` | ||
|
||
or | ||
|
||
``` | ||
$ docker run schemahero/schemahero -v `pwd`/imported:/out \ | ||
generate \ | ||
--driver postgres \ | ||
--uri postgres://user:pass@host:5432/dbname \ | ||
--dbname destired-schemahero-databasename \ | ||
--output-dir ./imported | ||
``` | ||
|
||
This will create .yaml files (1 per table) that you can deploy to a cluster to recreate the schema |
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,34 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/schemahero/schemahero/pkg/generate" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func Generate() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "generate", | ||
Short: "generate schemahero custom resources from a running database instance", | ||
Long: `...`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
g := generate.NewGenerator() | ||
return g.RunSync() | ||
}, | ||
} | ||
|
||
cmd.Flags().StringP("driver", "d", "", "name of the database driver to use") | ||
cmd.Flags().StringP("uri", "u", "", "connection string uri") | ||
cmd.Flags().StringP("namespace", "n", "default", "namespace to put the custom resources into") | ||
cmd.Flags().StringP("dbname", "", "", "schemahero database name to write in the yaml") | ||
cmd.Flags().StringP("output-dir", "o", "", "directory to write schema files to") | ||
|
||
cmd.MarkFlagRequired("driver") | ||
cmd.MarkFlagRequired("uri") | ||
cmd.MarkFlagRequired("dbname") | ||
|
||
viper.BindPFlags(cmd.Flags()) | ||
|
||
return cmd | ||
} |
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
Oops, something went wrong.