safe-migrate 0.8.0

Check PostgreSQL migrations against a synchronized database baseline
Documentation
#![allow(clippy::module_inception)]

pub mod config;
pub mod engine;

use squawk_syntax::ast::SourceFile;
use squawk_syntax::ast::Stmt;

/// Represents a parsed SQL migration file.
/// Retained for backward compatibility with CLI wrappers.
pub struct MigrationFile {
    source: SourceFile,
}

impl MigrationFile {
    pub fn parse(sql: &str) -> Result<Self, Vec<String>> {
        let parsed = SourceFile::parse(sql);
        let errors: Vec<String> = parsed.errors().iter().map(|e| e.to_string()).collect();

        if !errors.is_empty() {
            return Err(errors);
        }

        Ok(Self {
            source: parsed.tree(),
        })
    }

    pub fn statements(&self) -> impl Iterator<Item = Stmt> + '_ {
        self.source.stmts()
    }
}