feat(migrations): try to fix the migrations service
This commit is contained in:
parent
3dcf753ff3
commit
e61db1036e
12
src/db.rs
12
src/db.rs
|
|
@ -7,7 +7,7 @@ use crate::models::{CreateUser, Document, SearchRequest, SearchMode, SearchSnipp
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct Database {
|
||||
pool: PgPool,
|
||||
pub pool: PgPool,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
|
|
@ -365,7 +365,7 @@ impl Database {
|
|||
pub async fn get_documents_by_user(&self, user_id: Uuid, limit: i64, offset: i64) -> Result<Vec<Document>> {
|
||||
let rows = sqlx::query(
|
||||
r#"
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, tags, created_at, updated_at, user_id
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, ocr_confidence, ocr_word_count, ocr_processing_time_ms, ocr_status, tags, created_at, updated_at, user_id
|
||||
FROM documents
|
||||
WHERE user_id = $1
|
||||
ORDER BY created_at DESC
|
||||
|
|
@ -406,7 +406,7 @@ impl Database {
|
|||
pub async fn find_documents_by_filename(&self, filename: &str) -> Result<Vec<Document>> {
|
||||
let rows = sqlx::query(
|
||||
r#"
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, tags, created_at, updated_at, user_id
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, ocr_confidence, ocr_word_count, ocr_processing_time_ms, ocr_status, tags, created_at, updated_at, user_id
|
||||
FROM documents
|
||||
WHERE filename = $1 OR original_filename = $1
|
||||
ORDER BY created_at DESC
|
||||
|
|
@ -444,7 +444,7 @@ impl Database {
|
|||
pub async fn search_documents(&self, user_id: Uuid, search: SearchRequest) -> Result<(Vec<Document>, i64)> {
|
||||
let mut query_builder = sqlx::QueryBuilder::new(
|
||||
r#"
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, tags, created_at, updated_at, user_id,
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, ocr_confidence, ocr_word_count, ocr_processing_time_ms, ocr_status, tags, created_at, updated_at, user_id,
|
||||
ts_rank(to_tsvector('english', COALESCE(content, '') || ' ' || COALESCE(ocr_text, '')), plainto_tsquery('english', "#
|
||||
);
|
||||
|
||||
|
|
@ -536,7 +536,7 @@ impl Database {
|
|||
// Use trigram similarity for substring matching
|
||||
let mut builder = sqlx::QueryBuilder::new(
|
||||
r#"
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, tags, created_at, updated_at, user_id,
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, ocr_confidence, ocr_word_count, ocr_processing_time_ms, ocr_status, tags, created_at, updated_at, user_id,
|
||||
GREATEST(
|
||||
similarity(filename, "#
|
||||
);
|
||||
|
|
@ -575,7 +575,7 @@ impl Database {
|
|||
|
||||
let mut builder = sqlx::QueryBuilder::new(&format!(
|
||||
r#"
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, tags, created_at, updated_at, user_id,
|
||||
SELECT id, filename, original_filename, file_path, file_size, mime_type, content, ocr_text, ocr_confidence, ocr_word_count, ocr_processing_time_ms, ocr_status, tags, created_at, updated_at, user_id,
|
||||
GREATEST(
|
||||
CASE WHEN filename ILIKE '%' || "#
|
||||
));
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ pub mod config;
|
|||
pub mod db;
|
||||
pub mod enhanced_ocr;
|
||||
pub mod file_service;
|
||||
pub mod migrations;
|
||||
pub mod models;
|
||||
pub mod ocr;
|
||||
pub mod ocr_queue;
|
||||
|
|
|
|||
13
src/main.rs
13
src/main.rs
|
|
@ -43,11 +43,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
db.migrate().await?;
|
||||
|
||||
// Run automatic migrations
|
||||
if let Err(e) = readur::migrations::run_startup_migrations(&config.database_url, "migrations").await {
|
||||
error!("Failed to run migrations: {}", e);
|
||||
return Err(e.into());
|
||||
}
|
||||
// Run SQLx migrations
|
||||
sqlx::migrate!("./migrations")
|
||||
.run(&db.pool)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("Failed to run migrations: {}", e);
|
||||
e
|
||||
})?;
|
||||
|
||||
// Seed admin user
|
||||
seed::seed_admin_user(&db).await?;
|
||||
|
|
|
|||
Loading…
Reference in New Issue