diff --git a/Cargo.toml b/Cargo.toml index 43c89c3..ae15888 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/cli.rs b/src/cli.rs index 78b2b0c..cd80d95 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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 @@ -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 @@ -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")] diff --git a/src/macros.rs b/src/macros.rs index 64cd62b..b426b29 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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 /// diff --git a/src/migration.rs b/src/migration.rs index bcd1e6a..c0b8bf3 100644 --- a/src/migration.rs +++ b/src/migration.rs @@ -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 @@ -50,7 +50,7 @@ impl Migration for ExampleMigration { } } ``` -"## +"# )] use std::hash::Hash; @@ -70,7 +70,6 @@ use crate::operation::Operation; /// AsRef` 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: Send + Sync { /// Returns the application name associated with the migration. /// This can be the name of the folder or library where the migration is diff --git a/src/migrator/mod.rs b/src/migrator/mod.rs index 0c3d74b..166446d 100644 --- a/src/migrator/mod.rs +++ b/src/migrator/mod.rs @@ -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 @@ -132,7 +133,7 @@ impl DatabaseOperation for CustomMigrator { } impl Migrate for CustomMigrator {} ``` -"## +"# )] use std::collections::HashMap; @@ -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 { @@ -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 { /// Returns a reference to the list of migrations. fn migrations(&self) -> &Vec>; @@ -303,7 +304,7 @@ pub trait Info { } } -/// 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 @@ -329,7 +330,6 @@ 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 ::Connection, @@ -337,7 +337,6 @@ where ) -> 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 ::Connection, @@ -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: Info + DatabaseOperation + Send + Sync where @@ -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 ::Connection, @@ -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 diff --git a/src/migrator/tests.rs b/src/migrator/tests.rs index 5635abd..f48965e 100644 --- a/src/migrator/tests.rs +++ b/src/migrator/tests.rs @@ -19,7 +19,7 @@ impl CustomMigrator { } } - #[allow(clippy::borrowed_box)] + #[expect(clippy::borrowed_box)] fn add_applied_migration(&mut self, migration: &Box>) { let current_length = self.migrations.len(); self.applied_migrations.push(AppliedMigrationSqlRow::new( diff --git a/src/operation.rs b/src/operation.rs index b701b48..617359b 100644 --- a/src/operation.rs +++ b/src/operation.rs @@ -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 @@ -37,7 +37,7 @@ impl Operation for ExampleOperation { } } ``` -"## +" )] use sqlx::Database; @@ -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: Send + Sync where @@ -66,7 +65,7 @@ where /// apply. async fn up(&self, connection: &mut ::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