#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Check {
pub description: String,
pub sql: String,
}
impl Check {
pub fn new(description: impl Into<String>, sql: impl Into<String>) -> Self {
Self {
description: description.into(),
sql: sql.into(),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ExecuteStep {
pub description: String,
pub sql: String,
}
impl ExecuteStep {
pub fn new(description: impl Into<String>, sql: impl Into<String>) -> Self {
Self {
description: description.into(),
sql: sql.into(),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Operation {
pub id: String,
pub label: String,
pub precheck: Vec<Check>,
pub execute: Vec<ExecuteStep>,
pub postcheck: Vec<Check>,
pub outside_transaction: bool,
}
#[derive(Clone, Debug, Default)]
pub struct CreateIndexOptions {
pub concurrently: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ColumnDef {
pub name: String,
pub type_sql: String,
pub nullable: bool,
pub default_sql: Option<String>,
}
impl ColumnDef {
pub fn new(name: impl Into<String>, type_sql: impl Into<String>) -> Self {
Self {
name: name.into(),
type_sql: type_sql.into(),
nullable: false,
default_sql: None,
}
}
pub fn nullable(mut self, nullable: bool) -> Self {
self.nullable = nullable;
self
}
pub fn default_sql(mut self, default_sql: impl Into<String>) -> Self {
self.default_sql = Some(default_sql.into());
self
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PrimaryKey {
pub columns: Vec<String>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ReferentialAction {
Cascade,
Restrict,
SetNull,
NoAction,
SetDefault,
}
impl ReferentialAction {
pub fn as_sql(self) -> &'static str {
match self {
ReferentialAction::Cascade => "CASCADE",
ReferentialAction::Restrict => "RESTRICT",
ReferentialAction::SetNull => "SET NULL",
ReferentialAction::NoAction => "NO ACTION",
ReferentialAction::SetDefault => "SET DEFAULT",
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ForeignKeyReference {
pub table: String,
pub columns: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ForeignKeySpec {
pub name: String,
pub columns: Vec<String>,
pub references: ForeignKeyReference,
pub on_delete: Option<ReferentialAction>,
pub on_update: Option<ReferentialAction>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Migration {
pub id: i64,
pub parent_id: Option<i64>,
pub operations: Vec<Operation>,
}
impl Migration {
pub fn new(id: i64, parent_id: Option<i64>, operations: Vec<Operation>) -> Self {
Self {
id,
parent_id,
operations,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DialectCapabilities {
pub enum_types: bool,
pub sequences: bool,
pub materialized_views: bool,
pub extensions: bool,
pub concurrent_indexes: bool,
pub schemas: bool,
pub advisory_locks: bool,
pub add_check_constraints: bool,
pub add_primary_key_constraints: bool,
pub add_unique_constraints: bool,
pub add_foreign_keys: bool,
pub alter_column_default: bool,
pub alter_column_not_null: bool,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ApplyResult {
pub applied: Vec<i64>,
pub skipped_ops: Vec<String>,
}