pub enum MigrateCommand {
Add(AddMigrationOpts),
Run {
source: MigrationSourceOpt,
config: ConfigOpt,
dry_run: bool,
ignore_missing: IgnoreMissing,
connect_opts: ConnectOpts,
target_version: Option<i64>,
},
Revert {
source: MigrationSourceOpt,
config: ConfigOpt,
dry_run: bool,
ignore_missing: IgnoreMissing,
connect_opts: ConnectOpts,
target_version: Option<i64>,
},
Info {
source: MigrationSourceOpt,
config: ConfigOpt,
connect_opts: ConnectOpts,
},
BuildScript {
source: MigrationSourceOpt,
config: ConfigOpt,
force: bool,
},
}Variants§
Add(AddMigrationOpts)
Create a new migration with the given description.
Migrations may either be simple, or reversible.
Reversible migrations can be reverted with sqlx migrate revert, simple migrations cannot.
Reversible migrations are created as a pair of two files with the same filename but
extensions .up.sql and .down.sql for the up-migration and down-migration, respectively.
The up-migration should contain the commands to be used when applying the migration, while the down-migration should contain the commands to reverse the changes made by the up-migration.
When writing down-migrations, care should be taken to ensure that they do not leave the database in an inconsistent state.
Simple migrations have just .sql for their extension and represent an up-migration only.
Note that reverting a migration is destructive and will likely result in data loss. Reverting a migration will not restore any data discarded by commands in the up-migration.
It is recommended to always back up the database before running migrations.
For convenience, this command attempts to detect if reversible migrations are in-use.
If the latest existing migration is reversible, the new migration will also be reversible.
Otherwise, a simple migration is created.
This behavior can be overridden by --simple or --reversible, respectively.
The default type to use can also be set in sqlx.toml.
A version number will be automatically assigned to the migration.
Migrations are applied in ascending order by version number. Version numbers do not need to be strictly consecutive.
The migration process will abort if SQLx encounters a migration with a version number less than any previously applied migration.
Migrations should only be created with increasing version number.
For convenience, this command will attempt to detect if sequential versioning is in use, and if so, continue the sequence.
Sequential versioning is inferred if:
-
The version numbers of the last two migrations differ by exactly 1, or:
-
only one migration exists and its version number is either 0 or 1.
Otherwise, timestamp versioning (YYYYMMDDHHMMSS) is assumed.
This behavior can be overridden by --timestamp or --sequential, respectively.
The default versioning to use can also be set in sqlx.toml.
Run
Run all pending migrations.
Revert
Revert the latest migration with a down file.
Info
List all available migrations.
BuildScript
Generate a build.rs to trigger recompilation when a new migration is added.
Must be run in a Cargo project root.
Trait Implementations§
Source§impl CommandFactory for MigrateCommand
impl CommandFactory for MigrateCommand
Source§impl Debug for MigrateCommand
impl Debug for MigrateCommand
Source§impl FromArgMatches for MigrateCommand
impl FromArgMatches for MigrateCommand
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§fn update_from_arg_matches_mut<'b>(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut<'b>( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§impl Parser for MigrateCommand
impl Parser for MigrateCommand
Source§fn parse_from<I, T>(itr: I) -> Self
fn parse_from<I, T>(itr: I) -> Self
Source§fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
Source§fn update_from<I, T>(&mut self, itr: I)
fn update_from<I, T>(&mut self, itr: I)
Source§impl Subcommand for MigrateCommand
impl Subcommand for MigrateCommand
Source§fn augment_subcommands<'b>(__clap_app: Command) -> Command
fn augment_subcommands<'b>(__clap_app: Command) -> Command
Source§fn augment_subcommands_for_update<'b>(__clap_app: Command) -> Command
fn augment_subcommands_for_update<'b>(__clap_app: Command) -> Command
Command so it can instantiate self via
FromArgMatches::update_from_arg_matches_mut Read moreSource§fn has_subcommand(__clap_name: &str) -> bool
fn has_subcommand(__clap_name: &str) -> bool
Self can parse a specific subcommandAuto Trait Implementations§
impl Freeze for MigrateCommand
impl RefUnwindSafe for MigrateCommand
impl Send for MigrateCommand
impl Sync for MigrateCommand
impl Unpin for MigrateCommand
impl UnwindSafe for MigrateCommand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more