Last active
August 14, 2023 21:17
-
-
Save halfdan/6853a8cc8994eca4c9311ecad04a0eb0 to your computer and use it in GitHub Desktop.
Revisions
-
halfdan revised this gist
Apr 28, 2023 . No changes.There are no files selected for viewing
-
halfdan created this gist
Apr 28, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ defmodule SchemaChecker do def find_field_discrepancies do schema_modules() |> Enum.map(fn mod -> {mod.__schema__(:source), check_module(mod)} end) end defp schema_modules do {:ok, modules} = :application.get_key(:core, :modules) modules |> Enum.filter(&({:__schema__, 1} in &1.__info__(:functions))) |> Enum.filter(&(:__meta__ in Map.keys(&1.__schema__(:loaded)))) end defp check_module(module) do fields = module.__schema__(:fields) |> Enum.map(&module.__schema__(:field_source, &1)) |> Enum.map(&Atom.to_string/1) table_name = module.__schema__(:source) {:ok, %{columns: columns}} = DB.Repo.query("SELECT * FROM #{table_name} LIMIT 0") columns -- fields end end SchemaChecker.find_field_discrepancies