sqlx_core_oldapi/any/
migrate.rs1use crate::any::connection::AnyConnectionKind;
2use crate::any::kind::AnyKind;
3use crate::any::{Any, AnyConnection};
4use crate::error::Result;
5use crate::migrate::{AppliedMigration, Migrate, MigrateDatabase, MigrateResult, Migration};
6use futures_core::future::BoxFuture;
7use std::str::FromStr;
8use std::time::Duration;
9
10impl MigrateDatabase for Any {
11 fn create_database(url: &str) -> BoxFuture<'_, Result<()>> {
12 Box::pin(async move {
13 match AnyKind::from_str(url)? {
14 #[cfg(feature = "postgres")]
15 AnyKind::Postgres => crate::postgres::Postgres::create_database(url).await,
16
17 #[cfg(feature = "sqlite")]
18 AnyKind::Sqlite => crate::sqlite::Sqlite::create_database(url).await,
19
20 #[cfg(feature = "mysql")]
21 AnyKind::MySql => crate::mysql::MySql::create_database(url).await,
22
23 #[cfg(feature = "mssql")]
24 AnyKind::Mssql => unimplemented!(),
25 }
26 })
27 }
28
29 fn database_exists(url: &str) -> BoxFuture<'_, Result<bool>> {
30 Box::pin(async move {
31 match AnyKind::from_str(url)? {
32 #[cfg(feature = "postgres")]
33 AnyKind::Postgres => crate::postgres::Postgres::database_exists(url).await,
34
35 #[cfg(feature = "sqlite")]
36 AnyKind::Sqlite => crate::sqlite::Sqlite::database_exists(url).await,
37
38 #[cfg(feature = "mysql")]
39 AnyKind::MySql => crate::mysql::MySql::database_exists(url).await,
40
41 #[cfg(feature = "mssql")]
42 AnyKind::Mssql => unimplemented!(),
43 }
44 })
45 }
46
47 fn drop_database(url: &str) -> BoxFuture<'_, Result<()>> {
48 Box::pin(async move {
49 match AnyKind::from_str(url)? {
50 #[cfg(feature = "postgres")]
51 AnyKind::Postgres => crate::postgres::Postgres::drop_database(url).await,
52
53 #[cfg(feature = "sqlite")]
54 AnyKind::Sqlite => crate::sqlite::Sqlite::drop_database(url).await,
55
56 #[cfg(feature = "mysql")]
57 AnyKind::MySql => crate::mysql::MySql::drop_database(url).await,
58
59 #[cfg(feature = "mssql")]
60 AnyKind::Mssql => unimplemented!(),
61 }
62 })
63 }
64}
65
66impl Migrate for AnyConnection {
67 fn ensure_migrations_table(&mut self) -> BoxFuture<'_, Result<()>> {
68 match &mut self.0 {
69 #[cfg(feature = "postgres")]
70 AnyConnectionKind::Postgres(conn) => conn.ensure_migrations_table(),
71
72 #[cfg(feature = "sqlite")]
73 AnyConnectionKind::Sqlite(conn) => conn.ensure_migrations_table(),
74
75 #[cfg(feature = "mysql")]
76 AnyConnectionKind::MySql(conn) => conn.ensure_migrations_table(),
77
78 #[cfg(feature = "mssql")]
79 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
80 }
81 }
82
83 #[allow(deprecated)]
84 fn version(&mut self) -> BoxFuture<'_, Result<Option<(i64, bool)>>> {
85 match &mut self.0 {
86 #[cfg(feature = "postgres")]
87 AnyConnectionKind::Postgres(conn) => conn.version(),
88
89 #[cfg(feature = "sqlite")]
90 AnyConnectionKind::Sqlite(conn) => conn.version(),
91
92 #[cfg(feature = "mysql")]
93 AnyConnectionKind::MySql(conn) => conn.version(),
94
95 #[cfg(feature = "mssql")]
96 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
97 }
98 }
99
100 fn dirty_version(&mut self) -> BoxFuture<'_, Result<Option<i64>>> {
101 match &mut self.0 {
102 #[cfg(feature = "postgres")]
103 AnyConnectionKind::Postgres(conn) => conn.dirty_version(),
104
105 #[cfg(feature = "sqlite")]
106 AnyConnectionKind::Sqlite(conn) => conn.dirty_version(),
107
108 #[cfg(feature = "mysql")]
109 AnyConnectionKind::MySql(conn) => conn.dirty_version(),
110
111 #[cfg(feature = "mssql")]
112 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
113 }
114 }
115
116 #[allow(deprecated)]
117 fn validate<'e: 'm, 'm>(
118 &'e mut self,
119 migration: &'m Migration,
120 ) -> BoxFuture<'m, MigrateResult<()>> {
121 match &mut self.0 {
122 #[cfg(feature = "postgres")]
123 AnyConnectionKind::Postgres(conn) => conn.validate(migration),
124
125 #[cfg(feature = "sqlite")]
126 AnyConnectionKind::Sqlite(conn) => conn.validate(migration),
127
128 #[cfg(feature = "mysql")]
129 AnyConnectionKind::MySql(conn) => conn.validate(migration),
130
131 #[cfg(feature = "mssql")]
132 AnyConnectionKind::Mssql(_conn) => {
133 let _ = migration;
134 unimplemented!()
135 }
136 }
137 }
138
139 fn list_applied_migrations(&mut self) -> BoxFuture<'_, Result<Vec<AppliedMigration>>> {
140 match &mut self.0 {
141 #[cfg(feature = "postgres")]
142 AnyConnectionKind::Postgres(conn) => conn.list_applied_migrations(),
143
144 #[cfg(feature = "sqlite")]
145 AnyConnectionKind::Sqlite(conn) => conn.list_applied_migrations(),
146
147 #[cfg(feature = "mysql")]
148 AnyConnectionKind::MySql(conn) => conn.list_applied_migrations(),
149
150 #[cfg(feature = "mssql")]
151 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
152 }
153 }
154
155 fn lock(&mut self) -> BoxFuture<'_, Result<()>> {
156 match &mut self.0 {
157 #[cfg(feature = "postgres")]
158 AnyConnectionKind::Postgres(conn) => conn.lock(),
159
160 #[cfg(feature = "sqlite")]
161 AnyConnectionKind::Sqlite(conn) => conn.lock(),
162
163 #[cfg(feature = "mysql")]
164 AnyConnectionKind::MySql(conn) => conn.lock(),
165
166 #[cfg(feature = "mssql")]
167 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
168 }
169 }
170
171 fn unlock(&mut self) -> BoxFuture<'_, Result<()>> {
172 match &mut self.0 {
173 #[cfg(feature = "postgres")]
174 AnyConnectionKind::Postgres(conn) => conn.unlock(),
175
176 #[cfg(feature = "sqlite")]
177 AnyConnectionKind::Sqlite(conn) => conn.unlock(),
178
179 #[cfg(feature = "mysql")]
180 AnyConnectionKind::MySql(conn) => conn.unlock(),
181
182 #[cfg(feature = "mssql")]
183 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
184 }
185 }
186
187 fn apply<'e: 'm, 'm>(
188 &'e mut self,
189 migration: &'m Migration,
190 ) -> BoxFuture<'m, Result<Duration>> {
191 match &mut self.0 {
192 #[cfg(feature = "postgres")]
193 AnyConnectionKind::Postgres(conn) => conn.apply(migration),
194
195 #[cfg(feature = "sqlite")]
196 AnyConnectionKind::Sqlite(conn) => conn.apply(migration),
197
198 #[cfg(feature = "mysql")]
199 AnyConnectionKind::MySql(conn) => conn.apply(migration),
200
201 #[cfg(feature = "mssql")]
202 AnyConnectionKind::Mssql(_conn) => {
203 let _ = migration;
204 unimplemented!()
205 }
206 }
207 }
208
209 fn revert<'e: 'm, 'm>(
210 &'e mut self,
211 migration: &'m Migration,
212 ) -> BoxFuture<'m, Result<Duration>> {
213 match &mut self.0 {
214 #[cfg(feature = "postgres")]
215 AnyConnectionKind::Postgres(conn) => conn.revert(migration),
216
217 #[cfg(feature = "sqlite")]
218 AnyConnectionKind::Sqlite(conn) => conn.revert(migration),
219
220 #[cfg(feature = "mysql")]
221 AnyConnectionKind::MySql(conn) => conn.revert(migration),
222
223 #[cfg(feature = "mssql")]
224 AnyConnectionKind::Mssql(_conn) => {
225 let _ = migration;
226 unimplemented!()
227 }
228 }
229 }
230}