-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds the ability to execute down migrations using: ``` hydra migrate sql down -e --steps {num_of_steps} ``` Please read `hydra migrate sql down --help` carefully. Going forward, please use the following command to apply up migrations ``` hydra migrate sql up ... ``` instead of the previous, now deprecated ``` hydra migrate sql ... ``` command. See ory-corp/cloud#7350
- Loading branch information
Showing
16 changed files
with
245 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright © 2022 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/hydra/v2/driver" | ||
"github.com/ory/x/configx" | ||
"github.com/ory/x/servicelocatorx" | ||
|
||
"github.com/ory/hydra/v2/cmd/cli" | ||
) | ||
|
||
func NewMigrateSqlDownCmd(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModifier, cOpts []configx.OptionModifier) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "down <database-url>", | ||
Short: "Roll back SQL migrations", | ||
Args: cobra.RangeArgs(0, 1), | ||
Example: `Revert the most recent migration: | ||
DSN=... hydra migrate sql down -e --steps 1 | ||
Review migrations to decide which one to roll back: | ||
DSN=... hydra migrate sql down -e --steps 0 | ||
Revert a specific migration: | ||
DSN=... hydra migrate sql down -e --version 20230606112801000001 | ||
`, | ||
Long: `Run this command to roll back SQL migrations. This command is useful when you want to revert to a previous version of Ory Hydra. | ||
:::warning | ||
Before running this command on an existing database, create a back up. This command can be destructive as it may drop | ||
indices, columns, or whole tables. Run this command close to the SQL instance (same VPC / same machine). | ||
::: | ||
This command will not execute anything unless you provide a --steps flag with a value greater than 0. Per default, this | ||
command will roll back one migration at a time. You can specify the number of migrations to roll back using the --steps | ||
flag. | ||
Choosing how many migrations to roll back depends on the current state of the database. Please first execute the command | ||
without the --steps flag to review the migrations and decide which one to roll back. | ||
Once you have decided which migration to roll back, you can use the --steps flag to specify the number of migrations to | ||
roll back. For example, to roll back the most recent migration, you can run: | ||
DSN=... hydra migrate sql down -e --steps 1`, | ||
RunE: cli.NewHandler(slOpts, dOpts, cOpts).Migration.MigrateSQLDown, | ||
} | ||
|
||
cmd.Flags().BoolP("read-from-env", "e", false, "If set, reads the database connection string from the environment variable DSN or config file key dsn.") | ||
cmd.Flags().BoolP("yes", "y", false, "If set all confirmation requests are accepted without user interaction.") | ||
cmd.Flags().Int("steps", 0, "The number of migrations to roll back.") | ||
cmd.Flags().StringSlice("version", []string{}, "One or more migration versions.") | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright © 2022 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ory/hydra/v2/driver" | ||
"github.com/ory/x/configx" | ||
"github.com/ory/x/servicelocatorx" | ||
|
||
"github.com/ory/hydra/v2/cmd/cli" | ||
) | ||
|
||
func NewMigrateSqlUpCmd(slOpts []servicelocatorx.Option, dOpts []driver.OptionsModifier, cOpts []configx.OptionModifier) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "up <database-url>", | ||
Args: cobra.RangeArgs(0, 1), | ||
Short: "Create and upgrade the Ory Hydra SQL schema", | ||
Long: `Run this command on a fresh SQL installation and when you upgrade Ory Hydra to a newer version. | ||
:::warning | ||
Before running this command on an existing database, create a back up. This command can be destructive as it may drop | ||
indices, columns, or whole tables. Run this command close to the SQL instance (same VPC / same machine). | ||
::: | ||
It is recommended to review the migrations before running them. You can do this by running the command without the --yes | ||
flag: | ||
DSN=... hydra migrate sql up -e`, | ||
RunE: cli.NewHandler(slOpts, dOpts, cOpts).Migration.MigrateSQLUp, | ||
} | ||
|
||
cmd.Flags().BoolP("read-from-env", "e", false, "If set, reads the database connection string from the environment variable DSN or config file key dsn.") | ||
cmd.Flags().BoolP("yes", "y", false, "If set all confirmation requests are accepted without user interaction.") | ||
|
||
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
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.