glimr/db/migrate

Database Migration Utilities

Provides shared types and functions for database migrations. Used by driver packages to load and filter migrations from the filesystem.

Types

Represents a database migration loaded from a SQL file. Contains the version timestamp, descriptive name, and the raw SQL content to execute.

pub type Migration {
  Migration(version: String, name: String, sql: String)
}

Constructors

  • Migration(version: String, name: String, sql: String)

Values

pub fn extract_sql(sql: String) -> String

Removes SQL comments from migration content. Strips lines starting with – to clean up the SQL before execution. Returns the trimmed SQL content.

pub fn get_pending_migrations(
  all: List(Migration),
  applied: List(String),
) -> List(Migration)

Filters migrations to only those that haven’t been applied. Compares against a list of already-applied version strings and returns only the pending migrations.

pub fn load_all_migrations(
  connection_name: String,
) -> Result(List(Migration), String)

Loads all migration files from the migrations directory. Reads SQL files from src/data/{connection_name}/_migrations, parses version and name from filenames, and returns sorted by version.

Search Document