Skip to content

โœจ Scripting Migrations

Ikoโ€™s scripting model lets you define migrations in plain Bash โ€” using the same DSL commands youโ€™d use in CLI or shell mode.


๐Ÿ“ Where Scripts Go

Place your scripts in a scripts/ directory in your project:

myapp/
โ”œโ”€โ”€ migrations/
โ””โ”€โ”€ scripts/
    โ”œโ”€โ”€ auth.sh
    โ””โ”€โ”€ roles.sh

๐Ÿงช Example Script

# scripts/auth.sh

create_schema auth

create_table_as auth.user <<'SQL'
create table auth.user (
  username text primary key,
  password text not null,
  role name not null
);
SQL

create_function_as auth.encrypt_pass <<'SQL'
create function auth.encrypt_pass () returns trigger language plpgsql as $$
begin
  -- hash password before insert/update
  if tg_op = 'INSERT' or new.password <> old.password then
    new.password = crypt(new.password, gen_salt('bf'));
  end if;
  return new;
end; $$
SQL

Run with:

iko bash auth.sh

๐Ÿง  Tips

  • Use <<'SQL' to safely embed SQL blocks
  • Break large scripts into smaller ones per concern (e.g. auth.sh, roles.sh, audit.sh)
  • Scripts are regular Bash: loops, conditionals, and functions all work

๐Ÿงญ What's Next?

๐Ÿ‘‰ See how to deploy migrations to remote environments