Skip to content

Commit 8c8fa78

Browse files
committed
Remove migration that drops source/grch_version from files table
The schema.sql defines these columns and import_from_csv uses them. The migration was causing "table files has no column named source" errors during file imports.
1 parent d19f3fd commit 8c8fa78

1 file changed

Lines changed: 3 additions & 89 deletions

File tree

cli/src/data/db.rs

Lines changed: 3 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -312,95 +312,9 @@ impl BioVaultDb {
312312
}
313313
}
314314

315-
// Drop source and grch_version columns from files table if they exist
316-
// (these should only be in genotype_metadata table)
317-
let source_exists = conn
318-
.query_row(
319-
"SELECT COUNT(*) FROM pragma_table_info('files') WHERE name='source'",
320-
[],
321-
|row| row.get(0),
322-
)
323-
.map(|count: i32| count > 0)
324-
.unwrap_or(false);
325-
326-
let grch_exists = conn
327-
.query_row(
328-
"SELECT COUNT(*) FROM pragma_table_info('files') WHERE name='grch_version'",
329-
[],
330-
|row| row.get(0),
331-
)
332-
.map(|count: i32| count > 0)
333-
.unwrap_or(false);
334-
335-
if source_exists || grch_exists {
336-
info!("Dropping source and grch_version columns from files table");
337-
338-
// SQLite doesn't support DROP COLUMN directly, need to recreate table
339-
conn.execute("BEGIN TRANSACTION", [])?;
340-
341-
// Create new table without source/grch_version
342-
conn.execute(
343-
"CREATE TABLE files_new (
344-
id INTEGER PRIMARY KEY AUTOINCREMENT,
345-
participant_id INTEGER,
346-
file_path TEXT UNIQUE NOT NULL,
347-
file_hash TEXT NOT NULL,
348-
file_type TEXT,
349-
file_size INTEGER,
350-
metadata TEXT,
351-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
352-
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
353-
data_type TEXT DEFAULT 'Unknown',
354-
status TEXT DEFAULT 'complete',
355-
processing_error TEXT,
356-
queue_added_at DATETIME,
357-
FOREIGN KEY (participant_id) REFERENCES participants(id) ON DELETE SET NULL
358-
)",
359-
[],
360-
)?;
361-
362-
// Copy data
363-
conn.execute(
364-
"INSERT INTO files_new (id, participant_id, file_path, file_hash, file_type, file_size,
365-
metadata, created_at, updated_at, data_type, status, processing_error, queue_added_at)
366-
SELECT id, participant_id, file_path, file_hash, file_type, file_size,
367-
metadata, created_at, updated_at, data_type, status, processing_error, queue_added_at
368-
FROM files",
369-
[],
370-
)?;
371-
372-
// Drop old table
373-
conn.execute("DROP TABLE files", [])?;
374-
375-
// Rename new table
376-
conn.execute("ALTER TABLE files_new RENAME TO files", [])?;
377-
378-
// Recreate indexes
379-
conn.execute(
380-
"CREATE INDEX IF NOT EXISTS idx_files_participant_id ON files(participant_id)",
381-
[],
382-
)?;
383-
conn.execute(
384-
"CREATE INDEX IF NOT EXISTS idx_files_file_type ON files(file_type)",
385-
[],
386-
)?;
387-
conn.execute(
388-
"CREATE INDEX IF NOT EXISTS idx_files_hash ON files(file_hash)",
389-
[],
390-
)?;
391-
conn.execute(
392-
"CREATE INDEX IF NOT EXISTS idx_files_data_type ON files(data_type)",
393-
[],
394-
)?;
395-
conn.execute(
396-
"CREATE INDEX IF NOT EXISTS idx_files_status ON files(status)",
397-
[],
398-
)?;
399-
400-
conn.execute("COMMIT", [])?;
401-
402-
info!("Migration complete: removed source and grch_version columns from files table");
403-
}
315+
// NOTE: We keep source and grch_version columns in files table as they are used
316+
// by import_from_csv. The genotype_metadata table provides additional detailed
317+
// metadata (row_count, chromosome_count, inferred_sex) for genotype files.
404318

405319
// Create genotype_metadata table if it doesn't exist
406320
conn.execute(

0 commit comments

Comments
 (0)