Skip to main content

safe_migrate/engine/
mod.rs

1#![allow(clippy::module_inception)]
2
3pub mod config;
4pub mod engine;
5
6use squawk_syntax::ast::SourceFile;
7use squawk_syntax::ast::Stmt;
8
9/// Represents a parsed SQL migration file.
10/// Retained for backward compatibility with CLI wrappers.
11pub struct MigrationFile {
12    source: SourceFile,
13}
14
15impl MigrationFile {
16    pub fn parse(sql: &str) -> Result<Self, Vec<String>> {
17        let parsed = SourceFile::parse(sql);
18        let errors: Vec<String> = parsed.errors().iter().map(|e| e.to_string()).collect();
19
20        if !errors.is_empty() {
21            return Err(errors);
22        }
23
24        Ok(Self {
25            source: parsed.tree(),
26        })
27    }
28
29    pub fn statements(&self) -> impl Iterator<Item = Stmt> + '_ {
30        self.source.stmts()
31    }
32}