diff --git a/integration_test/pg/migration.exs b/integration_test/pg/migration.exs new file mode 100644 index 00000000..7a9a25fc --- /dev/null +++ b/integration_test/pg/migration.exs @@ -0,0 +1,57 @@ +defmodule Flop.Repo.Postgres.Migration do + use Ecto.Migration + + def change do + execute( + "CREATE TYPE public.distance AS (unit varchar, value float);", + "DROP TYPE public.distance;" + ) + + create table(:owners) do + add(:age, :integer) + add(:email, :string) + add(:name, :string) + add(:tags, {:array, :string}) + add(:attributes, :map) + add(:extra, {:map, :string}) + end + + create table(:pets) do + add(:age, :integer) + add(:family_name, :string) + add(:given_name, :string) + add(:name, :string) + add(:owner_id, references(:owners)) + add(:species, :string) + add(:mood, :string) + add(:tags, {:array, :string}) + end + + create table(:fruits) do + add(:family, :string) + add(:name, :string) + add(:attributes, :map) + add(:extra, {:map, :string}) + add(:owner_id, references(:owners)) + end + + create table(:walking_distances) do + add(:trip, :distance) + end + + # create pets table in other schema + + execute("CREATE SCHEMA other_schema;", "DROP SCHEMA other_schema;") + + create table(:pets, prefix: "other_schema") do + add(:age, :integer) + add(:family_name, :string) + add(:given_name, :string) + add(:name, :string) + add(:owner_id, :integer) + add(:species, :string) + add(:mood, :string) + add(:tags, {:array, :string}) + end + end +end diff --git a/integration_test/pg/test_helper.exs b/integration_test/pg/test_helper.exs index 6a0b70ba..4976711a 100644 --- a/integration_test/pg/test_helper.exs +++ b/integration_test/pg/test_helper.exs @@ -23,16 +23,19 @@ defmodule Flop.Integration.Case do end end +Code.require_file("migration.exs", __DIR__) + {:ok, _} = Ecto.Adapters.Postgres.ensure_all_started(Flop.Repo.config(), :temporary) # Load up the repository, start it, and run migrations -_ = Ecto.Adapters.Postgres.storage_down(Flop.Repo.config()) -:ok = Ecto.Adapters.Postgres.storage_up(Flop.Repo.config()) +Ecto.Adapters.Postgres.storage_down(Flop.Repo.config()) +Ecto.Adapters.Postgres.storage_up(Flop.Repo.config()) {:ok, _pid} = Flop.Repo.start_link() -[_ | _] = Ecto.Migrator.run(Flop.Repo, :up, log: true, all: true) +Ecto.Migrator.up(Flop.Repo, 0, Flop.Repo.Postgres.Migration, log: true) + Ecto.Adapters.SQL.Sandbox.mode(Flop.Repo, :manual) {:ok, _} = Application.ensure_all_started(:ex_machina) diff --git a/integration_test/sqlite/migration.exs b/integration_test/sqlite/migration.exs index 49d469e6..ac5eb202 100644 --- a/integration_test/sqlite/migration.exs +++ b/integration_test/sqlite/migration.exs @@ -1,4 +1,4 @@ -defmodule Flop.Repo.SQLite.Migration do +defmodule Flop.Repo.Postgres.Migration do use Ecto.Migration def change do diff --git a/priv/repo/migrations/.formatter.exs b/priv/repo/migrations/.formatter.exs deleted file mode 100644 index 3a510b28..00000000 --- a/priv/repo/migrations/.formatter.exs +++ /dev/null @@ -1,5 +0,0 @@ -[ - import_deps: [:ecto_sql], - inputs: ["*.exs"], - line_length: 80 -] diff --git a/priv/repo/migrations/20200527145236_create_test_tables.exs b/priv/repo/migrations/20200527145236_create_test_tables.exs deleted file mode 100644 index 9c4940e8..00000000 --- a/priv/repo/migrations/20200527145236_create_test_tables.exs +++ /dev/null @@ -1,33 +0,0 @@ -defmodule Flop.Repo.Migrations.CreateTestTables do - use Ecto.Migration - - def change do - create table(:owners) do - add :age, :integer - add :email, :string - add :name, :string - add :tags, {:array, :string} - add :attributes, :map - add :extra, {:map, :string} - end - - create table(:pets) do - add :age, :integer - add :family_name, :string - add :given_name, :string - add :name, :string - add :owner_id, references(:owners) - add :species, :string - add :mood, :string - add :tags, {:array, :string} - end - - create table(:fruits) do - add :family, :string - add :name, :string - add :attributes, :map - add :extra, {:map, :string} - add :owner_id, references(:owners) - end - end -end diff --git a/priv/repo/migrations/20210523123456_create_pets_in_second_schema.exs b/priv/repo/migrations/20210523123456_create_pets_in_second_schema.exs deleted file mode 100644 index d5dee232..00000000 --- a/priv/repo/migrations/20210523123456_create_pets_in_second_schema.exs +++ /dev/null @@ -1,18 +0,0 @@ -defmodule Flop.Repo.Migrations.CreatePetsInSecondSchema do - use Ecto.Migration - - def change do - execute("CREATE SCHEMA other_schema;", "DROP SCHEMA other_schema;") - - create table(:pets, prefix: "other_schema") do - add :age, :integer - add :family_name, :string - add :given_name, :string - add :name, :string - add :owner_id, :integer - add :species, :string - add :mood, :string - add :tags, {:array, :string} - end - end -end diff --git a/priv/repo/migrations/20230614113912_composite_type.exs b/priv/repo/migrations/20230614113912_composite_type.exs deleted file mode 100644 index 564110a3..00000000 --- a/priv/repo/migrations/20230614113912_composite_type.exs +++ /dev/null @@ -1,11 +0,0 @@ -defmodule Sibill.Repo.Migrations.CompositeType do - use Ecto.Migration - - def up do - execute("CREATE TYPE public.distance AS (unit varchar, value float);") - end - - def down do - execute("DROP TYPE public.distance;") - end -end diff --git a/priv/repo/migrations/20230614114123_create_distance_table.exs b/priv/repo/migrations/20230614114123_create_distance_table.exs deleted file mode 100644 index 25296fe9..00000000 --- a/priv/repo/migrations/20230614114123_create_distance_table.exs +++ /dev/null @@ -1,9 +0,0 @@ -defmodule Sibill.Repo.Migrations.CreateDistanceTable do - use Ecto.Migration - - def change do - create table(:walking_distances) do - add(:trip, :distance) - end - end -end