Skip to content

Commit 3995112

Browse files
committed
Revert "Fix scroll-tech#66: Auto-create database file if it doesn't exist"
This reverts commit cf977c3.
1 parent 97fe452 commit 3995112

File tree

1 file changed

+0
-33
lines changed
  • crates/database/db/src

1 file changed

+0
-33
lines changed

crates/database/db/src/db.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::{transaction::DatabaseTransaction, DatabaseConnectionProvider};
22
use crate::error::DatabaseError;
33

44
use sea_orm::{Database as SeaOrmDatabase, DatabaseConnection, TransactionTrait};
5-
use std::path::Path;
65

76
/// The [`Database`] struct is responsible for interacting with the database.
87
///
@@ -20,39 +19,7 @@ pub struct Database {
2019
impl Database {
2120
/// Creates a new [`Database`] instance associated with the provided database URL.
2221
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
4422
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-
5623
Ok(Self { connection })
5724
}
5825

0 commit comments

Comments
 (0)