Skip to content

Commit

Permalink
docs: improve docs by adding links
Browse files Browse the repository at this point in the history
Signed-off-by: Saurav Sharma <[email protected]>
  • Loading branch information
iamsauravsharma committed Dec 12, 2024
1 parent 1c64510 commit 2818475
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["database"]
sqlx = { version = "0.8.0", default-features = false, features = ["macros"] }
async-trait = "0.1.70"
tracing = { version = "0.1.37" }
thiserror = "1.0.41"
thiserror = "2.0.0"
clap = { version = "4.3.10", features = ["derive"], optional = true }
crc32fast = { version = "1.3.2", optional = true }

Expand Down
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct MigrationCommand {
}

impl MigrationCommand {
/// Parse `MigrationCommand` and run migration command line interface
/// Parse [`MigrationCommand`] and run migration command line interface
///
/// # Errors
/// If migration command fails to complete and raise some issue
Expand Down Expand Up @@ -192,7 +192,7 @@ where
}

#[derive(Parser, Debug)]
#[allow(clippy::struct_excessive_bools)]
#[expect(clippy::struct_excessive_bools)]
struct Apply {
/// App name up to which migration needs to be applied. If migration option
/// is also present than only till migration is applied
Expand Down Expand Up @@ -295,7 +295,7 @@ impl Apply {
}

#[derive(Parser, Debug)]
#[allow(clippy::struct_excessive_bools)]
#[expect(clippy::struct_excessive_bools)]
struct Revert {
/// Revert all migration. Conflicts with app args
#[arg(long, conflicts_with = "app")]
Expand Down
3 changes: 2 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ macro_rules! vec_box {
($($x:expr,)*) => (sqlx_migrator::vec_box![$($x),*]);
}

/// Macro for implementing the `Migration` trait for the provided database.
/// Macro for implementing the [Migration](crate::migration::Migration) trait
/// for the provided database.
///
/// This macro will use current file name as name for migration
///
Expand Down
7 changes: 3 additions & 4 deletions src/migration.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Module for defining the `Migration` trait, which represents a database
//! Module for defining the [`Migration`] trait, which represents a database
//! migration.
//!
//! This module provides the necessary abstractions for defining migrations
#![cfg_attr(
feature = "sqlite",
doc = r##"
doc = r#"
To create own implement migration trait for type
### Example
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Migration<Sqlite> for ExampleMigration {
}
}
```
"##
"#
)]

use std::hash::Hash;
Expand All @@ -70,7 +70,6 @@ use crate::operation::Operation;
/// AsRef<str>` where A is the app name and N is the name of the migration. You
/// can use migration in this form in `parents`, `replaces` and `run_before` if
/// you cannot reference migration or create migration easily
#[allow(clippy::module_name_repetitions)]
pub trait Migration<DB>: Send + Sync {
/// Returns the application name associated with the migration.
/// This can be the name of the folder or library where the migration is
Expand Down
39 changes: 18 additions & 21 deletions src/migrator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
//! It contains common enum and trait for implementing migrator for sqlx
//! supported database
//!
//! It also provides its own struct Migrator which supports Any, Postgres,
//! Sqlite and Mysql database
//! It also provides its own struct [`Migrator`] which supports
//! [Any](sqlx::Any), [Postgres](sqlx::Postgres), [Sqlite](sqlx::Sqlite) and
//! [MySql](sqlx::MySql) database
#![cfg_attr(
feature = "postgres",
doc = r##"
doc = r#"
# Example
Create own custom Migrator which only supports postgres and uses own unique
table name instead of default table name
Expand Down Expand Up @@ -132,7 +133,7 @@ impl DatabaseOperation<Postgres> for CustomMigrator {
}
impl Migrate<Postgres> for CustomMigrator {}
```
"##
"#
)]

use std::collections::HashMap;
Expand Down Expand Up @@ -177,7 +178,7 @@ enum PlanType {

/// Struct that determines the type of migration plan to execute.
///
/// A `Plan` can specify whether to apply or revert migrations, and may target
/// A [`Plan`] can specify whether to apply or revert migrations, and may target
/// all migrations, specific migrations, or a limited number of migrations.
#[derive(Debug)]
pub struct Plan {
Expand Down Expand Up @@ -242,8 +243,8 @@ impl Plan {
}
}

/// The `Info` trait provides database-agnostic methods for managing migrations
/// and interacting with migration states.
/// The [`Info`] trait provides database-agnostic methods for managing
/// migrations and interacting with migration states.
pub trait Info<DB> {
/// Returns a reference to the list of migrations.
fn migrations(&self) -> &Vec<BoxMigration<DB>>;
Expand Down Expand Up @@ -303,7 +304,7 @@ pub trait Info<DB> {
}
}

/// The `DatabaseOperation` trait defines a set of methods for performing
/// The [`DatabaseOperation`] trait defines a set of methods for performing
/// operations related to migration management on the database.
///
/// This trait is typically implemented for a database to support migration
Expand All @@ -329,15 +330,13 @@ where
) -> Result<(), Error>;

/// Adds a migration record to the migration table in the database.
#[allow(clippy::borrowed_box)]
async fn add_migration_to_db_table(
&self,
connection: &mut <DB as Database>::Connection,
migration: &BoxMigration<DB>,
) -> Result<(), Error>;

/// Removes a migration record from the migration table in the database.
#[allow(clippy::borrowed_box)]
async fn delete_migration_from_db_table(
&self,
connection: &mut <DB as Database>::Connection,
Expand Down Expand Up @@ -574,13 +573,13 @@ fn get_recursive<'get, DB>(
recursive_vec
}

/// The `Migrate` trait defines methods to manage and apply database migrations
/// according to a given plan.
/// The [`Migrate`] trait defines methods to manage and apply database
/// migrations according to a given plan.
///
/// This trait combines the functionalities of the `Info` and
/// `DatabaseOperation` traits, providing a full set of migration capabilities.
/// All methods have default implementations, meaning no explicit implementation
/// is required. Additionally, all methods are database-agnostic.
/// This trait combines the functionalities of the [`Info`] and
/// [`DatabaseOperation`] traits, providing a full set of migration
/// capabilities. All methods have default implementations, meaning no explicit
/// implementation is required. Additionally, all methods are database-agnostic.
#[async_trait::async_trait]
pub trait Migrate<DB>: Info<DB> + DatabaseOperation<DB> + Send + Sync
where
Expand All @@ -590,7 +589,7 @@ where
///
/// Returns a vector of migration. If plan is none than it will generate
/// plan with all migrations in order of apply
#[allow(clippy::too_many_lines)]
#[expect(clippy::too_many_lines)]
async fn generate_migration_plan(
&self,
connection: &mut <DB as Database>::Connection,
Expand Down Expand Up @@ -699,10 +698,8 @@ where
.all(|run_before_migration| migration_list.contains(run_before_migration))
&& replaces_child_parent_hash_map
.get(migration)
.map_or(true, |replace_migration| {
migration_list.contains(replace_migration)
})
&& replace_children.get(migration).map_or(true, |children| {
.is_none_or(|replace_migration| migration_list.contains(replace_migration))
&& replace_children.get(migration).is_none_or(|children| {
// check if children parents and run before are added or not already before
// adding replace migration. Since replace migration may not depend on
// children parent its need to be added first
Expand Down
2 changes: 1 addition & 1 deletion src/migrator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl CustomMigrator {
}
}

#[allow(clippy::borrowed_box)]
#[expect(clippy::borrowed_box)]
fn add_applied_migration(&mut self, migration: &Box<dyn Migration<Sqlite>>) {
let current_length = self.migrations.len();
self.applied_migrations.push(AppliedMigrationSqlRow::new(
Expand Down
17 changes: 8 additions & 9 deletions src/operation.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Module for defining the `Operation` trait
//! Module for defining the [`Operation`] trait
//!
//! This module provides the `Operation` trait, allowing users to define
//! This module provides the [`Operation`] trait, allowing users to define
//! database operations that can be executed as part of a migration process.
//! These operations can be applied (`up`) or optionally reverted (`down`).
#![cfg_attr(
feature = "sqlite",
doc = r##"
doc = "
To create own operation implement trait for type
### Example
Expand Down Expand Up @@ -37,7 +37,7 @@ impl Operation<Sqlite> for ExampleOperation {
}
}
```
"##
"
)]

use sqlx::Database;
Expand All @@ -50,10 +50,9 @@ use crate::error::Error;
/// database during a migration. Each operation can have an up method for
/// applying the change and an optional down method for rolling it back.
///
/// Operations can also specify whether they are "destructible," meaning that
/// they require user confirmation before being applied, due to potential data
/// loss or irreversible changes
#[allow(clippy::module_name_repetitions)]
/// Operations can also specify whether they are destructible meaning that they
/// require user confirmation before being applied, due to potential data loss
/// or irreversible changes
#[async_trait::async_trait]
pub trait Operation<DB>: Send + Sync
where
Expand All @@ -66,7 +65,7 @@ where
/// apply.
async fn up(&self, connection: &mut <DB as Database>::Connection) -> Result<(), Error>;

/// The `down` method reverses the operation when rolling back the
/// The down method reverses the operation when rolling back the
/// migration.
///
/// This method is called when the migration is being rolled back. Implement
Expand Down

0 comments on commit 2818475

Please sign in to comment.