Skip to content

failing test for calculations in different schema #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"attributes": [
{
"allow_nil?": false,
"default": "fragment(\"gen_random_uuid()\")",
"generated?": false,
"precision": null,
"primary_key?": true,
"references": null,
"scale": null,
"size": null,
"source": "id",
"type": "uuid"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"precision": null,
"primary_key?": false,
"references": {
"deferrable": false,
"destination_attribute": "id",
"destination_attribute_default": null,
"destination_attribute_generated": null,
"index?": false,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "records_temp_entities_record_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "public",
"table": "records"
},
"scale": null,
"size": null,
"source": "record_id",
"type": "uuid"
},
{
"allow_nil?": true,
"default": "nil",
"generated?": false,
"precision": null,
"primary_key?": false,
"references": {
"deferrable": false,
"destination_attribute": "id",
"destination_attribute_default": null,
"destination_attribute_generated": null,
"index?": false,
"match_type": null,
"match_with": null,
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"name": "records_temp_entities_temp_entity_id_fkey",
"on_delete": null,
"on_update": null,
"primary_key?": true,
"schema": "temp",
"table": "temp_entities"
},
"scale": null,
"size": null,
"source": "temp_entity_id",
"type": "uuid"
}
],
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true,
"hash": "1F00231E86F4E276096E683FD2836B40F36C6AD617A777D947E908FD52D09FDB",
"identities": [],
"multitenancy": {
"attribute": null,
"global": null,
"strategy": null
},
"repo": "Elixir.AshPostgres.TestRepo",
"schema": null,
"table": "records_temp_entities"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule AshPostgres.TestRepo.Migrations.CreateRecordTempEntitiesTable do
@moduledoc """
Updates resources based on their most recent snapshots.

This file was autogenerated with `mix ash_postgres.generate_migrations`
"""

use Ecto.Migration

def up do
create table(:records_temp_entities, primary_key: false) do
add(:id, :uuid, null: false, default: fragment("gen_random_uuid()"), primary_key: true)

add(
:record_id,
references(:records,
column: :id,
name: "records_temp_entities_record_id_fkey",
type: :uuid,
prefix: "public"
)
)

add(
:temp_entity_id,
references(:temp_entities,
column: :id,
name: "records_temp_entities_temp_entity_id_fkey",
type: :uuid,
prefix: "temp"
)
)
end
end

def down do
drop(constraint(:records_temp_entities, "records_temp_entities_record_id_fkey"))

drop(constraint(:records_temp_entities, "records_temp_entities_temp_entity_id_fkey"))

drop(table(:records_temp_entities))
end
end
8 changes: 6 additions & 2 deletions test/calculation_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPostgres.CalculationTest do
alias AshPostgres.Test.RecordTempEntity
use AshPostgres.RepoCase, async: false
alias AshPostgres.Test.{Account, Author, Comedian, Comment, Post, Record, TempEntity, User}

Expand Down Expand Up @@ -1018,9 +1019,12 @@ defmodule AshPostgres.CalculationTest do
end

test "calculation references use the appropriate schema" do
Record |> Ash.Changeset.for_create(:create, %{full_name: "name"}) |> Ash.create!()
record = Record |> Ash.Changeset.for_create(:create, %{full_name: "name"}) |> Ash.create!()

TempEntity |> Ash.Changeset.for_create(:create, %{full_name: "name"}) |> Ash.create!()
temp_entity =
TempEntity |> Ash.Changeset.for_create(:create, %{full_name: "name"}) |> Ash.create!()

Ash.Seed.seed!(RecordTempEntity, %{record_id: record.id, temp_entity_id: temp_entity.id})

full_name =
Record
Expand Down
1 change: 1 addition & 0 deletions test/support/domain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ defmodule AshPostgres.Test.Domain do
resource(AshPostgres.Test.Entity)
resource(AshPostgres.Test.ContentVisibilityGroup)
resource(AshPostgres.Test.TempEntity)
resource(AshPostgres.Test.RecordTempEntity)
resource(AshPostgres.Test.Permalink)
resource(AshPostgres.Test.Record)
resource(AshPostgres.Test.PostFollower)
Expand Down
12 changes: 11 additions & 1 deletion test/support/resources/record.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ defmodule AshPostgres.Test.Record do
source_attribute(:full_name)
destination_attribute(:full_name)
end

many_to_many :temp_entities, AshPostgres.Test.TempEntity do
public?(true)

through(AshPostgres.Test.RecordTempEntity)
end
end

postgres do
Expand All @@ -36,7 +42,11 @@ defmodule AshPostgres.Test.Record do
end

calculations do
calculate(:temp_entity_full_name, :string, expr(temp_entity.full_name))
calculate(
:temp_entity_full_name,
:string,
expr(fragment("coalesce(?, '')", temp_entities.full_name))
)
end

actions do
Expand Down
25 changes: 25 additions & 0 deletions test/support/resources/record_temp_entity.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule AshPostgres.Test.RecordTempEntity do
@moduledoc false

use Ash.Resource,
domain: AshPostgres.Test.Domain,
data_layer: AshPostgres.DataLayer

postgres do
table "records_temp_entities"
repo AshPostgres.TestRepo
end

attributes do
uuid_primary_key(:id)
end

relationships do
belongs_to(:record, AshPostgres.Test.Record, public?: true)
belongs_to(:temp_entity, AshPostgres.Test.TempEntity, public?: true)
end

actions do
defaults([:read, :destroy, create: :*, update: :*])
end
end