use toolu_orm_core::column::ColumnType;
use toolu_orm_core::diff::diff;
use toolu_orm_core::error::DbCoreError;
use toolu_orm_core::fts5::Fts5Table;
use toolu_orm_core::rename::RenameResolver;
use toolu_orm_core::schema::SchemaRegistry;
use toolu_orm_core::snapshot::Snapshot;
use toolu_orm_core::table::TableDef;
pub const NO_INDEXES_REASON: &str = "virtual tables cannot declare indexes";
pub fn memory_fts() -> TableDef {
Fts5Table::new("memory_fts")
.unindexed_column("memory_id", ColumnType::Text)
.column("body", ColumnType::Text)
.tokenize("porter")
.build()
}
pub fn registry(tables: Vec<TableDef>) -> SchemaRegistry {
SchemaRegistry::from_tables(tables)
}
pub fn snapshot_of(tables: Vec<TableDef>) -> Snapshot {
Snapshot::from_registry(®istry(tables))
}
pub fn refusal(old: &Snapshot, new: &SchemaRegistry) -> String {
match diff(old, new) {
Err(DbCoreError::VirtualTableChange { table, reason }) => format!("{table}: {reason}"),
Err(other) => format!("a different error: {other}"),
Ok(ops) => format!("no refusal at all, but {ops:?}"),
}
}
pub struct RenameMemoryFts;
impl RenameResolver for RenameMemoryFts {
fn resolve_tables(&self, added: &[String], removed: &[String]) -> Vec<(String, String)> {
if added.iter().any(|a| a == "note_fts") && removed.iter().any(|r| r == "memory_fts") {
return vec![("memory_fts".to_owned(), "note_fts".to_owned())];
}
vec![]
}
fn resolve_columns(
&self,
_table: &str,
_added: &[String],
_removed: &[String],
) -> Vec<(String, String)> {
vec![]
}
}