Packages
ecto_sql
3.5.0-rc.1
3.14.0
3.13.5
3.13.4
3.13.3
3.13.2
3.13.1
3.13.0
3.12.1
3.12.0
3.11.3
3.11.2
3.11.1
3.11.0
3.10.2
3.10.1
3.10.0
3.9.2
3.9.1
3.9.0
3.8.3
3.8.2
3.8.1
3.8.0
3.7.2
3.7.1
3.7.0
3.6.2
3.6.1
3.6.0
3.5.4
3.5.3
3.5.2
3.5.1
3.5.0
3.5.0-rc.1
3.5.0-rc.0
3.4.5
3.4.4
3.4.3
3.4.2
3.4.1
3.4.0
3.3.4
3.3.3
3.3.2
3.3.1
3.3.0
3.2.2
3.2.1
3.2.0
3.1.6
3.1.5
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
3.0.0-rc.1
3.0.0-rc.0
SQL-based adapters for Ecto and database migrations
Current section
Files
Jump to
Current section
Files
integration_test/sql/alter.exs
defmodule Ecto.Integration.AlterTest do
use Ecto.Integration.Case, async: false
alias Ecto.Integration.PoolRepo
defmodule AlterMigrationOne do
use Ecto.Migration
def up do
create table(:alter_col_type) do
add :value, :integer
end
execute "INSERT INTO alter_col_type (value) VALUES (1)"
end
def down do
drop table(:alter_col_type)
end
end
defmodule AlterMigrationTwo do
use Ecto.Migration
def up do
alter table(:alter_col_type) do
modify :value, :numeric
end
end
def down do
alter table(:alter_col_type) do
modify :value, :integer
end
end
end
import Ecto.Query, only: [from: 1, from: 2]
defp run(direction, repo, module) do
Ecto.Migration.Runner.run(repo, repo.config(), 1, module, :forward, direction, direction, log: false)
end
test "reset cache on returning query after alter column type" do
values = from v in "alter_col_type", select: v.value
assert :ok == run(:up, PoolRepo, AlterMigrationOne)
assert PoolRepo.all(values) == [1]
assert :ok == run(:up, PoolRepo, AlterMigrationTwo)
[%Decimal{}] = PoolRepo.all(values)
PoolRepo.transaction(fn() ->
assert [%Decimal{}] = PoolRepo.all(values)
assert :ok == run(:down, PoolRepo, AlterMigrationTwo)
# Optionally fail once with database error when
# already prepared on connection (and clear cache)
try do
PoolRepo.all(values, [mode: :savepoint])
rescue
_ ->
assert PoolRepo.all(values) == [1]
else
result ->
assert result == [1]
end
end)
after
assert :ok == run(:down, PoolRepo, AlterMigrationOne)
end
test "reset cache on parameterised query after alter column type" do
values = from v in "alter_col_type"
assert :ok == run(:up, PoolRepo, AlterMigrationOne)
assert PoolRepo.update_all(values, [set: [value: 2]]) == {1, nil}
assert :ok == run(:up, PoolRepo, AlterMigrationTwo)
assert PoolRepo.update_all(values, [set: [value: 3]]) == {1, nil}
PoolRepo.transaction(fn() ->
assert PoolRepo.update_all(values, [set: [value: Decimal.new(5)]]) == {1, nil}
assert :ok == run(:down, PoolRepo, AlterMigrationTwo)
assert PoolRepo.update_all(values, [set: [value: 6]]) == {1, nil}
end)
after
assert :ok == run(:down, PoolRepo, AlterMigrationOne)
end
end