โจ 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