Skip to main content

diesel_migrations/
migration_harness.rs

1use diesel::backend::Backend;
2use diesel::migration::{
3    Migration, MigrationConnection, MigrationSource, MigrationVersion, Result,
4};
5use diesel::prelude::*;
6use diesel::query_builder::QueryFragment;
7use diesel::query_dsl::methods;
8use diesel::serialize::ToSql;
9use diesel::sql_types::{Text, VarChar};
10use std::cell::RefCell;
11use std::collections::HashMap;
12use std::io::Write;
13
14use crate::errors::MigrationError;
15
16#[allow(unused_imports, dead_code, unreachable_pub, unused_qualifications)]
pub mod __diesel_schema_migrations {
    const _: () =
        {
            if !(2u16 <= diesel::internal::table_macro::MAX_COLUMN_COUNT) {
                {
                    ::core::panicking::panic_fmt(format_args!("`__diesel_schema_migrations` contains 2 columns, which is more than the supported maximum number of columns\nTry enabling a crate level feature to support more columns"));
                }
            };
        };
    use ::diesel;
    pub use self::columns::*;
    use diesel::sql_types::*;
    #[doc = "Re-exports all of the columns of this table, as well as the"]
    #[doc = "table struct renamed to the module name. This is meant to be"]
    #[doc = "glob imported for functions which only deal with one table."]
    pub mod dsl {
        pub use super::columns::version;
        pub use super::columns::run_on;
        pub use super::table as __diesel_schema_migrations;
    }
    #[allow(non_upper_case_globals, dead_code)]
    #[doc = "A tuple of all of the columns on thistable"]
    pub const all_columns: AllColumns = (version, run_on);
    #[allow(non_camel_case_types)]
    #[doc = "The actual table struct"]
    #[doc = r""]
    #[doc = r" This is the type which provides the base methods of the query"]
    #[doc = r" builder, such as `.select` and `.filter`."]
    pub struct table;
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::fmt::Debug for table {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::write_str(f, "table")
        }
    }
    #[automatically_derived]
    #[doc(hidden)]
    #[allow(non_camel_case_types)]
    unsafe impl ::core::clone::TrivialClone for table { }
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::clone::Clone for table {
        #[inline]
        fn clone(&self) -> table { *self }
    }
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::marker::Copy for table { }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl diesel::query_builder::QueryId for table {
                type QueryId = table<>;
                const HAS_STATIC_QUERY_ID: bool = true;
                const IS_WINDOW_FUNCTION: bool = false;
            }
        };
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::default::Default for table {
        #[inline]
        fn default() -> table { table {} }
    }
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::marker::StructuralPartialEq for table { }
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::cmp::PartialEq for table {
        #[inline]
        fn eq(&self, other: &table) -> bool { true }
    }
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::cmp::Eq for table {
        #[inline]
        #[doc(hidden)]
        #[coverage(off)]
        fn assert_fields_are_eq(&self) {}
    }
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::cmp::PartialOrd for table {
        #[inline]
        fn partial_cmp(&self, other: &table)
            -> ::core::option::Option<::core::cmp::Ordering> {
            ::core::option::Option::Some(::core::cmp::Ordering::Equal)
        }
    }
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::cmp::Ord for table {
        #[inline]
        fn cmp(&self, other: &table) -> ::core::cmp::Ordering {
            ::core::cmp::Ordering::Equal
        }
    }
    #[automatically_derived]
    #[allow(non_camel_case_types)]
    impl ::core::hash::Hash for table {
        #[inline]
        fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
    }
    impl table {
        #[allow(dead_code)]
        #[doc = "Represents `table_name.*`, which is sometimes necessary"]
        #[doc =
        r" for efficient count queries. It cannot be used in place of"]
        #[doc = r" `all_columns`"]
        pub fn star(&self) -> star { star }
    }
    #[allow(non_camel_case_types, dead_code)]
    #[doc = "The tuple of all column structs on this table"]
    pub type AllColumns = (version, run_on);
    #[doc = "The SQL type of all of the columns on this table"]
    pub type SqlType = <AllColumns as diesel::Expression>::SqlType;
    #[doc = "Helper type for representing a boxed query from this table"]
    pub type BoxedQuery<'a, DB, ST = SqlType> =
        diesel::internal::table_macro::BoxedSelectStatement<'a, ST,
        diesel::internal::table_macro::FromClause<table>, DB>;
    #[doc =
    "Helper type for representing a boxed cloneable query from this table"]
    pub type BoxedCloneQuery<'a, DB, ST = SqlType> =
        diesel::internal::table_macro::BoxedCloneSelectStatement<'a, ST,
        diesel::internal::table_macro::FromClause<table>, DB>;
    impl diesel::QuerySource for table {
        type FromClause =
            diesel::internal::table_macro::StaticQueryFragmentInstance<table>;
        type DefaultSelection =
            <Self as diesel::query_source::QueryRelation>::AllColumns;
        fn from_clause(&self) -> Self::FromClause {
            diesel::internal::table_macro::StaticQueryFragmentInstance::new()
        }
        fn default_selection(&self) -> Self::DefaultSelection {
            <Self as diesel::query_source::QueryRelation>::all_columns()
        }
    }
    impl diesel::internal::table_macro::PlainQuerySource for table {}
    impl<DB> diesel::query_builder::QueryFragment<DB> for table where
        DB: diesel::backend::Backend,
        <Self as
        diesel::internal::table_macro::StaticQueryFragment>::Component: diesel::query_builder::QueryFragment<DB>
        {
        fn walk_ast<'b>(&'b self,
            __diesel_internal_pass:
                diesel::query_builder::AstPass<'_, 'b, DB>)
            -> diesel::result::QueryResult<()> {
            <Self as
                    diesel::internal::table_macro::StaticQueryFragment>::STATIC_COMPONENT.walk_ast(__diesel_internal_pass)
        }
    }
    impl diesel::internal::table_macro::StaticQueryFragment for table {
        type Component = diesel::internal::table_macro::Identifier<'static>;
        const STATIC_COMPONENT: &'static Self::Component =
            &diesel::internal::table_macro::Identifier("__diesel_schema_migrations");
    }
    impl diesel::query_builder::AsQuery for table {
        type SqlType = SqlType;
        type Query =
            diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<Self>>;
        fn as_query(self) -> Self::Query {
            diesel::internal::table_macro::SelectStatement::simple(self)
        }
    }
    impl diesel::Table for table {
        type PrimaryKey = version;
        type AllColumns = AllColumns;
        fn primary_key(&self) -> Self::PrimaryKey { version }
        fn all_columns() -> Self::AllColumns { all_columns }
    }
    impl diesel::associations::HasTable for table {
        type Table = Self;
        fn table() -> Self::Table { table }
    }
    impl diesel::query_builder::IntoUpdateTarget for table {
        type WhereClause =
            <<Self as diesel::query_builder::AsQuery>::Query as
            diesel::query_builder::IntoUpdateTarget>::WhereClause;
        fn into_update_target(self)
            ->
                diesel::query_builder::UpdateTarget<Self::Table,
                Self::WhereClause> {
            use diesel::query_builder::AsQuery;
            let q:
                    diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<table>> =
                self.as_query();
            q.into_update_target()
        }
    }
    impl<T> diesel::insertable::Insertable<T> for table where
        <table as
        diesel::query_builder::AsQuery>::Query: diesel::insertable::Insertable<T>
        {
        type Values =
            <<table as diesel::query_builder::AsQuery>::Query as
            diesel::insertable::Insertable<T>>::Values;
        fn values(self) -> Self::Values {
            use diesel::query_builder::AsQuery;
            self.as_query().values()
        }
    }
    impl<'a, T> diesel::insertable::Insertable<T> for &'a table where
        table: diesel::insertable::Insertable<T> {
        type Values = <table as diesel::insertable::Insertable<T>>::Values;
        fn values(self) -> Self::Values { (*self).values() }
    }
    impl diesel::query_source::AppearsInFromClause<Self> for table {
        type Count = diesel::query_source::Once;
    }
    impl<S> diesel::internal::table_macro::AliasAppearsInFromClause<S, Self>
        for table where S: diesel::query_source::AliasSource<Target = Self> {
        type Count = diesel::query_source::Never;
    }
    impl<S1, S2>
        diesel::internal::table_macro::AliasAliasAppearsInFromClause<Self, S2,
        S1> for table where
        S1: diesel::query_source::AliasSource<Target = Self>,
        S2: diesel::query_source::AliasSource<Target = Self>,
        S1: diesel::internal::table_macro::AliasAliasAppearsInFromClauseSameTable<S2,
        Self> {
        type Count =
            <S1 as
            diesel::internal::table_macro::AliasAliasAppearsInFromClauseSameTable<S2,
            Self>>::Count;
    }
    impl<S>
        diesel::query_source::AppearsInFromClause<diesel::query_source::Alias<S>>
        for table where S: diesel::query_source::AliasSource {
        type Count = diesel::query_source::Never;
    }
    impl<S, C>
        diesel::internal::table_macro::FieldAliasMapperAssociatedTypesDisjointnessTrick<Self,
        S, C> for table where
        S: diesel::query_source::AliasSource<Target = Self> +
        ::core::clone::Clone,
        C: diesel::query_source::QueryRelationField<QueryRelation = Self> {
        type Out = diesel::query_source::AliasedField<S, C>;
        fn map(__diesel_internal_column: C,
            __diesel_internal_alias: &diesel::query_source::Alias<S>)
            -> Self::Out {
            __diesel_internal_alias.field(__diesel_internal_column)
        }
    }
    impl<StmtKind> diesel::query_source::AppearsInFromClause<table> for
        diesel::internal::table_macro::returning::ReturningQuerySource<StmtKind,
        table> {
        type Count = diesel::query_source::Once;
    }
    impl<StmtKind, T>
        diesel::query_source::AppearsInFromClause<diesel::internal::table_macro::returning::ReturningQuerySource<StmtKind,
        T>> for table {
        type Count = diesel::query_source::Never;
    }
    impl diesel::query_source::AppearsInFromClause<table> for
        diesel::internal::table_macro::NoFromClause {
        type Count = diesel::query_source::Never;
    }
    impl<Left, Right, Kind>
        diesel::JoinTo<diesel::internal::table_macro::Join<Left, Right, Kind>>
        for table where
        diesel::internal::table_macro::Join<Left, Right,
        Kind>: diesel::JoinTo<Self>, Left: diesel::query_source::QuerySource,
        Right: diesel::query_source::QuerySource {
        type FromClause =
            diesel::internal::table_macro::Join<Left, Right, Kind>;
        type OnClause =
            <diesel::internal::table_macro::Join<Left, Right, Kind> as
            diesel::JoinTo<Self>>::OnClause;
        fn join_target(__diesel_internal_rhs:
                diesel::internal::table_macro::Join<Left, Right, Kind>)
            -> (Self::FromClause, Self::OnClause) {
            let (_, __diesel_internal_on_clause) =
                diesel::internal::table_macro::Join::join_target(Self);
            (__diesel_internal_rhs, __diesel_internal_on_clause)
        }
    }
    impl<Join, On>
        diesel::JoinTo<diesel::internal::table_macro::JoinOn<Join, On>> for
        table where
        diesel::internal::table_macro::JoinOn<Join, On>: diesel::JoinTo<Self>
        {
        type FromClause = diesel::internal::table_macro::JoinOn<Join, On>;
        type OnClause =
            <diesel::internal::table_macro::JoinOn<Join, On> as
            diesel::JoinTo<Self>>::OnClause;
        fn join_target(__diesel_internal_rhs:
                diesel::internal::table_macro::JoinOn<Join, On>)
            -> (Self::FromClause, Self::OnClause) {
            let (_, __diesel_internal_on_clause) =
                diesel::internal::table_macro::JoinOn::join_target(Self);
            (__diesel_internal_rhs, __diesel_internal_on_clause)
        }
    }
    impl<F, S, D, W, O, L, Of, G>
        diesel::JoinTo<diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<F>,
        S, D, W, O, L, Of, G>> for table where
        diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<F>,
        S, D, W, O, L, Of, G>: diesel::JoinTo<Self>,
        F: diesel::query_source::QuerySource {
        type FromClause =
            diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<F>,
            S, D, W, O, L, Of, G>;
        type OnClause =
            <diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<F>,
            S, D, W, O, L, Of, G> as diesel::JoinTo<Self>>::OnClause;
        fn join_target(__diesel_internal_rhs:
                diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<F>,
                S, D, W, O, L, Of, G>) -> (Self::FromClause, Self::OnClause) {
            let (_, __diesel_internal_on_clause) =
                diesel::internal::table_macro::SelectStatement::join_target(Self);
            (__diesel_internal_rhs, __diesel_internal_on_clause)
        }
    }
    impl<'a, QS, ST, DB>
        diesel::JoinTo<diesel::internal::table_macro::BoxedSelectStatement<'a,
        diesel::internal::table_macro::FromClause<QS>, ST, DB>> for table
        where
        diesel::internal::table_macro::BoxedSelectStatement<'a,
        diesel::internal::table_macro::FromClause<QS>, ST,
        DB>: diesel::JoinTo<Self>, QS: diesel::query_source::QuerySource {
        type FromClause =
            diesel::internal::table_macro::BoxedSelectStatement<'a,
            diesel::internal::table_macro::FromClause<QS>, ST, DB>;
        type OnClause =
            <diesel::internal::table_macro::BoxedSelectStatement<'a,
            diesel::internal::table_macro::FromClause<QS>, ST, DB> as
            diesel::JoinTo<Self>>::OnClause;
        fn join_target(__diesel_internal_rhs:
                diesel::internal::table_macro::BoxedSelectStatement<'a,
                diesel::internal::table_macro::FromClause<QS>, ST, DB>)
            -> (Self::FromClause, Self::OnClause) {
            let (_, __diesel_internal_on_clause) =
                diesel::internal::table_macro::BoxedSelectStatement::join_target(Self);
            (__diesel_internal_rhs, __diesel_internal_on_clause)
        }
    }
    impl<'a, QS, ST, DB>
        diesel::JoinTo<diesel::internal::table_macro::BoxedCloneSelectStatement<'a,
        diesel::internal::table_macro::FromClause<QS>, ST, DB>> for table
        where
        diesel::internal::table_macro::BoxedCloneSelectStatement<'a,
        diesel::internal::table_macro::FromClause<QS>, ST,
        DB>: diesel::JoinTo<Self>, QS: diesel::query_source::QuerySource {
        type FromClause =
            diesel::internal::table_macro::BoxedCloneSelectStatement<'a,
            diesel::internal::table_macro::FromClause<QS>, ST, DB>;
        type OnClause =
            <diesel::internal::table_macro::BoxedCloneSelectStatement<'a,
            diesel::internal::table_macro::FromClause<QS>, ST, DB> as
            diesel::JoinTo<Self>>::OnClause;
        fn join_target(__diesel_internal_rhs:
                diesel::internal::table_macro::BoxedCloneSelectStatement<'a,
                diesel::internal::table_macro::FromClause<QS>, ST, DB>)
            -> (Self::FromClause, Self::OnClause) {
            let (_, __diesel_internal_on_clause) =
                diesel::internal::table_macro::BoxedCloneSelectStatement::join_target(Self);
            (__diesel_internal_rhs, __diesel_internal_on_clause)
        }
    }
    impl<S> diesel::JoinTo<diesel::query_source::Alias<S>> for table where
        diesel::query_source::Alias<S>: diesel::JoinTo<Self> {
        type FromClause = diesel::query_source::Alias<S>;
        type OnClause =
            <diesel::query_source::Alias<S> as
            diesel::JoinTo<Self>>::OnClause;
        fn join_target(__diesel_internal_rhs: diesel::query_source::Alias<S>)
            -> (Self::FromClause, Self::OnClause) {
            let (_, __diesel_internal_on_clause) =
                diesel::query_source::Alias::<S>::join_target(Self);
            (__diesel_internal_rhs, __diesel_internal_on_clause)
        }
    }
    impl<S> diesel::JoinTo<diesel::query_builder::Only<S>> for table where
        diesel::query_builder::Only<S>: diesel::JoinTo<table> {
        type FromClause = diesel::query_builder::Only<S>;
        type OnClause =
            <diesel::query_builder::Only<S> as
            diesel::JoinTo<table>>::OnClause;
        fn join_target(__diesel_internal_rhs: diesel::query_builder::Only<S>)
            -> (Self::FromClause, Self::OnClause) {
            let (_, __diesel_internal_on_clause) =
                diesel::query_builder::Only::<S>::join_target(table);
            (__diesel_internal_rhs, __diesel_internal_on_clause)
        }
    }
    impl diesel::query_source::AppearsInFromClause<diesel::query_builder::Only<table>>
        for table {
        type Count = diesel::query_source::Once;
    }
    impl diesel::query_source::AppearsInFromClause<table> for
        diesel::query_builder::Only<table> {
        type Count = diesel::query_source::Once;
    }
    impl<S, TSM> diesel::JoinTo<diesel::query_builder::Tablesample<S, TSM>>
        for table where
        diesel::query_builder::Tablesample<S, TSM>: diesel::JoinTo<table>,
        TSM: diesel::internal::table_macro::TablesampleMethod {
        type FromClause = diesel::query_builder::Tablesample<S, TSM>;
        type OnClause =
            <diesel::query_builder::Tablesample<S, TSM> as
            diesel::JoinTo<table>>::OnClause;
        fn join_target(__diesel_internal_rhs:
                diesel::query_builder::Tablesample<S, TSM>)
            -> (Self::FromClause, Self::OnClause) {
            let (_, __diesel_internal_on_clause) =
                diesel::query_builder::Tablesample::<S,
                        TSM>::join_target(table);
            (__diesel_internal_rhs, __diesel_internal_on_clause)
        }
    }
    impl<TSM>
        diesel::query_source::AppearsInFromClause<diesel::query_builder::Tablesample<table,
        TSM>> for table where
        TSM: diesel::internal::table_macro::TablesampleMethod {
        type Count = diesel::query_source::Once;
    }
    impl<TSM> diesel::query_source::AppearsInFromClause<table> for
        diesel::query_builder::Tablesample<table, TSM> where
        TSM: diesel::internal::table_macro::TablesampleMethod {
        type Count = diesel::query_source::Once;
    }
    #[doc = "Contains all of the columns of this table"]
    pub mod columns {
        use ::diesel;
        use super::table;
        use diesel::sql_types::*;
        #[allow(non_camel_case_types, dead_code)]
        #[doc = "Represents `table_name.*`, which is sometimes needed for"]
        #[doc = r" efficient count queries. It cannot be used in place of"]
        #[doc = r" `all_columns`, and has a `SqlType` of `()` to prevent it"]
        #[doc = r" being used that way"]
        pub struct star;
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::fmt::Debug for star {
            #[inline]
            fn fmt(&self, f: &mut ::core::fmt::Formatter)
                -> ::core::fmt::Result {
                ::core::fmt::Formatter::write_str(f, "star")
            }
        }
        #[automatically_derived]
        #[doc(hidden)]
        #[allow(non_camel_case_types, dead_code)]
        unsafe impl ::core::clone::TrivialClone for star { }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::clone::Clone for star {
            #[inline]
            fn clone(&self) -> star { *self }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::marker::Copy for star { }
        const _: () =
            {
                use diesel;
                #[allow(non_camel_case_types)]
                impl diesel::query_builder::QueryId for star {
                    type QueryId = star<>;
                    const HAS_STATIC_QUERY_ID: bool = true;
                    const IS_WINDOW_FUNCTION: bool = false;
                }
            };
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::marker::StructuralPartialEq for star { }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::PartialEq for star {
            #[inline]
            fn eq(&self, other: &star) -> bool { true }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::Eq for star {
            #[inline]
            #[doc(hidden)]
            #[coverage(off)]
            fn assert_fields_are_eq(&self) {}
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::PartialOrd for star {
            #[inline]
            fn partial_cmp(&self, other: &star)
                -> ::core::option::Option<::core::cmp::Ordering> {
                ::core::option::Option::Some(::core::cmp::Ordering::Equal)
            }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::Ord for star {
            #[inline]
            fn cmp(&self, other: &star) -> ::core::cmp::Ordering {
                ::core::cmp::Ordering::Equal
            }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::hash::Hash for star {
            #[inline]
            fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
        }
        impl<__GB> diesel::expression::ValidGrouping<__GB> for star where
            super::AllColumns: diesel::expression::ValidGrouping<__GB> {
            type IsAggregate =
                <super::AllColumns as
                diesel::expression::ValidGrouping<__GB>>::IsAggregate;
        }
        impl diesel::Expression for star {
            type SqlType =
                diesel::expression::expression_types::NotSelectable;
        }
        impl<DB: diesel::backend::Backend>
            diesel::query_builder::QueryFragment<DB> for star where
            <table as
            diesel::QuerySource>::FromClause: diesel::query_builder::QueryFragment<DB>
            {
            #[allow(non_snake_case)]
            fn walk_ast<'b>(&'b self,
                mut __diesel_internal_out:
                    diesel::query_builder::AstPass<'_, 'b, DB>)
                -> diesel::result::QueryResult<()> {
                use diesel::QuerySource;
                if !__diesel_internal_out.should_skip_from() {
                    const FROM_CLAUSE:
                        diesel::internal::table_macro::StaticQueryFragmentInstance<table>
                        =
                        diesel::internal::table_macro::StaticQueryFragmentInstance::new();
                    FROM_CLAUSE.walk_ast(__diesel_internal_out.reborrow())?;
                    __diesel_internal_out.push_sql(".");
                }
                __diesel_internal_out.push_sql("*");
                Ok(())
            }
        }
        impl diesel::SelectableExpression<table> for star {}
        impl diesel::AppearsOnTable<table> for star {}
        #[allow(non_camel_case_types, dead_code)]
        pub struct version;
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::fmt::Debug for version {
            #[inline]
            fn fmt(&self, f: &mut ::core::fmt::Formatter)
                -> ::core::fmt::Result {
                ::core::fmt::Formatter::write_str(f, "version")
            }
        }
        #[automatically_derived]
        #[doc(hidden)]
        #[allow(non_camel_case_types, dead_code)]
        unsafe impl ::core::clone::TrivialClone for version { }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::clone::Clone for version {
            #[inline]
            fn clone(&self) -> version { *self }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::marker::Copy for version { }
        const _: () =
            {
                use diesel;
                #[allow(non_camel_case_types)]
                impl diesel::query_builder::QueryId for version {
                    type QueryId = version<>;
                    const HAS_STATIC_QUERY_ID: bool = true;
                    const IS_WINDOW_FUNCTION: bool = false;
                }
            };
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::default::Default for version {
            #[inline]
            fn default() -> version { version {} }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::marker::StructuralPartialEq for version { }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::PartialEq for version {
            #[inline]
            fn eq(&self, other: &version) -> bool { true }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::Eq for version {
            #[inline]
            #[doc(hidden)]
            #[coverage(off)]
            fn assert_fields_are_eq(&self) {}
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::PartialOrd for version {
            #[inline]
            fn partial_cmp(&self, other: &version)
                -> ::core::option::Option<::core::cmp::Ordering> {
                ::core::option::Option::Some(::core::cmp::Ordering::Equal)
            }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::Ord for version {
            #[inline]
            fn cmp(&self, other: &version) -> ::core::cmp::Ordering {
                ::core::cmp::Ordering::Equal
            }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::hash::Hash for version {
            #[inline]
            fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
        }
        impl diesel::expression::Expression for version {
            type SqlType = VarChar;
        }
        impl<DB> diesel::query_builder::QueryFragment<DB> for version where
            DB: diesel::backend::Backend,
            diesel::internal::table_macro::StaticQueryFragmentInstance<table>: diesel::query_builder::QueryFragment<DB>
            {
            #[allow(non_snake_case)]
            fn walk_ast<'b>(&'b self,
                mut __diesel_internal_out:
                    diesel::query_builder::AstPass<'_, 'b, DB>)
                -> diesel::result::QueryResult<()> {
                if !__diesel_internal_out.should_skip_from() {
                    const FROM_CLAUSE:
                        diesel::internal::table_macro::StaticQueryFragmentInstance<table>
                        =
                        diesel::internal::table_macro::StaticQueryFragmentInstance::new();
                    FROM_CLAUSE.walk_ast(__diesel_internal_out.reborrow())?;
                    __diesel_internal_out.push_sql(".");
                }
                __diesel_internal_out.push_identifier("version")
            }
        }
        impl diesel::SelectableExpression<super::table> for version {}
        impl<__StmtKind>
            diesel::SelectableExpression<diesel::internal::table_macro::returning::ReturningQuerySource<__StmtKind,
            super::table>> for version {}
        impl<QS> diesel::AppearsOnTable<QS> for version where
            QS: diesel::query_source::AppearsInFromClause<super::table, Count
            = diesel::query_source::Once> {}
        impl<Left, Right>
            diesel::SelectableExpression<diesel::internal::table_macro::Join<Left,
            Right, diesel::internal::table_macro::LeftOuter>> for version
            where
            version: diesel::AppearsOnTable<diesel::internal::table_macro::Join<Left,
            Right, diesel::internal::table_macro::LeftOuter>>,
            Self: diesel::SelectableExpression<Left>,
            Right: diesel::query_source::AppearsInFromClause<super::table,
            Count = diesel::query_source::Never> +
            diesel::query_source::QuerySource,
            Left: diesel::query_source::QuerySource {}
        impl<Left, Right>
            diesel::SelectableExpression<diesel::internal::table_macro::Join<Left,
            Right, diesel::internal::table_macro::Inner>> for version where
            version: diesel::AppearsOnTable<diesel::internal::table_macro::Join<Left,
            Right, diesel::internal::table_macro::Inner>>,
            Left: diesel::query_source::AppearsInFromClause<super::table> +
            diesel::query_source::QuerySource,
            Right: diesel::query_source::AppearsInFromClause<super::table> +
            diesel::query_source::QuerySource,
            (Left::Count,
            Right::Count): diesel::internal::table_macro::Pick<Left, Right>,
            Self: diesel::SelectableExpression<<(Left::Count, Right::Count) as
            diesel::internal::table_macro::Pick<Left, Right>>::Selection> {}
        impl<Join, On>
            diesel::SelectableExpression<diesel::internal::table_macro::JoinOn<Join,
            On>> for version where
            version: diesel::SelectableExpression<Join> +
            diesel::AppearsOnTable<diesel::internal::table_macro::JoinOn<Join,
            On>> {}
        impl<From>
            diesel::SelectableExpression<diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<From>>>
            for version where From: diesel::query_source::QuerySource,
            version: diesel::SelectableExpression<From> +
            diesel::AppearsOnTable<diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<From>>>
            {}
        impl<__GB> diesel::expression::ValidGrouping<__GB> for version where
            __GB: diesel::expression::IsContainedInGroupBy<version, Output =
            diesel::expression::is_contained_in_group_by::Yes> {
            type IsAggregate = diesel::expression::is_aggregate::Yes;
        }
        impl diesel::expression::ValidGrouping<()> for version {
            type IsAggregate = diesel::expression::is_aggregate::No;
        }
        impl diesel::expression::IsContainedInGroupBy<version> for version {
            type Output = diesel::expression::is_contained_in_group_by::Yes;
        }
        impl<T> diesel::EqAll<T> for version where
            T: diesel::expression::AsExpression<VarChar>,
            diesel::dsl::Eq<version,
            T::Expression>: diesel::Expression<SqlType =
            diesel::sql_types::Bool> {
            type Output = diesel::dsl::Eq<Self, T::Expression>;
            fn eq_all(self, __diesel_internal_rhs: T) -> Self::Output {
                use diesel::expression_methods::ExpressionMethods;
                self.eq(__diesel_internal_rhs)
            }
        }
        impl diesel::query_source::AppearsInFromClause<diesel::query_builder::Only<super::table>>
            for version {
            type Count = diesel::query_source::Once;
        }
        impl diesel::SelectableExpression<diesel::query_builder::Only<super::table>>
            for version {}
        impl<TSM>
            diesel::query_source::AppearsInFromClause<diesel::query_builder::Tablesample<super::table,
            TSM>> for version where
            TSM: diesel::internal::table_macro::TablesampleMethod {
            type Count = diesel::query_source::Once;
        }
        impl<TSM>
            diesel::SelectableExpression<diesel::query_builder::Tablesample<super::table,
            TSM>> for version where
            TSM: diesel::internal::table_macro::TablesampleMethod {}
        impl diesel::query_source::Column for version {
            type Table = super::table;
            const NAME: &'static str = "version";
        }
        #[allow(non_camel_case_types, dead_code)]
        pub struct run_on;
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::fmt::Debug for run_on {
            #[inline]
            fn fmt(&self, f: &mut ::core::fmt::Formatter)
                -> ::core::fmt::Result {
                ::core::fmt::Formatter::write_str(f, "run_on")
            }
        }
        #[automatically_derived]
        #[doc(hidden)]
        #[allow(non_camel_case_types, dead_code)]
        unsafe impl ::core::clone::TrivialClone for run_on { }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::clone::Clone for run_on {
            #[inline]
            fn clone(&self) -> run_on { *self }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::marker::Copy for run_on { }
        const _: () =
            {
                use diesel;
                #[allow(non_camel_case_types)]
                impl diesel::query_builder::QueryId for run_on {
                    type QueryId = run_on<>;
                    const HAS_STATIC_QUERY_ID: bool = true;
                    const IS_WINDOW_FUNCTION: bool = false;
                }
            };
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::default::Default for run_on {
            #[inline]
            fn default() -> run_on { run_on {} }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::marker::StructuralPartialEq for run_on { }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::PartialEq for run_on {
            #[inline]
            fn eq(&self, other: &run_on) -> bool { true }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::Eq for run_on {
            #[inline]
            #[doc(hidden)]
            #[coverage(off)]
            fn assert_fields_are_eq(&self) {}
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::PartialOrd for run_on {
            #[inline]
            fn partial_cmp(&self, other: &run_on)
                -> ::core::option::Option<::core::cmp::Ordering> {
                ::core::option::Option::Some(::core::cmp::Ordering::Equal)
            }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::cmp::Ord for run_on {
            #[inline]
            fn cmp(&self, other: &run_on) -> ::core::cmp::Ordering {
                ::core::cmp::Ordering::Equal
            }
        }
        #[automatically_derived]
        #[allow(non_camel_case_types, dead_code)]
        impl ::core::hash::Hash for run_on {
            #[inline]
            fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
        }
        impl diesel::expression::Expression for run_on {
            type SqlType = Timestamp;
        }
        impl<DB> diesel::query_builder::QueryFragment<DB> for run_on where
            DB: diesel::backend::Backend,
            diesel::internal::table_macro::StaticQueryFragmentInstance<table>: diesel::query_builder::QueryFragment<DB>
            {
            #[allow(non_snake_case)]
            fn walk_ast<'b>(&'b self,
                mut __diesel_internal_out:
                    diesel::query_builder::AstPass<'_, 'b, DB>)
                -> diesel::result::QueryResult<()> {
                if !__diesel_internal_out.should_skip_from() {
                    const FROM_CLAUSE:
                        diesel::internal::table_macro::StaticQueryFragmentInstance<table>
                        =
                        diesel::internal::table_macro::StaticQueryFragmentInstance::new();
                    FROM_CLAUSE.walk_ast(__diesel_internal_out.reborrow())?;
                    __diesel_internal_out.push_sql(".");
                }
                __diesel_internal_out.push_identifier("run_on")
            }
        }
        impl diesel::SelectableExpression<super::table> for run_on {}
        impl<__StmtKind>
            diesel::SelectableExpression<diesel::internal::table_macro::returning::ReturningQuerySource<__StmtKind,
            super::table>> for run_on {}
        impl<QS> diesel::AppearsOnTable<QS> for run_on where
            QS: diesel::query_source::AppearsInFromClause<super::table, Count
            = diesel::query_source::Once> {}
        impl<Left, Right>
            diesel::SelectableExpression<diesel::internal::table_macro::Join<Left,
            Right, diesel::internal::table_macro::LeftOuter>> for run_on where
            run_on: diesel::AppearsOnTable<diesel::internal::table_macro::Join<Left,
            Right, diesel::internal::table_macro::LeftOuter>>,
            Self: diesel::SelectableExpression<Left>,
            Right: diesel::query_source::AppearsInFromClause<super::table,
            Count = diesel::query_source::Never> +
            diesel::query_source::QuerySource,
            Left: diesel::query_source::QuerySource {}
        impl<Left, Right>
            diesel::SelectableExpression<diesel::internal::table_macro::Join<Left,
            Right, diesel::internal::table_macro::Inner>> for run_on where
            run_on: diesel::AppearsOnTable<diesel::internal::table_macro::Join<Left,
            Right, diesel::internal::table_macro::Inner>>,
            Left: diesel::query_source::AppearsInFromClause<super::table> +
            diesel::query_source::QuerySource,
            Right: diesel::query_source::AppearsInFromClause<super::table> +
            diesel::query_source::QuerySource,
            (Left::Count,
            Right::Count): diesel::internal::table_macro::Pick<Left, Right>,
            Self: diesel::SelectableExpression<<(Left::Count, Right::Count) as
            diesel::internal::table_macro::Pick<Left, Right>>::Selection> {}
        impl<Join, On>
            diesel::SelectableExpression<diesel::internal::table_macro::JoinOn<Join,
            On>> for run_on where run_on: diesel::SelectableExpression<Join> +
            diesel::AppearsOnTable<diesel::internal::table_macro::JoinOn<Join,
            On>> {}
        impl<From>
            diesel::SelectableExpression<diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<From>>>
            for run_on where From: diesel::query_source::QuerySource,
            run_on: diesel::SelectableExpression<From> +
            diesel::AppearsOnTable<diesel::internal::table_macro::SelectStatement<diesel::internal::table_macro::FromClause<From>>>
            {}
        impl<__GB> diesel::expression::ValidGrouping<__GB> for run_on where
            __GB: diesel::expression::IsContainedInGroupBy<run_on, Output =
            diesel::expression::is_contained_in_group_by::Yes> {
            type IsAggregate = diesel::expression::is_aggregate::Yes;
        }
        impl diesel::expression::ValidGrouping<()> for run_on {
            type IsAggregate = diesel::expression::is_aggregate::No;
        }
        impl diesel::expression::IsContainedInGroupBy<run_on> for run_on {
            type Output = diesel::expression::is_contained_in_group_by::Yes;
        }
        impl<T> diesel::EqAll<T> for run_on where
            T: diesel::expression::AsExpression<Timestamp>,
            diesel::dsl::Eq<run_on,
            T::Expression>: diesel::Expression<SqlType =
            diesel::sql_types::Bool> {
            type Output = diesel::dsl::Eq<Self, T::Expression>;
            fn eq_all(self, __diesel_internal_rhs: T) -> Self::Output {
                use diesel::expression_methods::ExpressionMethods;
                self.eq(__diesel_internal_rhs)
            }
        }
        impl<Rhs> ::core::ops::Add<Rhs> for run_on where
            Rhs: diesel::expression::AsExpression<<<run_on as
            diesel::Expression>::SqlType as diesel::sql_types::ops::Add>::Rhs>
            {
            type Output =
                diesel::internal::table_macro::ops::Add<Self,
                Rhs::Expression>;
            fn add(self, __diesel_internal_rhs: Rhs) -> Self::Output {
                diesel::internal::table_macro::ops::Add::new(self,
                    __diesel_internal_rhs.as_expression())
            }
        }
        impl<Rhs> ::core::ops::Sub<Rhs> for run_on where
            Rhs: diesel::expression::AsExpression<<<run_on as
            diesel::Expression>::SqlType as diesel::sql_types::ops::Sub>::Rhs>
            {
            type Output =
                diesel::internal::table_macro::ops::Sub<Self,
                Rhs::Expression>;
            fn sub(self, __diesel_internal_rhs: Rhs) -> Self::Output {
                diesel::internal::table_macro::ops::Sub::new(self,
                    __diesel_internal_rhs.as_expression())
            }
        }
        impl diesel::query_source::AppearsInFromClause<diesel::query_builder::Only<super::table>>
            for run_on {
            type Count = diesel::query_source::Once;
        }
        impl diesel::SelectableExpression<diesel::query_builder::Only<super::table>>
            for run_on {}
        impl<TSM>
            diesel::query_source::AppearsInFromClause<diesel::query_builder::Tablesample<super::table,
            TSM>> for run_on where
            TSM: diesel::internal::table_macro::TablesampleMethod {
            type Count = diesel::query_source::Once;
        }
        impl<TSM>
            diesel::SelectableExpression<diesel::query_builder::Tablesample<super::table,
            TSM>> for run_on where
            TSM: diesel::internal::table_macro::TablesampleMethod {}
        impl diesel::query_source::Column for run_on {
            type Table = super::table;
            const NAME: &'static str = "run_on";
        }
        impl diesel::expression::IsContainedInGroupBy<version> for run_on {
            type Output = diesel::expression::is_contained_in_group_by::No;
        }
        impl diesel::expression::IsContainedInGroupBy<run_on> for version {
            type Output = diesel::expression::is_contained_in_group_by::Yes;
        }
    }
}diesel::table! {
17    __diesel_schema_migrations (version) {
18        version -> VarChar,
19        run_on -> Timestamp,
20    }
21}
22
23/// A migration harness is an entity which applies migration to an existing database
24pub trait MigrationHarness<DB: Backend> {
25    /// Checks if the database represented by the current harness has unapplied migrations
26    fn has_pending_migration<S: MigrationSource<DB>>(&mut self, source: S) -> Result<bool> {
27        self.pending_migrations(source).map(|p| !p.is_empty())
28    }
29
30    /// Execute all unapplied migrations for a given migration source
31    fn run_pending_migrations<S: MigrationSource<DB>>(
32        &mut self,
33        source: S,
34    ) -> Result<Vec<MigrationVersion<'_>>> {
35        let pending = self.pending_migrations(source)?;
36        self.run_migrations(&pending)
37    }
38
39    /// Execute all migrations in the given list
40    ///
41    /// This method does not check if a certain migration was already applied or not
42    #[doc(hidden)]
43    fn run_migrations(
44        &mut self,
45        migrations: &[Box<dyn Migration<DB>>],
46    ) -> Result<Vec<MigrationVersion<'_>>> {
47        migrations.iter().map(|m| self.run_migration(m)).collect()
48    }
49
50    /// Execute the next migration from the given migration source
51    fn run_next_migration<S: MigrationSource<DB>>(
52        &mut self,
53        source: S,
54    ) -> Result<MigrationVersion<'_>> {
55        let pending_migrations = self.pending_migrations(source)?;
56        let next_migration = pending_migrations
57            .first()
58            .ok_or(MigrationError::NoMigrationRun)?;
59        self.run_migration(next_migration)
60    }
61
62    /// Revert all applied migrations from a given migration source
63    fn revert_all_migrations<S: MigrationSource<DB>>(
64        &mut self,
65        source: S,
66    ) -> Result<Vec<MigrationVersion<'_>>> {
67        let applied_versions = self.applied_migrations()?;
68        let mut migrations = source
69            .migrations()?
70            .into_iter()
71            .map(|m| (m.name().version().as_owned(), m))
72            .collect::<HashMap<_, _>>();
73
74        applied_versions
75            .into_iter()
76            .map(|version| {
77                let migration_to_revert = migrations
78                    .remove(&version)
79                    .ok_or(MigrationError::UnknownMigrationVersion(version))?;
80                self.revert_migration(&migration_to_revert)
81            })
82            .collect()
83    }
84
85    /// Revert the last migration from a given migration source
86    ///
87    /// This method returns a error if the given migration source does not
88    /// contain the last applied migration
89    fn revert_last_migration<S: MigrationSource<DB>>(
90        &mut self,
91        source: S,
92    ) -> Result<MigrationVersion<'static>> {
93        let applied_versions = self.applied_migrations()?;
94        let migrations = source.migrations()?;
95        let last_migration_version = applied_versions
96            .first()
97            .ok_or(MigrationError::NoMigrationRun)?;
98        let migration_to_revert = migrations
99            .iter()
100            .find(|m| m.name().version() == *last_migration_version)
101            .ok_or_else(|| {
102                MigrationError::UnknownMigrationVersion(last_migration_version.as_owned())
103            })?;
104        self.revert_migration(migration_to_revert)
105    }
106
107    /// Get a list of non applied migrations for a specific migration source
108    ///
109    /// The returned migration list is sorted in ascending order by the individual version
110    /// of each migration
111    fn pending_migrations<S: MigrationSource<DB>>(
112        &mut self,
113        source: S,
114    ) -> Result<Vec<Box<dyn Migration<DB>>>> {
115        let applied_versions = self.applied_migrations()?;
116        let mut migrations = source
117            .migrations()?
118            .into_iter()
119            .map(|m| (m.name().version().as_owned(), m))
120            .collect::<HashMap<_, _>>();
121        for applied_version in applied_versions {
122            migrations.remove(&applied_version);
123        }
124
125        let mut migrations = migrations.into_values().collect::<Vec<_>>();
126
127        migrations.sort_unstable_by(|a, b| a.name().version().cmp(&b.name().version()));
128
129        Ok(migrations)
130    }
131
132    /// Apply a single migration
133    ///
134    /// Types implementing this trait should call [`Migration::run`] internally and record
135    /// that a specific migration version was executed afterwards.
136    ///
137    /// The default implementation wraps the migration in a transaction when the migration
138    /// metadata reports `run_in_transaction = true` (the default). See
139    /// [`FileBasedMigrations`](crate::FileBasedMigrations) to learn how to configure
140    /// this for a specific migration.
141    fn run_migration(&mut self, migration: &dyn Migration<DB>)
142    -> Result<MigrationVersion<'static>>;
143
144    /// Revert a single migration
145    ///
146    /// Types implementing this trait should call [`Migration::revert`] internally
147    /// and record that a specific migration version was reverted afterwards.
148    ///
149    /// The default implementation wraps the revert in a transaction when the migration
150    /// metadata reports `run_in_transaction = true` (the default). See
151    /// [`FileBasedMigrations`](crate::FileBasedMigrations) to learn how to configure
152    /// this for a specific migration.
153    fn revert_migration(
154        &mut self,
155        migration: &dyn Migration<DB>,
156    ) -> Result<MigrationVersion<'static>>;
157
158    /// Get a list of already applied migration versions
159    fn applied_migrations(&mut self) -> Result<Vec<MigrationVersion<'static>>>;
160}
161
162impl<C, DB> MigrationHarness<DB> for C
163where
164    DB: Backend + diesel::internal::migrations::DieselReserveSpecialization,
165    C: Connection<Backend = DB> + MigrationConnection + 'static,
166    __diesel_schema_migrations::table: methods::BoxedDsl<'static, DB, Output = __diesel_schema_migrations::BoxedQuery<'static, DB>>,
167    __diesel_schema_migrations::BoxedQuery<'static, DB, VarChar>:
168        methods::LoadQuery<'static, C, MigrationVersion<'static>>,
169    diesel::internal::migrations::DefaultValues: QueryFragment<DB>,
170    str: ToSql<Text, DB>,
171{
172    fn run_migration(
173        &mut self,
174        migration: &dyn Migration<DB>,
175    ) -> Result<MigrationVersion<'static>> {
176        let saved_search_path = self.read_search_path()?;
177
178        let apply_migration = |conn: &mut C| -> Result<()> {
179            migration.run(conn)?;
180            if let Some(ref path) = saved_search_path {
181                conn.set_search_path(path)?;
182            }
183            diesel::insert_into(__diesel_schema_migrations::table)
184                .values(
185                    __diesel_schema_migrations::version.eq(migration.name().version().as_owned()),
186                )
187                .execute(conn)?;
188            Ok(())
189        };
190
191        if migration.metadata().run_in_transaction() {
192            self.transaction(apply_migration)?;
193        } else {
194            apply_migration(self)?;
195        }
196
197        if let Some(ref path) = saved_search_path {
198            self.set_search_path(path)?;
199        }
200
201        Ok(migration.name().version().as_owned())
202    }
203
204    fn revert_migration(
205        &mut self,
206        migration: &dyn Migration<DB>,
207    ) -> Result<MigrationVersion<'static>> {
208        let saved_search_path = self.read_search_path()?;
209
210        let revert_migration = |conn: &mut C| -> Result<()> {
211            migration.revert(conn)?;
212            if let Some(ref path) = saved_search_path {
213                conn.set_search_path(path)?;
214            }
215            diesel::delete(
216                __diesel_schema_migrations::table.find(migration.name().version().as_owned()),
217            )
218            .execute(conn)?;
219            Ok(())
220        };
221
222        if migration.metadata().run_in_transaction() {
223            self.transaction(revert_migration)?;
224        } else {
225            revert_migration(self)?;
226        }
227
228        if let Some(ref path) = saved_search_path {
229            self.set_search_path(path)?;
230        }
231
232        Ok(migration.name().version().as_owned())
233    }
234
235    fn applied_migrations(&mut self) -> Result<Vec<MigrationVersion<'static>>> {
236        setup_database(self)?;
237        Ok(__diesel_schema_migrations::table
238            .into_boxed()
239            .select(__diesel_schema_migrations::version)
240            .order(__diesel_schema_migrations::version.desc())
241            .load(self)?)
242    }
243}
244
245/// A migration harness that writes messages
246/// into some output for each applied/reverted migration
247pub struct HarnessWithOutput<'a, C, W> {
248    connection: &'a mut C,
249    output: RefCell<W>,
250}
251
252impl<'a, C, W> HarnessWithOutput<'a, C, W> {
253    /// Create a new `HarnessWithOutput` that writes to a specific writer
254    pub fn new<DB>(harness: &'a mut C, output: W) -> Self
255    where
256        C: MigrationHarness<DB>,
257        DB: Backend,
258        W: Write,
259    {
260        Self {
261            connection: harness,
262            output: RefCell::new(output),
263        }
264    }
265}
266
267impl<'a, C> HarnessWithOutput<'a, C, std::io::Stdout> {
268    /// Create a new `HarnessWithOutput` that writes to stdout
269    pub fn write_to_stdout<DB>(harness: &'a mut C) -> Self
270    where
271        C: MigrationHarness<DB>,
272        DB: Backend,
273    {
274        Self {
275            connection: harness,
276            output: RefCell::new(std::io::stdout()),
277        }
278    }
279}
280
281impl<C, W, DB> MigrationHarness<DB> for HarnessWithOutput<'_, C, W>
282where
283    W: Write,
284    C: MigrationHarness<DB>,
285    DB: Backend,
286{
287    fn run_migration(
288        &mut self,
289        migration: &dyn Migration<DB>,
290    ) -> Result<MigrationVersion<'static>> {
291        if migration.name().version() != MigrationVersion::from("00000000000000") {
292            let mut output = self.output.try_borrow_mut()?;
293            output.write_fmt(format_args!("Running migration {0}\n", migration.name()))writeln!(output, "Running migration {}", migration.name())?;
294        }
295        self.connection.run_migration(migration)
296    }
297
298    fn revert_migration(
299        &mut self,
300        migration: &dyn Migration<DB>,
301    ) -> Result<MigrationVersion<'static>> {
302        if migration.name().version() != MigrationVersion::from("00000000000000") {
303            let mut output = self.output.try_borrow_mut()?;
304            output.write_fmt(format_args!("Rolling back migration {0}\n",
        migration.name()))writeln!(output, "Rolling back migration {}", migration.name())?;
305        }
306        self.connection.revert_migration(migration)
307    }
308
309    fn applied_migrations(&mut self) -> Result<Vec<MigrationVersion<'static>>> {
310        self.connection.applied_migrations()
311    }
312}
313
314fn setup_database<Conn: MigrationConnection>(conn: &mut Conn) -> QueryResult<usize> {
315    conn.setup()
316}