use crate::MigrationError;
use scylla::Session;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TableInfo {
pub keyspace: String,
pub table_name: String,
pub columns: Vec<ColumnInfo>,
pub primary_key: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ColumnInfo {
pub name: String,
pub data_type: String,
pub kind: String, }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IndexInfo {
pub name: String,
pub table_name: String,
pub column_name: String,
pub index_type: String,
}
pub struct SchemaIntrospector<'a> {
session: &'a Session,
keyspace: &'a str,
}
impl<'a> SchemaIntrospector<'a> {
pub fn new(session: &'a Session, keyspace: &'a str) -> Self {
Self { session, keyspace }
}
pub async fn get_tables(&self) -> Result<Vec<TableInfo>, MigrationError> {
let query = "SELECT table_name FROM system_schema.tables WHERE keyspace_name = ?";
let rows = self.session.query(query, (self.keyspace,)).await?;
let mut tables = Vec::new();
for row in rows
.rows_typed::<(String,)>()
.map_err(|e| MigrationError::IntegrityError(e.to_string()))?
{
let (table_name,) = row.map_err(|e| MigrationError::IntegrityError(e.to_string()))?;
tables.push(TableInfo {
keyspace: self.keyspace.to_string(),
table_name,
columns: Vec::new(), primary_key: Vec::new(), });
}
Ok(tables)
}
pub async fn get_indexes(&self) -> Result<Vec<IndexInfo>, MigrationError> {
Ok(Vec::new()) }
pub async fn detect_schema_drift(
&self,
_expected_schema: &[TableInfo],
) -> Result<Vec<String>, MigrationError> {
Ok(Vec::new()) }
}