@@ -2,7 +2,6 @@ use super::{transaction::DatabaseTransaction, DatabaseConnectionProvider};
2
2
use crate :: error:: DatabaseError ;
3
3
4
4
use sea_orm:: { Database as SeaOrmDatabase , DatabaseConnection , TransactionTrait } ;
5
- use std:: path:: Path ;
6
5
7
6
/// The [`Database`] struct is responsible for interacting with the database.
8
7
///
@@ -20,39 +19,7 @@ pub struct Database {
20
19
impl Database {
21
20
/// Creates a new [`Database`] instance associated with the provided database URL.
22
21
pub async fn new ( database_url : & str ) -> Result < Self , DatabaseError > {
23
- // Ensure the parent directory exists for file-based databases
24
- if database_url. starts_with ( "sqlite://" ) && !database_url. contains ( ":memory:" ) {
25
- // Extract the file path portion from the URL
26
- let file_path = & database_url[ "sqlite://" . len ( ) ..] ;
27
- if !file_path. is_empty ( ) {
28
- // Create the parent directory if it doesn't exist
29
- if let Some ( parent_dir) = Path :: new ( file_path) . parent ( ) {
30
- if !parent_dir. exists ( ) {
31
- tracing:: info!( target: "scroll::db" , "Creating database directory: {:?}" , parent_dir) ;
32
- std:: fs:: create_dir_all ( parent_dir) . map_err ( |e| {
33
- DatabaseError :: DatabaseError ( sea_orm:: DbErr :: Custom ( format ! (
34
- "Failed to create database directory: {}" ,
35
- e
36
- ) ) )
37
- } ) ?;
38
- }
39
- }
40
- }
41
- }
42
-
43
- // Connect to the database
44
22
let connection = SeaOrmDatabase :: connect ( database_url) . await ?;
45
-
46
- // Run migrations to ensure the schema is up to date
47
- tracing:: info!( target: "scroll::db" , "Running database migrations" ) ;
48
- migration:: Migrator :: up ( & connection, None ) . await . map_err ( |e| {
49
- DatabaseError :: DatabaseError ( sea_orm:: DbErr :: Custom ( format ! (
50
- "Failed to apply database migrations: {}" ,
51
- e
52
- ) ) )
53
- } ) ?;
54
- tracing:: info!( target: "scroll::db" , "Database migrations complete" ) ;
55
-
56
23
Ok ( Self { connection } )
57
24
}
58
25
0 commit comments