pub struct Writer { /* private fields */ }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.jsonImplementations§
Source§impl Writer
impl Writer
Sourcepub fn new(out: impl Into<PathBuf>, dialect: Dialect) -> Writer
pub fn new(out: impl Into<PathBuf>, dialect: Dialect) -> Writer
Create a new migration writer with the given settings
Sourcepub const fn with_breakpoints(self, enabled: bool) -> Writer
pub const fn with_breakpoints(self, enabled: bool) -> Writer
Set whether to use breakpoints in generated SQL
Sourcepub const fn with_prefix_mode(self, mode: PrefixMode) -> Writer
pub const fn with_prefix_mode(self, mode: PrefixMode) -> Writer
Set the prefix mode for migration tags
Sourcepub fn with_custom_name(self, name: impl Into<String>) -> Writer
pub fn with_custom_name(self, name: impl Into<String>) -> Writer
Set a custom name for the next migration
Sourcepub fn migrations_dir(&self) -> &Path
pub fn migrations_dir(&self) -> &Path
Get the migrations directory path
Sourcepub fn ensure_dirs(&self) -> Result<(), Error>
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).
Sourcepub fn migration_folder_path(&self, tag: &str) -> PathBuf
pub fn migration_folder_path(&self, tag: &str) -> PathBuf
Get the path to a migration folder
Sourcepub fn migration_sql_path(&self, tag: &str) -> PathBuf
pub fn migration_sql_path(&self, tag: &str) -> PathBuf
Get the path to a migration SQL file (V3 format: folder/migration.sql)
Sourcepub fn snapshot_path(&self, tag: &str) -> PathBuf
pub fn snapshot_path(&self, tag: &str) -> PathBuf
Get the path to a snapshot file (V3 format: folder/snapshot.json)
Sourcepub fn discover_migrations(&self) -> Result<Vec<String>, Error>
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.
Sourcepub fn load_previous_snapshot(&self) -> Result<Snapshot<SqliteEntity>, Error>
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.
Sourcepub fn write_sqlite_migration(
&self,
diff: &SchemaDiff,
current_snapshot: &Snapshot<SqliteEntity>,
) -> Result<String, MigrationError>
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.
Sourcepub fn generate_migration_from_snapshots(
&self,
prev: &Snapshot<SqliteEntity>,
cur: &Snapshot<SqliteEntity>,
) -> Result<String, MigrationError>
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.
Sourcepub fn write_custom_migration(&self) -> Result<String, MigrationError>
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.