Skip to main content

Writer

Struct Writer 

Source
pub struct Writer { /* private fields */ }
Available on crate feature std only.
Expand description

Low-level writer for creating migration files in V3 folder structure.

V3 format creates a folder per migration:

out/
  20231220143052_initial_schema/
    migration.sql
    snapshot.json
  20231221093015_add_users/
    migration.sql
    snapshot.json

Implementations§

Source§

impl Writer

Source

pub fn new(out: impl Into<PathBuf>, dialect: Dialect) -> Writer

Create a new migration writer with the given settings

Source

pub const fn with_breakpoints(self, enabled: bool) -> Writer

Set whether to use breakpoints in generated SQL

Source

pub const fn with_prefix_mode(self, mode: PrefixMode) -> Writer

Set the prefix mode for migration tags

Source

pub fn with_custom_name(self, name: impl Into<String>) -> Writer

Set a custom name for the next migration

Source

pub fn migrations_dir(&self) -> &Path

Get the migrations directory path

Source

pub const fn dialect(&self) -> Dialect

Get the dialect

Source

pub fn ensure_dirs(&self) -> Result<(), Error>

Ensure the migration directory exists.

§Errors

Returns an error if the migrations directory cannot be created (e.g. insufficient permissions or a conflicting non-directory file exists).

Source

pub fn migration_folder_path(&self, tag: &str) -> PathBuf

Get the path to a migration folder

Source

pub fn migration_sql_path(&self, tag: &str) -> PathBuf

Get the path to a migration SQL file (V3 format: folder/migration.sql)

Source

pub fn snapshot_path(&self, tag: &str) -> PathBuf

Get the path to a snapshot file (V3 format: folder/snapshot.json)

Source

pub fn discover_migrations(&self) -> Result<Vec<String>, Error>

Discover all existing migration folders, sorted by name.

§Errors

Returns an error if the migrations directory cannot be read.

Source

pub fn load_previous_snapshot(&self) -> Result<Snapshot<SqliteEntity>, Error>

Load the previous snapshot by scanning existing migration folders.

§Errors

Returns an error if the migrations directory cannot be read or the found snapshot cannot be parsed.

Source

pub fn write_sqlite_migration( &self, diff: &SchemaDiff, current_snapshot: &Snapshot<SqliteEntity>, ) -> Result<String, MigrationError>

Write a SQLite migration in V3 folder format.

§Errors

Returns MigrationError::NoChanges if the diff produces no statements, or MigrationError::IoError if any filesystem operation fails during migration emission.

Source

pub fn generate_migration_from_snapshots( &self, prev: &Snapshot<SqliteEntity>, cur: &Snapshot<SqliteEntity>, ) -> Result<String, MigrationError>

Generate migration from comparing two snapshots.

§Errors

Returns MigrationError::NoChanges if the snapshots diff is empty, or any error produced by Self::write_sqlite_migration.

Source

pub fn write_custom_migration(&self) -> Result<String, MigrationError>

Write a custom (empty) migration for user SQL.

§Errors

Returns MigrationError::IoError if directory creation or file writes fail while emitting the placeholder migration folder.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AliasExt for T

Source§

fn alias(self, name: &'static str) -> AliasedExpr<Self>

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, 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<Mk> MarkerAggValidFor<()> for Mk

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Scope> ScopeSatisfies<Nil, ()> for Scope

Source§

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

Source§

type Error = !

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> TypeEq<T> for T