diff --git a/priv/repo/migrations/20240219101411_alter_alert_queries_table_text_field.exs b/priv/repo/migrations/20240219101411_alter_alert_queries_table_text_field.exs new file mode 100644 index 000000000..0f04b9387 --- /dev/null +++ b/priv/repo/migrations/20240219101411_alter_alert_queries_table_text_field.exs @@ -0,0 +1,10 @@ +defmodule Logflare.Repo.Migrations.AlterAlertQueriesTableTextField do + use Ecto.Migration + + def change do + alter table(:alert_queries) do + modify :query, :text, from: :string + modify :description, :text, from: :string + end + end +end diff --git a/test/logflare/alerting_test.exs b/test/logflare/alerting_test.exs index 18e7b1bec..492fbe5c0 100644 --- a/test/logflare/alerting_test.exs +++ b/test/logflare/alerting_test.exs @@ -71,6 +71,23 @@ defmodule Logflare.AlertingTest do assert alert_query.token end + test "bug: create_alert_query/1 with very long query", %{user: user} do + assert {:ok, %AlertQuery{}} = + Alerting.create_alert_query(user, %{ + @valid_attrs + | query: """ + with pg as ( + select round(count(t.id) / 360 ) as rate from `postgres.logs` t + where t.timestamp > timestamp_sub(current_timestamp(), interval 5 minute) + ), cf as ( + select round(count(t.id) / 360 ) as rate from `cloudflare.logs.prod` t + where t.timestamp > timestamp_sub(current_timestamp(), interval 5 minute) + ) + select pg.rate as pg_per_sec, cf.rate as cf_per_sec from pg, cf + """ + }) + end + test "create_alert_query/1 with invalid data returns error changeset", %{user: user} do assert {:error, %Ecto.Changeset{}} = Alerting.create_alert_query(user, @invalid_attrs) # invalid cron