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)]
|
#[derive(Clone)]
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
pool: PgPool,
|
pub pool: PgPool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
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>> {
|
pub async fn get_documents_by_user(&self, user_id: Uuid, limit: i64, offset: i64) -> Result<Vec<Document>> {
|
||||||
let rows = sqlx::query(
|
let rows = sqlx::query(
|
||||||
r#"
|
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
|
FROM documents
|
||||||
WHERE user_id = $1
|
WHERE user_id = $1
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
|
|
@ -406,7 +406,7 @@ impl Database {
|
||||||
pub async fn find_documents_by_filename(&self, filename: &str) -> Result<Vec<Document>> {
|
pub async fn find_documents_by_filename(&self, filename: &str) -> Result<Vec<Document>> {
|
||||||
let rows = sqlx::query(
|
let rows = sqlx::query(
|
||||||
r#"
|
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
|
FROM documents
|
||||||
WHERE filename = $1 OR original_filename = $1
|
WHERE filename = $1 OR original_filename = $1
|
||||||
ORDER BY created_at DESC
|
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)> {
|
pub async fn search_documents(&self, user_id: Uuid, search: SearchRequest) -> Result<(Vec<Document>, i64)> {
|
||||||
let mut query_builder = sqlx::QueryBuilder::new(
|
let mut query_builder = sqlx::QueryBuilder::new(
|
||||||
r#"
|
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', "#
|
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
|
// Use trigram similarity for substring matching
|
||||||
let mut builder = sqlx::QueryBuilder::new(
|
let mut builder = sqlx::QueryBuilder::new(
|
||||||
r#"
|
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(
|
GREATEST(
|
||||||
similarity(filename, "#
|
similarity(filename, "#
|
||||||
);
|
);
|
||||||
|
|
@ -575,7 +575,7 @@ impl Database {
|
||||||
|
|
||||||
let mut builder = sqlx::QueryBuilder::new(&format!(
|
let mut builder = sqlx::QueryBuilder::new(&format!(
|
||||||
r#"
|
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(
|
GREATEST(
|
||||||
CASE WHEN filename ILIKE '%' || "#
|
CASE WHEN filename ILIKE '%' || "#
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ pub mod config;
|
||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod enhanced_ocr;
|
pub mod enhanced_ocr;
|
||||||
pub mod file_service;
|
pub mod file_service;
|
||||||
pub mod migrations;
|
|
||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod ocr;
|
pub mod ocr;
|
||||||
pub mod ocr_queue;
|
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?;
|
db.migrate().await?;
|
||||||
|
|
||||||
// Run automatic migrations
|
// Run SQLx migrations
|
||||||
if let Err(e) = readur::migrations::run_startup_migrations(&config.database_url, "migrations").await {
|
sqlx::migrate!("./migrations")
|
||||||
error!("Failed to run migrations: {}", e);
|
.run(&db.pool)
|
||||||
return Err(e.into());
|
.await
|
||||||
}
|
.map_err(|e| {
|
||||||
|
error!("Failed to run migrations: {}", e);
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
// Seed admin user
|
// Seed admin user
|
||||||
seed::seed_admin_user(&db).await?;
|
seed::seed_admin_user(&db).await?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue