Oban.Pro.Migration (Oban Pro v1.5.0-rc.0)
Migrations create and modify the database tables and indexes Oban Pro needs to function.
If you use prefixes, or have multiple instances with different prefixes, you can specify the prefix and create multiple tables in one migration:
Usage
To use migrations in your application you'll need to generate an Ecto.Migration
that wraps
calls to Oban.Pro.Migration
:
mix ecto.gen.migration add_oban_pro
Open the generated migration and delegate the up/0
and down/0
functions to
Oban.Pro.Migration
:
defmodule MyApp.Repo.Migrations.AddObanPro do
use Ecto.Migration
def up, do: Oban.Pro.Migration.up()
def down, do: Oban.Pro.Migration.down()
end
This will run all of the necessary migrations for your database.
Now, run the migration to create the table:
mix ecto.migrate
Upgrading
Like Oban
, migrations are versioned and you may need to run the migration again when new
oban_pro
versions are released. To do this, generate a new migration:
mix ecto.gen.migration upgrade_oban_pro
Open the generated migration in your editor and call the up
and down
functions on
Oban.Pro.Migration
, with an optional version number:
defmodule MyApp.Repo.Migrations.UpgradeObanPro do
use Ecto.Migration
def up, do: Oban.Pro.Migrations.up(version: "1.5.0")
def down, do: Oban.Migrations.down(version: "1.4.0")
end
Differences from Oban
Unlike Oban, the migration versions correspond directly to the
oban_pro
package version. In addition, runningdown/0
will only step back one version, not all the way down.
Isolation with Prefixes
Oban supports namespacing through PostgreSQL schemas, therefore so does Oban Pro. Specify a prefix within your migration:
defmodule MyApp.Repo.Migrations.AddPrefixedObanPro do
use Ecto.Migration
def up, do: Oban.Pro.Migration.up(prefix: "private")
def down, do: Oban.Pro.Migration.down(prefix: "private")
end
Summary
Functions
Run the down
changes for migrations between the current version and the previous version.
Run the up
changes for all migrations between the initial version and the current version.
Functions
down(opts \\ [])
Run the down
changes for migrations between the current version and the previous version.
This behaviour differs from Oban.Migration
by only stepping down one version per
invocation. You must explicitly specify version 1.0.0
to rollback all the way and drop initial
tables.
Example
Run migrations down from the current version to the previous:
Oban.Pro.Migration.down()
Run migrations down to and including a specified version:
Oban.Pro.Migration.down(version: "1.4.0")
Run all down migrations back to the original:
Oban.Pro.Migration.down(version: "1.0.0")
Run migrations in an alternate prefix:
Oban.Pro.Migration.down(prefix: "payments")
up(opts \\ [])
Run the up
changes for all migrations between the initial version and the current version.
Example
Run all migrations up to the current version:
Oban.Pro.Migration.up()
Run migrations up to a specified version:
Oban.Pro.Migration.up(version: "1.4.0")
Run migrations in an alternate prefix:
Oban.Pro.Migration.up(prefix: "payments")