Config

Struct Config 

Source
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,
}
Expand description

Configuration for migrations when executed using sqlx::migrate!() or through sqlx-cli.

§Note

A manually constructed [Migrator][crate::migrate::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=lf

This 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, LF
§defaults: MigrationDefaults

Specify default options for new migrations created with sqlx migrate add.

Trait Implementations§

Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Config

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,