diff --git a/.tool-versions b/.tool-versions index 3d664e3..607df04 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -elixir 1.19.5-otp-28 -erlang 28.3.1 +elixir 1.20.3-otp-29 +erlang 29.0.5 diff --git a/lib/yacto/migration/file.ex b/lib/yacto/migration/file.ex index 713a6f0..99cc030 100644 --- a/lib/yacto/migration/file.ex +++ b/lib/yacto/migration/file.ex @@ -216,6 +216,7 @@ defmodule Yacto.Migration.File do {:ok, module()} | {:error, any()} def load_migration_module(migration_dir, %__MODULE__{} = migration_file) do path = Path.join(migration_dir, migration_file.path) + unload_module_if_loaded(migration_module_name(migration_file)) modules = Code.compile_file(path) @@ -236,6 +237,17 @@ defmodule Yacto.Migration.File do end end + defp migration_module_name(%__MODULE__{} = migration_file) do + Module.concat([migration_file.schema_name, "Migration#{pad4(migration_file.version)}"]) + end + + defp unload_module_if_loaded(mod) do + if Code.ensure_loaded?(mod) do + :code.purge(mod) + :code.delete(mod) + end + end + def new(schema_name, version, dbname, operation, now) when is_binary(schema_name) do datetime_str = now diff --git a/lib/yacto/migration/gen_migration.ex b/lib/yacto/migration/gen_migration.ex index d7cb7b3..cf27290 100644 --- a/lib/yacto/migration/gen_migration.ex +++ b/lib/yacto/migration/gen_migration.ex @@ -1,6 +1,4 @@ defmodule Yacto.Migration.GenMigration do - require Logger - defp convert_fields(types, attrs) do # types: # %{del: %{field: type}, diff --git a/lib/yacto/migration/migrator.ex b/lib/yacto/migration/migrator.ex index 6e0a69f..dd0f875 100644 --- a/lib/yacto/migration/migrator.ex +++ b/lib/yacto/migration/migrator.ex @@ -32,6 +32,7 @@ defmodule Yacto.Migration.Migrator do if repo in repos do config = repo.config() + {:ok, module} = Yacto.Migration.File.load_migration_module(migration_dir, migration_file) diff --git a/mix.exs b/mix.exs index b724329..6efdc00 100644 --- a/mix.exs +++ b/mix.exs @@ -8,7 +8,7 @@ defmodule Yacto.Mixfile do [ app: :yacto, version: @version, - elixir: "~> 1.11", + elixir: "~> 1.19", elixirc_paths: elixirc_paths(Mix.env()), elixirc_options: [all_warnings: true, warnings_as_errors: true], start_permanent: Mix.env() == :prod, @@ -32,12 +32,11 @@ defmodule Yacto.Mixfile do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:ecto_sql, "~> 3.11"}, + {:ecto_sql, "~> 3.14"}, {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, - {:myxql, "~> 0.6.4"}, + {:myxql, "~> 0.9.0"}, {:elixir_uuid, "~> 1.2"}, - {:memoize, "~> 1.4"}, - {:power_assert, "~> 0.3.0", only: :test} + {:memoize, "~> 1.4"} ] end diff --git a/mix.lock b/mix.lock index de5d0c8..3a8244c 100644 --- a/mix.lock +++ b/mix.lock @@ -1,23 +1,16 @@ %{ - "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, - "db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"}, - "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, - "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"}, - "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"}, - "ecto": {:hex, :ecto, "3.11.2", "e1d26be989db350a633667c5cda9c3d115ae779b66da567c68c80cfb26a8c9ee", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c38bca2c6f8d8023f2145326cc8a80100c3ffe4dcbd9842ff867f7fc6156c65"}, - "ecto_sql": {:hex, :ecto_sql, "3.11.3", "4eb7348ff8101fbc4e6bbc5a4404a24fecbe73a3372d16569526b0cf34ebc195", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e5f36e3d736b99c7fee3e631333b8394ade4bafe9d96d35669fca2d81c2be928"}, + "db_connection": {:hex, :db_connection, "2.10.2", "ae391e803a5adff104da913c2fc1c0c14a37f8b10001dcef568796e1fb7bf95c", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "510b14482330f1af6490a2fa0efd8d4f1435d1529b165647df22ac0f2df0fa93"}, + "decimal": {:hex, :decimal, "3.1.1", "430d87b04011ce6cbd4fd205be758311a81f87d552d40904abd00f015935b1d0", [:mix], [], "hexpm", "c5f25f2ced74a0587d03e6023f595db8e924c9d3922c8c8ffd9edfc4498cf1f6"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.46", "67607a0532e810c6f630a515c548d0b24949643f168cc556303bee4cf96105c7", [:mix], [], "hexpm", "9c44636e8a1c68c62f526b2dcd85d941dbbcee7ab82cf64ba06ce28bef8e89f5"}, + "ecto": {:hex, :ecto, "3.14.1", "7b740d87bdf45996aa0c2c2e081640906f10caa7ce5ba328fd294c7d49d0cc6f", [:mix], [{:decimal, "~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "24b991956796700f467d0a3ef3d303138a3ef9ddddf8b98f43758ee067b20a30"}, + "ecto_sql": {:hex, :ecto_sql, "3.14.0", "06446ab8410d2f85bfbb80857ee224ab3b693700cbb38f6535d507449a627b2e", [:mix], [{:db_connection, "~> 2.9", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.14.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.8", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f4d8d36faf294c9417b5a37ec7ac8217ee2abdef5fcf197ba690f361548d3949"}, "elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"}, - "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, - "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, - "makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"}, - "mariaex": {:hex, :mariaex, "0.9.1", "83266fec657ea68dd426f4bbc12594be45ee91fe162ebf1bf017ce3cfa098ddd", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"}, - "memoize": {:hex, :memoize, "1.4.3", "ead4ba248291acbaecbfe7e68ed762d329dd9c29c727020c7393dda4060c4471", [:mix], [], "hexpm", "a75176b84b9ce92faaf567c82fcbc584ef95727e0827cb38606b0a197f7e47ef"}, - "myxql": {:hex, :myxql, "0.6.4", "1502ea37ee23c31b79725b95d4cc3553693c2bda7421b1febc50722fd988c918", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:geo, "~> 3.4", [hex: :geo, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "a3307f4671f3009d3708283649adf205bfe280f7e036fc8ef7f16dbf821ab8e9"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, - "power_assert": {:hex, :power_assert, "0.3.0", "485280d8d02653e029ff0d64b0aa506ec17559dd48ce6de97696a10a5e077f7b", [:mix], [], "hexpm", "9b021050190b9237ff24dc5bb346e9c7428740d19c4c44c4b749eb23bed6cf64"}, - "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, - "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.40.3", "4a972ffe64bc07dc605af487e98fc19b72a4185f55ca031b94c0552d6071c1d9", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "2756e357742fecd9749b489b85d67c9ce99c465f2e75728d9e6dc8d704b973de"}, + "makeup": {:hex, :makeup, "1.2.2", "882d46dc0905e9ff7abf2aab61a7e6b3dcc555533977d8a23b06019e6c89ac94", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "9a1a24e5b343b8ae16abea0822c10a6f75da27af7fa802ada5251f7579bfccfa"}, + "makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.1.0", "835f7e60792e08824cda445639555d7bf1bbbddb1b60b306e33cb6f6db24dc74", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "1cd6780fb1dd1a03979abaed0fe82712b0625118fd5257d3ebbf73f960c73c3c"}, + "memoize": {:hex, :memoize, "1.4.5", "cd939ae2cc21772361a0944c7e2aa6eec6396820c1b8d22cc2725bcc7f4f978c", [:mix], [], "hexpm", "72cd8cb9871e83a8c7ac316ea88813a31f8e918ffb4880892e361c9e4f696b9a"}, + "myxql": {:hex, :myxql, "0.9.0", "1aec422f2c6b23215be0f00d84389f1ec27032d561ccf2927917e1bc541a6464", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 3.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:geo, "~> 3.4 or ~> 4.0", [hex: :geo, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "3a17b38562a7a995c291570875fd96c06b7b0369d6eb0592a52a9dccbe5d144b"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"}, + "telemetry": {:hex, :telemetry, "1.4.2", "a0cb522801dffb1c49fe6e30561badffc7b6d0e180db1300df759faa22062855", [:rebar3], [], "hexpm", "928f6495066506077862c0d1646609eed891a4326bee3126ba54b60af61febb1"}, } diff --git a/test/yacto/db_test.exs b/test/yacto/db_test.exs index c929628..8253418 100644 --- a/test/yacto/db_test.exs +++ b/test/yacto/db_test.exs @@ -1,5 +1,5 @@ defmodule Yacto.DBTest do - use PowerAssert + use ExUnit.Case @databases %{ default: %{module: Yacto.DB.Single, repo: Yacto.Repo.Default}, diff --git a/test/yacto/migration/file_test.exs b/test/yacto/migration/file_test.exs index 282d750..bd335ad 100644 --- a/test/yacto/migration/file_test.exs +++ b/test/yacto/migration/file_test.exs @@ -1,5 +1,5 @@ defmodule Yacto.Migration.FileTest do - use PowerAssert + use ExUnit.Case @migration_dir "_migrations" diff --git a/test/yacto/migration/migration_test.exs b/test/yacto/migration/migration_test.exs index df8e1e2..d1b92d1 100644 --- a/test/yacto/migration/migration_test.exs +++ b/test/yacto/migration/migration_test.exs @@ -1,8 +1,34 @@ defmodule Yacto.Migration.MigrationTest do - use PowerAssert + use ExUnit.Case require Ecto.Query + defp compile_migration!(source) when is_binary(source) do + source + |> extract_migration_module!() + |> unload_module_if_loaded() + + [{mod, _}] = Code.compile_string(source) + mod + end + + defp extract_migration_module!(source) do + case Regex.run(~r/^\s*defmodule\s+([A-Za-z0-9_.]+)\s+do/m, source, capture: :all_but_first) do + [module_name] -> + Module.concat([module_name]) + + _ -> + raise ArgumentError, "Could not extract migration module name from source" + end + end + + defp unload_module_if_loaded(mod) do + if Code.ensure_loaded?(mod) do + :code.purge(mod) + :code.delete(mod) + end + end + describe "DB のセットアップが必要なテスト" do @databases %{ default: %{module: Yacto.DB.Single, repo: Yacto.MigrationTest.Repo1}, @@ -29,9 +55,6 @@ defmodule Yacto.Migration.MigrationTest do port: 3306 ] - {:ok, _} = ExUnit.Callbacks.start_supervised({Yacto.MigrationTest.Repo0, repo0_config}) - {:ok, _} = ExUnit.Callbacks.start_supervised({Yacto.MigrationTest.Repo1, repo1_config}) - for {repo, config} <- [ {Yacto.MigrationTest.Repo0, repo0_config}, {Yacto.MigrationTest.Repo1, repo1_config} @@ -40,6 +63,9 @@ defmodule Yacto.Migration.MigrationTest do :ok = repo.__adapter__().storage_up(config) end + {:ok, _} = ExUnit.Callbacks.start_supervised({Yacto.MigrationTest.Repo0, repo0_config}) + {:ok, _} = ExUnit.Callbacks.start_supervised({Yacto.MigrationTest.Repo1, repo1_config}) + _ = File.rm_rf(Yacto.Migration.Util.get_migration_dir(:yacto)) _ = File.rm_rf(Yacto.Migration.Util.get_migration_dir_for_gen()) @@ -96,8 +122,7 @@ defmodule Yacto.Migration.MigrationTest do db_opts: [databases: @databases] ) - [{mod, _}] = Code.compile_string(migrate) - mod + compile_migration!(migrate) end) # Yacto.MigrationTest.Player3 のテーブルが作られているはずなので、 @@ -141,7 +166,9 @@ defmodule Yacto.Migration.MigrationTest do Yacto.MigrationTest.DropFieldWithIndex2 ]) - ExUnit.Callbacks.on_exit(fn -> Application.delete_env(:yacto, :ignore_migration_schemas) end) + ExUnit.Callbacks.on_exit(fn -> + Application.delete_env(:yacto, :ignore_migration_schemas) + end) Mix.Task.rerun("yacto.gen.migration", [ "--prefix", @@ -200,7 +227,9 @@ defmodule Yacto.Migration.MigrationTest do Yacto.MigrationTest.DropFieldWithIndex2 ]) - ExUnit.Callbacks.on_exit(fn -> Application.delete_env(:yacto, :ignore_migration_schemas) end) + ExUnit.Callbacks.on_exit(fn -> + Application.delete_env(:yacto, :ignore_migration_schemas) + end) Mix.Task.rerun("yacto.gen.migration", ["--prefix", "Yacto.MigrationTest"]) @@ -227,7 +256,9 @@ defmodule Yacto.Migration.MigrationTest do Yacto.MigrationTest.DropFieldWithIndex2 ]) - ExUnit.Callbacks.on_exit(fn -> Application.delete_env(:yacto, :ignore_migration_schemas) end) + ExUnit.Callbacks.on_exit(fn -> + Application.delete_env(:yacto, :ignore_migration_schemas) + end) Mix.Task.rerun("yacto.gen.migration", ["--prefix", "Yacto.MigrationTest"]) @@ -256,7 +287,9 @@ defmodule Yacto.Migration.MigrationTest do Yacto.MigrationTest.DropFieldWithIndex2 ]) - ExUnit.Callbacks.on_exit(fn -> Application.delete_env(:yacto, :ignore_migration_schemas) end) + ExUnit.Callbacks.on_exit(fn -> + Application.delete_env(:yacto, :ignore_migration_schemas) + end) Mix.Task.rerun("yacto.gen.migration", ["--prefix", "Yacto.MigrationTest"]) Mix.Task.rerun("yacto.migrate", ["--app", "yacto", "--migration-dir", migration_dir]) @@ -287,7 +320,9 @@ defmodule Yacto.Migration.MigrationTest do test "フィールドの削除とインデックスの削除が同時に行われた場合に正しくマイグレーションできる" do migration_dir = Yacto.Migration.Util.get_migration_dir_for_gen() - ExUnit.Callbacks.on_exit(fn -> Application.delete_env(:yacto, :ignore_migration_schemas) end) + ExUnit.Callbacks.on_exit(fn -> + Application.delete_env(:yacto, :ignore_migration_schemas) + end) Application.put_env(:yacto, :ignore_migration_schemas, [ Yacto.MigrationTest.Player2, @@ -331,7 +366,9 @@ defmodule Yacto.Migration.MigrationTest do test "マイグレートでテーブルの削除ができる" do migration_dir = Yacto.Migration.Util.get_migration_dir_for_gen() - ExUnit.Callbacks.on_exit(fn -> Application.delete_env(:yacto, :ignore_migration_schemas) end) + ExUnit.Callbacks.on_exit(fn -> + Application.delete_env(:yacto, :ignore_migration_schemas) + end) Application.put_env(:yacto, :ignore_migration_schemas, [ Yacto.MigrationTest.Player2, @@ -381,7 +418,9 @@ defmodule Yacto.Migration.MigrationTest do migration_dir = Yacto.Migration.Util.get_migration_dir_for_gen() _ = File.rm_rf(migration_dir) - ExUnit.Callbacks.on_exit(fn -> Application.delete_env(:yacto, :ignore_migration_schemas) end) + ExUnit.Callbacks.on_exit(fn -> + Application.delete_env(:yacto, :ignore_migration_schemas) + end) Application.put_env(:yacto, :ignore_migration_schemas, [ Yacto.MigrationTest.Player2, @@ -403,7 +442,9 @@ defmodule Yacto.Migration.MigrationTest do migration_dir = Yacto.Migration.Util.get_migration_dir_for_gen() _ = File.rm_rf(migration_dir) - ExUnit.Callbacks.on_exit(fn -> Application.delete_env(:yacto, :ignore_migration_schemas) end) + ExUnit.Callbacks.on_exit(fn -> + Application.delete_env(:yacto, :ignore_migration_schemas) + end) Application.put_env(:yacto, :ignore_migration_schemas, [ Yacto.MigrationTest.Player2, @@ -590,21 +631,21 @@ defmodule Yacto.Migration.MigrationTest do assert @migrate1 == migrate1 - [{mod1, _}] = Code.compile_string(migrate1) + mod1 = compile_migration!(migrate1) {:changed, migrate2, 1} = Yacto.Migration.GenMigration.generate(Yacto.MigrationTest.Player2, mod1) assert @migrate2 == migrate2 - [{mod2, _}] = Code.compile_string(migrate2) + mod2 = compile_migration!(migrate2) {:changed, migrate3, 2} = Yacto.Migration.GenMigration.generate(Yacto.MigrationTest.Player3, mod2) assert @migrate3 == migrate3 - [{mod3, _}] = Code.compile_string(migrate3) + mod3 = compile_migration!(migrate3) {:deleted, migrate4, 3} = Yacto.Migration.GenMigration.generate(nil, mod3) assert @migrate4 == migrate4 end @@ -757,13 +798,13 @@ defmodule Yacto.Migration.MigrationTest do port: 3306 ] - {:ok, _} = ExUnit.Callbacks.start_supervised({repo0, repo0_config}) - _ = repo0.__adapter__().storage_down(repo0_config) :ok = repo0.__adapter__().storage_up(repo0_config) + + {:ok, _} = ExUnit.Callbacks.start_supervised({repo0, repo0_config}) Yacto.Migration.SchemaMigration.ensure_schema_migrations_table!(repo0) - [{mod1, _}] = Code.compile_string(@migrate1) + mod1 = compile_migration!(@migrate1) Yacto.Migration.Migrator.migrate( :yacto, @@ -773,7 +814,7 @@ defmodule Yacto.Migration.MigrationTest do mod1 ) - [{mod2, _}] = Code.compile_string(@migrate2) + mod2 = compile_migration!(@migrate2) Yacto.Migration.Migrator.migrate( :yacto, @@ -783,7 +824,7 @@ defmodule Yacto.Migration.MigrationTest do mod2 ) - [{mod3, _}] = Code.compile_string(@migrate3) + mod3 = compile_migration!(@migrate3) Yacto.Migration.Migrator.migrate( :yacto, @@ -793,7 +834,7 @@ defmodule Yacto.Migration.MigrationTest do mod3 ) - [{mod4, _}] = Code.compile_string(@migrate4) + mod4 = compile_migration!(@migrate4) Yacto.Migration.Migrator.migrate( :yacto, @@ -803,7 +844,7 @@ defmodule Yacto.Migration.MigrationTest do mod4 ) - [{mod5, _}] = Code.compile_string(@migrate5) + mod5 = compile_migration!(@migrate5) Yacto.Migration.Migrator.migrate( :yacto, @@ -813,7 +854,7 @@ defmodule Yacto.Migration.MigrationTest do mod5 ) - [{mod6, _}] = Code.compile_string(@migrate6) + mod6 = compile_migration!(@migrate6) Yacto.Migration.Migrator.migrate( :yacto, @@ -823,7 +864,7 @@ defmodule Yacto.Migration.MigrationTest do mod6 ) - [{mod7, _}] = Code.compile_string(@migrate7) + mod7 = compile_migration!(@migrate7) Yacto.Migration.Migrator.migrate( :yacto, @@ -833,7 +874,7 @@ defmodule Yacto.Migration.MigrationTest do mod7 ) - [{mod8, _}] = Code.compile_string(@migrate8) + mod8 = compile_migration!(@migrate8) Yacto.Migration.Migrator.migrate( :yacto, @@ -894,6 +935,5 @@ defmodule Yacto.Migration.MigrationTest do assert @virtualfield == migrate end - end end diff --git a/test/yacto/migration/router_test.exs b/test/yacto/migration/router_test.exs index f1572ed..194e899 100644 --- a/test/yacto/migration/router_test.exs +++ b/test/yacto/migration/router_test.exs @@ -1,5 +1,5 @@ defmodule Yacto.Migration.RouterTest do - use PowerAssert + use ExUnit.Case defmodule Item do use Yacto.Schema diff --git a/test/yacto/migration/schema_test.exs b/test/yacto/migration/schema_test.exs index f39e178..39657de 100644 --- a/test/yacto/migration/schema_test.exs +++ b/test/yacto/migration/schema_test.exs @@ -1,5 +1,5 @@ defmodule Yacto.Migration.SchemaTest do - use PowerAssert + use ExUnit.Case defmodule Schema do use Yacto.Schema, dbname: :default diff --git a/test/yacto/migration/sharding_test.exs b/test/yacto/migration/sharding_test.exs index 7fb320a..7b2ea37 100644 --- a/test/yacto/migration/sharding_test.exs +++ b/test/yacto/migration/sharding_test.exs @@ -34,17 +34,17 @@ defmodule Yacto.Migration.ShardingTest do ]} end + for {repo, config} <- [default_config] ++ player_configs do + _ = repo.__adapter__().storage_down(config) + :ok = repo.__adapter__().storage_up(config) + end + {:ok, _} = ExUnit.Callbacks.start_supervised(default_config) for config <- player_configs do {:ok, _} = ExUnit.Callbacks.start_supervised(config) end - for {repo, config} <- [default_config] ++ player_configs do - _ = repo.__adapter__().storage_down(config) - :ok = repo.__adapter__().storage_up(config) - end - Application.put_env(:yacto, :databases, @databases) Application.put_env(:yacto, :ecto_repos, [ diff --git a/test/yacto/migration/structure_test.exs b/test/yacto/migration/structure_test.exs index 7a7d34d..a4b4987 100644 --- a/test/yacto/migration/structure_test.exs +++ b/test/yacto/migration/structure_test.exs @@ -1,5 +1,5 @@ defmodule Yacto.Migration.StructureTest do - use PowerAssert + use ExUnit.Case defmodule Schema do use Yacto.Schema, dbname: :default diff --git a/test/yacto/migration/util_test.exs b/test/yacto/migration/util_test.exs index 20fc18b..a09ad25 100644 --- a/test/yacto/migration/util_test.exs +++ b/test/yacto/migration/util_test.exs @@ -1,5 +1,5 @@ defmodule Yacto.Migration.UtilTest do - use PowerAssert + use ExUnit.Case test "マイグレーションディレクトリの確認" do expected = Path.join([File.cwd!(), "_build", "test", "lib", "yacto", "priv", "migrations"]) @@ -10,7 +10,6 @@ defmodule Yacto.Migration.UtilTest do end test "get_all_schema で全てのスキーマを取得できるか" do - require Yacto.Migration.SchemaMigration assert Yacto.Migration.SchemaMigration in Yacto.Migration.Util.get_all_schema(:yacto) # prefix を付けて確認 diff --git a/test/yacto/query_test.exs b/test/yacto/query_test.exs index 202e2fe..2181a91 100644 --- a/test/yacto/query_test.exs +++ b/test/yacto/query_test.exs @@ -1,5 +1,6 @@ defmodule Yacto.QueryTest do - use PowerAssert + use ExUnit.Case + require Ecto.Query setup_all do diff --git a/test/yacto/xa_test.exs b/test/yacto/xa_test.exs index 0a03ff7..c0f7e85 100644 --- a/test/yacto/xa_test.exs +++ b/test/yacto/xa_test.exs @@ -1,5 +1,6 @@ defmodule Yacto.XATest do - use PowerAssert + use ExUnit.Case + doctest Yacto.XA require Ecto.Query @@ -38,7 +39,9 @@ defmodule Yacto.XATest do test "Multi Transaction without XA" do :result = - Yacto.XA.transaction([Yacto.XATest.Repo0, Yacto.XATest.Repo1], fn -> :result end, noxa: true) + Yacto.XA.transaction([Yacto.XATest.Repo0, Yacto.XATest.Repo1], fn -> :result end, + noxa: true + ) end test "XA Transaction" do diff --git a/test/yacto/yacto_test.exs b/test/yacto/yacto_test.exs index 6f03588..87089c7 100644 --- a/test/yacto/yacto_test.exs +++ b/test/yacto/yacto_test.exs @@ -1,5 +1,5 @@ defmodule YactoTest do - use PowerAssert + use ExUnit.Case @databases %{ default: %{module: Yacto.DB.Single, repo: Yacto.QueryTest.Repo.Default},