Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Create migration adding TOTP fields to `users` and recovery codes table (#3535)

Adrian Gruntkowski2512f3cbe263
diff --git a/priv/repo/migrations/20231115140646_add_totp_user_fields_and_recovery_codes.exs b/priv/repo/migrations/20231115140646_add_totp_user_fields_and_recovery_codes.exs
new file mode 100644
index 0000000000..da74ea48d4
--- /dev/null
+++ b/priv/repo/migrations/20231115140646_add_totp_user_fields_and_recovery_codes.exs
@@ -0,0 +1,19 @@
+defmodule Plausible.Repo.Migrations.AddTotpUserFieldsAndRecoveryCodes do
+ use Ecto.Migration
+
+ def change do
+ alter table(:users) do
+ add :totp_secret, :binary
+ add :totp_enabled, :boolean, null: false, default: false
+ add :totp_last_used_at, :naive_datetime
+ end
+
+ create table(:totp_recovery_codes) do
+ add :code_digest, :binary, null: false
+ add :user_id, references(:users, on_delete: :delete_all), null: false
+ timestamps(updated_at: false)
+ end
+
+ create index(:totp_recovery_codes, [:user_id])
+ end
+end