From 05e7f93da200e0e7f2571fee96b4da3dd6bfb419 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 1 Mar 2023 12:01:27 +0100 Subject: [PATCH] Add a migration for native_stats_start_at (#2716) --- ...0301095227_add_native_stats_start_date.exs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 priv/repo/migrations/20230301095227_add_native_stats_start_date.exs diff --git a/priv/repo/migrations/20230301095227_add_native_stats_start_date.exs b/priv/repo/migrations/20230301095227_add_native_stats_start_date.exs new file mode 100644 index 000000000..3eaec68a1 --- /dev/null +++ b/priv/repo/migrations/20230301095227_add_native_stats_start_date.exs @@ -0,0 +1,23 @@ +defmodule Plausible.Repo.Migrations.AddNativeStatsStartDate do + use Ecto.Migration + + def up do + alter table(:sites) do + add :native_stats_start_at, :naive_datetime, null: true + end + + execute """ + UPDATE sites SET native_stats_start_at = inserted_at + """ + + alter table(:sites) do + modify :native_stats_start_at, :naive_datetime, null: false, default: fragment("now()") + end + end + + def down do + alter table(:sites) do + remove :native_stats_start_at + end + end +end