Skip to content

Commit

Permalink
Add v1 migration for completeness, fix independent migration
Browse files Browse the repository at this point in the history
  • Loading branch information
v0idpwn committed Nov 22, 2023
1 parent 28232c8 commit 37d7055
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/kafkaesque/migrations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ defmodule Kafkaesque.Migrations do

timestamps()
end

create_if_not_exists(index(:kafkaesque_messages, [:state]))
end

def down() do
Expand All @@ -25,6 +27,22 @@ defmodule Kafkaesque.Migrations do

def up(current, next)

def up(nil, :v1) do
create table(:kafkaesque_messages, primary_key: false) do
add(:id, :bigserial, primary_key: true)
add(:state, :string, null: false, default: "pending")
add(:topic, :string, null: false)
add(:partition, :integer, null: false)
add(:body, :binary)
add(:attempt, :integer, null: false, default: 0)
add(:attempted_by, :string)
add(:attempted_at, :naive_datetime)
add(:published_at, :naive_datetime)

timestamps()
end
end

def up(:v1, :v2) do
alter table(:kafkaesque_messages) do
add_if_not_exists(:key, :binary, default: "", null: false)
Expand All @@ -46,4 +64,8 @@ defmodule Kafkaesque.Migrations do
remove_if_exists(:key, :binary)
end
end

def down(:v1, nil) do
drop(table(:kafkaesque_messages))
end
end

0 comments on commit 37d7055

Please sign in to comment.