Skip to content

Commit

Permalink
collocate postgres migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
woylie committed Sep 10, 2024
1 parent 56b4b26 commit 1ae36b5
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 80 deletions.
57 changes: 57 additions & 0 deletions integration_test/pg/migration.exs
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions integration_test/pg/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion integration_test/sqlite/migration.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Flop.Repo.SQLite.Migration do
defmodule Flop.Repo.Postgres.Migration do
use Ecto.Migration

def change do
Expand Down
5 changes: 0 additions & 5 deletions priv/repo/migrations/.formatter.exs

This file was deleted.

33 changes: 0 additions & 33 deletions priv/repo/migrations/20200527145236_create_test_tables.exs

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions priv/repo/migrations/20230614113912_composite_type.exs

This file was deleted.

9 changes: 0 additions & 9 deletions priv/repo/migrations/20230614114123_create_distance_table.exs

This file was deleted.

0 comments on commit 1ae36b5

Please sign in to comment.