pub struct Config {
pub create_schemas: BTreeSet<Box<str>>,
pub table_name: Option<Box<str>>,
pub migrations_dir: Option<Box<str>>,
pub ignored_chars: BTreeSet<char>,
pub defaults: MigrationDefaults,
}_unstable-docs only.Expand description
Configuration for migrations when executed using sqlx::migrate!() or through sqlx-cli.
ยงNote
A manually constructed Migrator will not be aware of these
configuration options. We recommend using sqlx::migrate!() instead.
ยงWarning: Potential Data Loss or Corruption!
Many of these options, if changed after migrations are set up, can result in data loss or corruption of a production database if the proper precautions are not taken.
Be sure you know what you are doing and that you read all relevant documentation thoroughly.
Fieldsยง
ยงcreate_schemas: BTreeSet<Box<str>>Specify the names of schemas to create if they donโt already exist.
This is done before checking the existence of the migrations table
(_sqlx_migrations or overridden table_name below) so that it may be placed in
one of these schemas.
ยงExample
sqlx.toml:
[migrate]
create-schemas = ["foo"]table_name: Option<Box<str>>Override the name of the table used to track executed migrations.
May be schema-qualified and/or contain quotes. Defaults to _sqlx_migrations.
Potentially useful for multi-tenant databases.
ยงWarning: Potential Data Loss or Corruption!
Changing this option for a production database will likely result in data loss or corruption as the migration machinery will no longer be aware of what migrations have been applied and will attempt to re-run them.
You should create the new table as a copy of the existing migrations table (with contents!), and be sure all instances of your application have been migrated to the new table before deleting the old one.
ยงExample
sqlx.toml:
[migrate]
# Put `_sqlx_migrations` in schema `foo`
table-name = "foo._sqlx_migrations"migrations_dir: Option<Box<str>>Override the directory used for migrations files.
Relative to the crate root for sqlx::migrate!(), or the current directory for sqlx-cli.
ignored_chars: BTreeSet<char>Specify characters that should be ignored when hashing migrations.
Any characters contained in the given array will be dropped when a migration is hashed.
ยงWarning: May Change Hashes for Existing Migrations
Changing the characters considered in hashing migrations will likely change the output of the hash.
This may require manual rectification for deployed databases.
ยงExample: Ignore Carriage Return (<CR> | \r)
Line ending differences between platforms can result in migrations having non-repeatable
hashes. The most common culprit is the carriage return (<CR> | \r), which Windows
uses in its line endings alongside line feed (<LF> | \n), often written CRLF or \r\n,
whereas Linux and macOS use only line feeds.
sqlx.toml:
[migrate]
ignored-chars = ["\r"]For projects using Git, this can also be addressed using .gitattributes:
# Force newlines in migrations to be line feeds on all platforms
migrations/*.sql text eol=lfThis may require resetting or re-checking out the migrations files to take effect.
ยงExample: Ignore all Whitespace Characters
To make your migrations amenable to reformatting, you may wish to tell SQLx to ignore all whitespace characters in migrations.
ยงWarning: Beware Syntactically Significant Whitespace!
If your migrations use string literals or quoted identifiers which contain whitespace, this configuration will cause the migration machinery to ignore some changes to these. This may result in a mismatch between the development and production versions of your database.
sqlx.toml:
[migrate]
# Ignore common whitespace characters when hashing
ignored-chars = [" ", "\t", "\r", "\n"] # Space, tab, CR, LFdefaults: MigrationDefaultsSpecify default options for new migrations created with sqlx migrate add.
Implementationsยง
Sourceยงimpl Config
impl Config
pub fn migrations_dir(&self) -> &str
migrate only.pub fn table_name(&self) -> &str
migrate only.pub fn to_resolve_config(&self) -> ResolveConfig
migrate only.Trait Implementationsยง
Auto Trait Implementationsยง
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
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