use super::super::super::{quote_sql_identifier, Catalog, Result};
pub(super) fn migrate(tx: &rusqlite::Connection) -> Result<()> {
tx.execute_batch(super::v06::CREATE_SQL)?;
for table in [
"_named_graphs",
"_graph_vertices",
"_graph_edges",
"_graph_membership",
"_metadata",
] {
for event in ["INSERT", "DELETE", "UPDATE"] {
let name = quote_sql_identifier(&format!("uqa_cache_{table}_{event}"));
tx.execute_batch(&format!("DROP TRIGGER IF EXISTS {name}"))?;
}
}
tx.execute_batch(
"CREATE INDEX IF NOT EXISTS _graph_membership_by_graph \
ON _graph_membership(graph_name, entity_type, entity_id); \
INSERT INTO _cache_revisions(kind, name, generation) \
SELECT 'graph', name, 1 FROM ( \
SELECT name FROM _named_graphs \
UNION SELECT graph_name AS name FROM _graph_membership \
) WHERE true \
ON CONFLICT(kind, name) DO UPDATE SET generation = generation + 1;",
)?;
Catalog::install_cache_revision_tracking(tx)
}