Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Created October 3, 2024 17:32
Show Gist options
  • Save sorentwo/d9e14687024e87eb062db4a4abb7b5ee to your computer and use it in GitHub Desktop.
Save sorentwo/d9e14687024e87eb062db4a4abb7b5ee to your computer and use it in GitHub Desktop.
Departition Oban Jobs Table
def up do
execute("LOCK TABLE oban_jobs")
execute("CREATE TABLE oban_jobs_temp AS TABLE oban_jobs")
execute("DROP TABLE oban_jobs CASCADE")
flush()
Oban.Migrations.up()
Oban.Pro.Migrations.Workflow.up()
Oban.Pro.Migrations.Batch.up()
execute("""
INSERT INTO
oban_jobs
SELECT
id,
state,
queue,
worker,
args,
errors,
attempt,
max_attempts,
inserted_at,
scheduled_at,
attempted_at,
completed_at,
attempted_by,
discarded_at,
priority,
tags,
meta,
cancelled_at
FROM oban_jobs_temp
""")
execute("SELECT setval('oban_jobs_id_seq', max(id)) FROM oban_jobs")
execute("DROP TABLE oban_jobs_temp")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment