From 37d70557c736baf8d19de543384754a29cd5cc9e Mon Sep 17 00:00:00 2001 From: v0idpwn Date: Wed, 22 Nov 2023 04:23:08 -0300 Subject: [PATCH] Add v1 migration for completeness, fix independent migration --- lib/kafkaesque/migrations.ex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/kafkaesque/migrations.ex b/lib/kafkaesque/migrations.ex index dcdb81f..ad30425 100644 --- a/lib/kafkaesque/migrations.ex +++ b/lib/kafkaesque/migrations.ex @@ -17,6 +17,8 @@ defmodule Kafkaesque.Migrations do timestamps() end + + create_if_not_exists(index(:kafkaesque_messages, [:state])) end def down() do @@ -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) @@ -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