Command Reference
This page lists all the commands provided by Iko.
Iko provides a developer-friendly DSL for defining database migrations. These
commands generate deploy
, revert
, and verify
scripts using built-in
templates and follow a consistent pattern.
You can run commands:
- Directly from the command line
- Inside an interactive Iko shell
- From reusable Bash scripts
π For a breakdown of these options, see Running Commands.
π For tips on writing migration scripts, see Scripting.
π Sqitch Commands
Iko wraps and aliases all core Sqitch commands.
For example:
iko deploy
iko revert
iko status
You can also access Sqitch directly:
iko sqitch --version
π§© Ad-Hoc Migrations
add
If your change doesnβt match one of the built-in commands, you can use add
to
create a named migration manually:
add create_customer_view
Youβll be prompted to enter a note, and then edit the deploy/revert/verify SQL files yourself.
Only the deploy script is required. The verify and revert scripts are optional.
More details: sqitch-add docs
add_as
Create a custom migration with inline deploy SQL.
This is useful in scripts when your change isnβt covered by a built-in command
but you want to define the deploy step inline (instead of editing manually like
with add
).
β οΈ
add_as
creates empty verify and revert scripts. So the change won't be verified or reverted (unless you write these manually later).
Syntax:
add_as <change> <<'SQL'
<sql>
SQL
Example:
add_as create_customer_view <<'SQL'
create view customer_view as
select id, name from customer;
SQL
π¨οΈ Comments
comment
Add or update a comment on a Postgres object.
Syntax:
comment <object> <comment>
Example:
comment schema api 'Schema for the API endpoints'
π§© Extensions
create_extension
Install a Postgres extension.
Syntax:
create_extension <extension>
Example:
create_extension pgcrypto
π§ Functions
create_function
Create a function using your editor.
Syntax:
create_function <function>
Example:
create_function create_user
create_function_as
Define a function inline β useful in scripts.
Syntax:
create_function_as <function> <<'SQL'
<sql>
SQL
Example:
create_function_as square <<'SQL'
create function square(n int) returns int as $$
begin
return n * n;
end;
$$ language plpgsql;
SQL
π Grants
grant_execute
Grant execute permission on a function.
Syntax:
grant_execute <function> <signature> <role>
Example:
grant_execute login '(text,text)' dbuser
grant_schema_usage
Grant usage on a schema.
Syntax:
grant_schema_usage <schema> <role>
Example:
grant_schema_usage api dbuser
grant_role_membership
Grant membership in a role.
Syntax:
grant_role_membership <role_specification> <role>
Example:
grant_role_membership authenticator dbuser
grant_table_privilege
Grant privileges on a table.
Syntax:
grant_table_privilege <type> <table> <role>
Example:
grant_table_privilege insert asset dbuser
π€ Roles
create_role
Create a nologin role.
Syntax:
create_role <role>
Example:
create_role dbuser
create_login_role
Create a login role with password.
Syntax:
create_login_role <role> <password>
Example:
create_login_role dbuser 'securepass123'
ποΈ Schemas
create_schema
Syntax:
create_schema <schema>
Example:
create_schema api
π§± Tables
create_table
Create a table using your editor.
Syntax:
create_table <table>
Example:
create_table customer
create_table_as
Define a table inline β ideal for scripts.
Syntax:
create_table_as <table> <<'SQL'
<sql>
SQL
Example:
create_table_as customer <<'SQL'
create table customer (
id bigint generated always as identity primary key,
name text not null,
created_at timestamp not null default now()
);
SQL
π Triggers
create_trigger
Create a trigger linked to a function.
Syntax:
create_trigger <trigger> <table> <function>
Example:
create_trigger customer_updated customer customer_updated
Note: Trigger names cannot be schema-qualified β they inherit the table's schema.
create_trigger_as
Define a trigger inline.
Syntax:
create_trigger_as <trigger> <table> <<'SQL'
<sql>
SQL
Example:
create_trigger_as modify contact <<'SQL'
create trigger modify
after insert or update on contact
for each row execute function modify_record();
SQL
βοΈ Next Steps
π Learn the different ways to run commands
π Or go deeper into writing reusable scripts