storch

Storch is a module to migrate sqlight databases

Types

Migrations with an id and a sql script

pub type Migration {
  Migration(id: Int, up: String)
}

Constructors

  • Migration(id: Int, up: String)

Migration error type

pub type MigrationError {
  DirectoryNotExist(String)
  InvalidMigrationName(String)
  InvalidMigrationId(String)
  TransactionError(sqlight.Error)
  MigrationsTableError(sqlight.Error)
  MigrationScriptError(Int, sqlight.Error)
}

Constructors

  • DirectoryNotExist(String)

    Folder that you gave does not exist

  • InvalidMigrationName(String)

    The migration script file name is not valid

  • InvalidMigrationId(String)

    The migration script file has a non-integer id

  • TransactionError(sqlight.Error)

    Error starting or comitting the migration transaction

  • MigrationsTableError(sqlight.Error)

    Error reading/writing/creating the transactions table

  • MigrationScriptError(Int, sqlight.Error)

    Error applying the migrations script

Functions

pub fn get_migrations(
  in directory: String,
) -> Result(List(Migration), MigrationError)

Get a list of migrations from a folder in the filesystem migration files must end in .sql and start with an integer id followed by an underscore example: 0000001_init.sql

you could store these in the priv directory if you like, that’s probably the best way

pub fn main() -> Nil

Runs the storch cli to generate new migrations and dump the schema run gleam run -m storch to find out more

pub fn migrate(
  migrations: List(Migration),
  on connection: Connection,
) -> Result(Nil, MigrationError)

Pass in a list of migrations and a sqlight connection

Search Document