degen_sql/db/postgres/models/
migrations_model.rs1use crate::db::postgres::postgres_db::Database;
2
3use super::model::PostgresModelError;
4
5use std::str::FromStr;
6
7pub struct Migration {
8 name: String,
9 executed_at: u64,
10}
11
12pub struct MigrationsModel {}
13
14impl MigrationsModel {
15 pub async fn find(psql_db: &Database) -> Result<Vec<Migration>, PostgresModelError> {
16 let rows = psql_db
17 .query(
18 "
19 SELECT
20 name,
21 executed_at
22 FROM migrations
23
24 ORDER BY executed_at DESC
25 ;
26 ",
27 &[],
28 )
29 .await;
30
31 match rows {
32 Ok(rows) => {
33 let mut migrations = Vec::new();
34
35 for row in rows {
36 let migration = Migration {
37 name: row.get("name"),
38
39 executed_at: row.get::<_, i64>("executed_at") as u64,
41 };
42
43 migrations.push(migration);
44 }
45
46 Ok(migrations)
47 }
48 Err(e) => {
49 eprintln!("Database error: {:?}", e);
50 Err( e.into() )
51 }
52 }
53 }
54}