@@ -92,14 +92,24 @@ pub trait Migrate: Query<Vec<Migration>>
9292where
9393 Self : Sized ,
9494{
95+ // Needed cause some database vendors like Mssql have a non sql standard way of checking the migrations table
96+ fn assert_migrations_table_query ( migration_table_name : & str ) -> String {
97+ ASSERT_MIGRATIONS_TABLE_QUERY . replace ( "%MIGRATION_TABLE_NAME%" , migration_table_name)
98+ }
99+
100+ fn get_last_applied_migration_query ( migration_table_name : & str ) -> String {
101+ GET_LAST_APPLIED_MIGRATION_QUERY . replace ( "%MIGRATION_TABLE_NAME%" , migration_table_name)
102+ }
103+
104+ fn get_applied_migrations_query ( migration_table_name : & str ) -> String {
105+ GET_APPLIED_MIGRATIONS_QUERY . replace ( "%MIGRATION_TABLE_NAME%" , migration_table_name)
106+ }
107+
95108 fn assert_migrations_table ( & mut self , migration_table_name : & str ) -> Result < usize , Error > {
96109 // Needed cause some database vendors like Mssql have a non sql standard way of checking the migrations table,
97110 // thou on this case it's just to be consistent with the async trait `AsyncMigrate`
98111 self . execute (
99- [ ASSERT_MIGRATIONS_TABLE_QUERY
100- . replace ( "%MIGRATION_TABLE_NAME%" , migration_table_name)
101- . as_str ( ) ]
102- . into_iter ( ) ,
112+ [ Self :: assert_migrations_table_query ( migration_table_name) . as_str ( ) ] . into_iter ( ) ,
103113 )
104114 . migration_err ( "error asserting migrations table" , None )
105115 }
@@ -109,10 +119,7 @@ where
109119 migration_table_name : & str ,
110120 ) -> Result < Option < Migration > , Error > {
111121 let mut migrations = self
112- . query (
113- & GET_LAST_APPLIED_MIGRATION_QUERY
114- . replace ( "%MIGRATION_TABLE_NAME%" , migration_table_name) ,
115- )
122+ . query ( Self :: get_last_applied_migration_query ( migration_table_name) . as_str ( ) )
116123 . migration_err ( "error getting last applied migration" , None ) ?;
117124
118125 Ok ( migrations. pop ( ) )
@@ -123,10 +130,7 @@ where
123130 migration_table_name : & str ,
124131 ) -> Result < Vec < Migration > , Error > {
125132 let migrations = self
126- . query (
127- & GET_APPLIED_MIGRATIONS_QUERY
128- . replace ( "%MIGRATION_TABLE_NAME%" , migration_table_name) ,
129- )
133+ . query ( Self :: get_applied_migrations_query ( migration_table_name) . as_str ( ) )
130134 . migration_err ( "error getting applied migrations" , None ) ?;
131135
132136 Ok ( migrations)
0 commit comments