From 0f057dfc3fe5686aa3aede68296e5713435959c5 Mon Sep 17 00:00:00 2001 From: Josh Lee Date: Thu, 16 Nov 2023 17:18:48 -0500 Subject: [PATCH] Add help text for float feature flags; Make upgrades possible for postgres --- .../templates/feature_flag/form.html.heex | 3 ++- .../20220524172636_create_featureflags.exs | 16 +++++++++------- ...31104172636_update_featureflags_use_float.exs | 7 +++++++ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 src/featureflagservice/priv/repo/migrations/20231104172636_update_featureflags_use_float.exs diff --git a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex index 0c8030069c..c01310f22c 100644 --- a/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex +++ b/src/featureflagservice/lib/featureflagservice_web/templates/feature_flag/form.html.heex @@ -30,7 +30,8 @@ <%= error_tag f, :description %> <%= label f, :enabled %> - <%= text_input f, :enabled %> + <%= number_input f, :enabled, min: 0, max: 1, step: 0.1, "aria-describedby": "enabled_help_text" %> +

A value between 0.0 and 1.0. 0.0 is always disabled, 1.0 is always enabled, and all values between set a percentage chance on each request.

<%= error_tag f, :enabled %> <%= submit "Save" %> diff --git a/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs b/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs index 47aeb2c391..9462edebb6 100644 --- a/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs +++ b/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs @@ -1,5 +1,3 @@ - - defmodule Featureflagservice.Repo.Migrations.CreateFeatureflags do use Ecto.Migration @@ -7,7 +5,7 @@ defmodule Featureflagservice.Repo.Migrations.CreateFeatureflags do create table(:featureflags) do add :name, :string add :description, :string - add :enabled, :float, default: 0, null: false + add :enabled, :boolean, default: false, null: false timestamps() end @@ -21,22 +19,26 @@ defmodule Featureflagservice.Repo.Migrations.CreateFeatureflags do repo().insert(%Featureflagservice.FeatureFlags.FeatureFlag{ name: "productCatalogFailure", description: "Fail product catalog service on a specific product", - enabled: 0.0}) + enabled: false + }) repo().insert(%Featureflagservice.FeatureFlags.FeatureFlag{ name: "recommendationCache", description: "Cache recommendations", - enabled: 0.0}) + enabled: false + }) repo().insert(%Featureflagservice.FeatureFlags.FeatureFlag{ name: "adServiceFailure", description: "Fail ad service requests sporadically", - enabled: 0.0}) + enabled: false + }) repo().insert(%Featureflagservice.FeatureFlags.FeatureFlag{ name: "cartServiceFailure", description: "Fail cart service requests sporadically", - enabled: 0.0}) + enabled: false + }) end defp execute_down do diff --git a/src/featureflagservice/priv/repo/migrations/20231104172636_update_featureflags_use_float.exs b/src/featureflagservice/priv/repo/migrations/20231104172636_update_featureflags_use_float.exs new file mode 100644 index 0000000000..117cff788b --- /dev/null +++ b/src/featureflagservice/priv/repo/migrations/20231104172636_update_featureflags_use_float.exs @@ -0,0 +1,7 @@ +defmodule Featureflagservice.Repo.Migrations.UpdateFeatureFlagsUseFloat do + use Ecto.Migration + + def change do + "alter table featureflags alter enabled DROP DEFAULT,alter table featureflags alter enabled type numeric(2,1) using (case when enabled then 1.0 else 0.0 end), alter enabled set default '0.0';" + end +end