@@ -92,14 +92,24 @@ pub trait Migrate: Query<Vec<Migration>>
92
92
where
93
93
Self : Sized ,
94
94
{
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
+
95
108
fn assert_migrations_table ( & mut self , migration_table_name : & str ) -> Result < usize , Error > {
96
109
// Needed cause some database vendors like Mssql have a non sql standard way of checking the migrations table,
97
110
// thou on this case it's just to be consistent with the async trait `AsyncMigrate`
98
111
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 ( ) ,
103
113
)
104
114
. migration_err ( "error asserting migrations table" , None )
105
115
}
@@ -109,10 +119,7 @@ where
109
119
migration_table_name : & str ,
110
120
) -> Result < Option < Migration > , Error > {
111
121
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 ( ) )
116
123
. migration_err ( "error getting last applied migration" , None ) ?;
117
124
118
125
Ok ( migrations. pop ( ) )
@@ -123,10 +130,7 @@ where
123
130
migration_table_name : & str ,
124
131
) -> Result < Vec < Migration > , Error > {
125
132
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 ( ) )
130
134
. migration_err ( "error getting applied migrations" , None ) ?;
131
135
132
136
Ok ( migrations)
0 commit comments