use super::{
SqlAddColumnMetadata, SqlCreateIndexMetadata, SqlDropIndexMetadata, SqlForeignKeyMetadata,
SqlNamedConstraint, SqlSettingUse, SqlStatementKind, SqlTableSchemaEvent, SqlUnnamedConstraint,
};
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlCreateTableMetadata {
pub table_name: String,
pub columns: Vec<SqlColumnMetadata>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlColumnMetadata {
pub name: String,
pub type_name: Option<String>,
pub constraints: Vec<String>,
pub is_primary_key: bool,
pub is_generated: bool,
pub generated_expression: Option<String>,
pub generated_function: Option<String>,
pub generated_function_arg_columns: Vec<String>,
pub generated_source_columns: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlDeclaredIdentifier {
pub name: String,
pub line: usize,
}
#[doc(hidden)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct SqlMigrationDefinition {
pub name: Vec<String>,
pub argument_types: Option<Vec<String>>,
}
#[doc(hidden)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SqlMigrationDefinitionEvent {
Create {
definition: SqlMigrationDefinition,
unqualified_index_table: Option<String>,
index_owner: Option<SqlMigrationIndexOwner>,
line: usize,
},
Drop(SqlMigrationDefinition),
DropIndex(Vec<String>),
DropTable {
table: [String; 2],
qualified: bool,
},
DropFunction(Vec<String>),
ResetDefinitions,
ResetFunctions,
ResetIndexes,
TableCreated {
table: [String; 2],
qualified: bool,
},
TableInheritance {
table: [String; 2],
parent: [String; 2],
add: bool,
partition: bool,
qualified: bool,
},
AlterIndexOwner {
table: [String; 2],
effect: SqlMigrationIndexEffect,
qualified: bool,
},
SearchPath {
default: bool,
assignment: bool,
local: bool,
},
TemporaryTable {
name: String,
on_commit_drop: bool,
},
TransactionStart,
TransactionEnd {
chain: bool,
rolled_back: bool,
},
Reset,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlUnanalyzableStatement {
pub line: usize,
pub column: usize,
pub head: String,
pub valid_unsupported: bool,
pub procedural_body: bool,
pub source_order: Vec<usize>,
pub insert_keyword_count: usize,
pub recovered_insert_count: usize,
pub has_top_level_not_exists: bool,
pub schema_unanalyzable: bool,
pub statement_unanalyzable: bool,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct SqlSchemaFileFacts {
pub path: PathBuf,
pub ddl_projection: Option<Box<SqlSchemaFileFacts>>,
pub unanalyzable_statements: Vec<SqlUnanalyzableStatement>,
pub tables: Vec<SqlCreateTableMetadata>,
pub table_events: Vec<SqlTableSchemaEvent>,
pub table_events_collected: bool,
pub indexes: Vec<SqlCreateIndexMetadata>,
pub dropped_indexes: Vec<SqlDropIndexMetadata>,
pub dropped_tables: Vec<SqlDropIndexMetadata>,
pub foreign_keys: Vec<SqlForeignKeyMetadata>,
pub add_columns: Vec<SqlAddColumnMetadata>,
pub unnamed_constraints: Vec<SqlUnnamedConstraint>,
pub single_statement_transactions: Vec<usize>,
pub query_marker_tokens_unavailable: bool,
pub complex_queries: Vec<super::SqlComplexQuery>,
pub unanalyzable_sql_lines: Vec<usize>,
pub catalog_usage: Option<crate::usage::SqlCatalogUsage>,
pub statement_kinds: Vec<SqlStatementKind>,
pub setting_uses: Vec<SqlSettingUse>,
#[doc(hidden)]
pub clause_uses: Vec<super::SqlPolicyClauseUse>,
pub function_calls: Vec<super::super::SqlFunctionCallFact>,
pub not_valid_constraints: Vec<SqlNamedConstraint>,
pub validated_constraints: Vec<SqlNamedConstraint>,
pub declared_identifiers: Vec<SqlDeclaredIdentifier>,
#[doc(hidden)]
pub definition_events: Vec<SqlMigrationDefinitionEvent>,
}
impl SqlSchemaFileFacts {
pub fn ddl_facts(&self) -> &Self {
self.ddl_projection.as_deref().unwrap_or(self)
}
pub fn set_path(&mut self, path: PathBuf) {
if let Some(ddl) = &mut self.ddl_projection {
ddl.set_path(path.clone());
}
self.path = path;
}
}
#[doc(hidden)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlMigrationIndexOwner {
pub table: [String; 2],
pub columns: std::collections::BTreeSet<String>,
}
#[doc(hidden)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SqlMigrationIndexEffect {
DropColumns { names: Vec<String>, only: bool },
RenameColumn { from: String, to: String },
RenameTable([String; 2]),
InvalidateName(String),
}