Oban 2.7 migration issue

Setting up Oban to get an idea of how that works. I followed the instructions on the GitHub - sorentwo/oban: šŸ’Ž Robust job processing in Elixir, backed by modern PostgreSQL page, but Iā€™m running into an error during the migration for the setup

def deps do
  [
    {:oban, "~> 2.7"}
  ]
end

Then run mix deps.get
create a database migration to add the oban_jobs table to your database:

mix ecto.gen.migration add_oban_jobs_table
Open the generated migration in your editor and call the up and down functions on Oban.Migrations:

defmodule MyApp.Repo.Migrations.AddObanJobsTable do
  use Ecto.Migration

  def up do
    Oban.Migrations.up()
  end

  def down do
    Oban.Migrations.down(version: 1)
  end
end

when I run the migration to create the table: mix ecto.migrate

Iā€™m getting the following error

14:23:03.996 [info]  alter table public.oban_jobs
** (Postgrex.Error) ERROR 42601 (syntax_error) syntax error at or near "NOT"

    query: ALTER TABLE "public"."oban_jobs" ADD COLUMN IF NOT EXISTS "attempted_by" text[]
    (ecto_sql 3.6.2) lib/ecto/adapters/sql.ex:760: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir 1.11.4) lib/enum.ex:1411: Enum."-map/2-lists^map/1-0-"/2
    (ecto_sql 3.6.2) lib/ecto/adapters/sql.ex:848: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.6.2) lib/ecto/migration/runner.ex:343: Ecto.Migration.Runner.log_and_execute_ddl/3
    (ecto_sql 3.6.2) lib/ecto/migration/runner.ex:117: anonymous fn/6 in Ecto.Migration.Runner.flush/0
    (elixir 1.11.4) lib/enum.ex:2193: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ecto_sql 3.6.2) lib/ecto/migration/runner.ex:116: Ecto.Migration.Runner.flush/0
    (ecto_sql 3.6.2) lib/ecto/migration/runner.ex:280: Ecto.Migration.Runner.perform_operation/3
    (stdlib 3.12) timer.erl:166: :timer.tc/1
    (ecto_sql 3.6.2) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/8
    (ecto_sql 3.6.2) lib/ecto/migrator.ex:324: Ecto.Migrator.attempt/8
    (ecto_sql 3.6.2) lib/ecto/migrator.ex:250: anonymous fn/5 in Ecto.Migrator.do_up/5
    (ecto_sql 3.6.2) lib/ecto/migrator.ex:295: anonymous fn/6 in Ecto.Migrator.async_migrate_maybe_in_transaction/7
    (ecto_sql 3.6.2) lib/ecto/adapters/sql.ex:1017: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
    (db_connection 2.4.0) lib/db_connection.ex:1512: DBConnection.run_transaction/4
    (ecto_sql 3.6.2) lib/ecto/migrator.ex:313: Ecto.Migrator.run_maybe_in_transaction/4
    (elixir 1.11.4) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (elixir 1.11.4) lib/task/supervised.ex:35: Task.Supervised.reply/5
    (stdlib 3.12) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

Elixir 1.11.4 (compiled with Erlang/OTP 22)
Can someone please help with this ** (Postgrex.Error)

Thanks! :smiley:

What version of postgres are you running? As far as I understand this usage of ALTER TABLE is only allowed in postgres 10 and newer.

2 Likes

when I did check for postgres version , it was 9.5

$ sudo -u postgres psql -c "SELECT version();"
                                                      version                                                      
-------------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.5.25 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609, 64-bit
(1 row)

Now I upgraded to 11 ,
Oban migration up successfully , with the upgraded version :+1:
Thank you @NobbZ :+1:

1 Like