       where: r.gate_type == "percentage"
     )
 
-    out = @repo.transaction fn() ->
-      table_lock!()
+    out = case db_type() do
+      :postgres -> _put_percentage_postgres(flag_name, gate, find_one_q)
+      :mysql    -> _put_percentage_mysql(flag_name, gate, find_one_q)
+    end
+
+    case out do
+      {:ok, {:ok, result}} ->
+        publish_change(flag_name)
+        {:ok, result}
+      {:error, _} = error ->
+        error
+    end
+  end
+
+
+  def put(flag_name, gate = %Gate{}) do
+    changeset = Record.build(flag_name, gate)
+    options = upsert_options(gate)
+
+    case do_insert(flag_name, changeset, options) do
+      {:ok, flag} ->
+        publish_change(flag_name)
+        {:ok, flag}
+      other ->
+        other
+    end
+  end
+
+
+  defp _put_percentage_postgres(flag_name, gate, find_one_q) do
+    @repo.transaction fn() ->
+      postgres_table_lock!()
       case @repo.one(find_one_q) do
         record = %Record{} ->
           changeset = Record.update_target(record, gate)

  end


  defp table_lock! do
    Ecto.Adapters.SQL.query!(
      @repo,
      "LOCK TABLE fun_with_flags_toggles IN SHARE ROW EXCLUSIVE MODE;"
    )
  end




  import Ecto.Query

  require Logger

  @repo Config.ecto_repo()
  @mysql_lock_timeout_s 3

  def worker_spec do
    nil
