mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
fix: handle new if types
improvement: relax ash version requirement
This commit is contained in:
parent
9a97cb682d
commit
98004f3251
22 changed files with 25 additions and 387 deletions
|
@ -2701,7 +2701,13 @@ defmodule AshPostgres.DataLayer do
|
|||
type
|
||||
) do
|
||||
[condition_type, when_true_type, when_false_type] =
|
||||
determine_types(If, [condition, when_true, when_false])
|
||||
case determine_types(If, [condition, when_true, when_false]) do
|
||||
[condition_type, when_true] ->
|
||||
[condition_type, when_true, nil]
|
||||
|
||||
[condition_type, when_true, when_false] ->
|
||||
[condition_type, when_true, when_false]
|
||||
end
|
||||
|
||||
{params, condition} =
|
||||
do_filter_to_expr(condition, bindings, params, pred_embedded? || embedded?, condition_type)
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -96,7 +96,7 @@ defmodule AshPostgres.MixProject do
|
|||
{:ecto_sql, "~> 3.7"},
|
||||
{:jason, "~> 1.0"},
|
||||
{:postgrex, ">= 0.0.0"},
|
||||
{:ash, ash_version("1.50.1")},
|
||||
{:ash, ash_version("1.50")},
|
||||
{:git_ops, "~> 2.4.5", only: :dev},
|
||||
{:ex_doc, "~> 0.22", only: :dev, runtime: false},
|
||||
{:ex_check, "~> 0.11.0", only: :dev},
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
{
|
||||
"attributes": [
|
||||
{
|
||||
"allow_nil?": false,
|
||||
"default": "fragment(\"uuid_generate_v4()\")",
|
||||
"generated?": false,
|
||||
"name": "id",
|
||||
"primary_key?": true,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "uuid"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "score",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "bigint"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "resource_id",
|
||||
"primary_key?": false,
|
||||
"references": {
|
||||
"destination_field": "id",
|
||||
"destination_field_default": "fragment(\"uuid_generate_v4()\")",
|
||||
"destination_field_generated": null,
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
"global": null,
|
||||
"strategy": null
|
||||
},
|
||||
"name": "comment_ratings_resource_id_fkey",
|
||||
"on_delete": null,
|
||||
"on_update": null,
|
||||
"table": "comments"
|
||||
},
|
||||
"size": null,
|
||||
"type": "uuid"
|
||||
}
|
||||
],
|
||||
"base_filter": null,
|
||||
"check_constraints": [],
|
||||
"custom_indexes": [],
|
||||
"has_create_action": true,
|
||||
"hash": "05F649E4414D4489F59CD3EB03D7147689EBD2EAC32327C697D1C7DC2B9E480D",
|
||||
"identities": [],
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
"global": null,
|
||||
"strategy": null
|
||||
},
|
||||
"repo": "Elixir.AshPostgres.TestRepo",
|
||||
"table": "comment_ratings"
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
{
|
||||
"attributes": [
|
||||
{
|
||||
"allow_nil?": false,
|
||||
"default": "fragment(\"uuid_generate_v4()\")",
|
||||
"generated?": false,
|
||||
"name": "id",
|
||||
"primary_key?": true,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "uuid"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "title",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "likes",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "bigint"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "arbitrary_timestamp",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "utc_datetime_usec"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "post_id",
|
||||
"primary_key?": false,
|
||||
"references": {
|
||||
"destination_field": "id",
|
||||
"destination_field_default": null,
|
||||
"destination_field_generated": null,
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
"global": null,
|
||||
"strategy": null
|
||||
},
|
||||
"name": "special_name_fkey",
|
||||
"on_delete": "delete",
|
||||
"on_update": "update",
|
||||
"table": "posts"
|
||||
},
|
||||
"size": null,
|
||||
"type": "uuid"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "author_id",
|
||||
"primary_key?": false,
|
||||
"references": {
|
||||
"destination_field": "id",
|
||||
"destination_field_default": null,
|
||||
"destination_field_generated": null,
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
"global": null,
|
||||
"strategy": null
|
||||
},
|
||||
"name": "comments_author_id_fkey",
|
||||
"on_delete": null,
|
||||
"on_update": null,
|
||||
"table": "authors"
|
||||
},
|
||||
"size": null,
|
||||
"type": "uuid"
|
||||
}
|
||||
],
|
||||
"base_filter": null,
|
||||
"check_constraints": [],
|
||||
"custom_indexes": [],
|
||||
"has_create_action": true,
|
||||
"hash": "7622548F1B045347C5FCFED994A9765A990B02FCCD0FCC185AC628CBF964D436",
|
||||
"identities": [],
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
"global": null,
|
||||
"strategy": null
|
||||
},
|
||||
"repo": "Elixir.AshPostgres.TestRepo",
|
||||
"table": "comments"
|
||||
}
|
|
@ -30,6 +30,16 @@
|
|||
"size": null,
|
||||
"type": "bigint"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "arbitrary_timestamp",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "utc_datetime_usec"
|
||||
},
|
||||
{
|
||||
"allow_nil?": false,
|
||||
"default": "fragment(\"now()\")",
|
||||
|
@ -91,7 +101,7 @@
|
|||
"check_constraints": [],
|
||||
"custom_indexes": [],
|
||||
"has_create_action": true,
|
||||
"hash": "FF020E5617D17FF19EBBD8E2BFF9B3D99149A5CE37E48B5CDC3B208A60D42DCF",
|
||||
"hash": "8C7B9F47D65676E7A767135486DDFCBC6719A2D5B493D3E97DF23F181632045D",
|
||||
"identities": [],
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
|
@ -1,60 +0,0 @@
|
|||
{
|
||||
"attributes": [
|
||||
{
|
||||
"allow_nil?": false,
|
||||
"default": "fragment(\"uuid_generate_v4()\")",
|
||||
"generated?": false,
|
||||
"name": "id",
|
||||
"primary_key?": true,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "uuid"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "score",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "bigint"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "resource_id",
|
||||
"primary_key?": false,
|
||||
"references": {
|
||||
"destination_field": "id",
|
||||
"destination_field_default": "fragment(\"uuid_generate_v4()\")",
|
||||
"destination_field_generated": null,
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
"global": null,
|
||||
"strategy": null
|
||||
},
|
||||
"name": "post_ratings_resource_id_fkey",
|
||||
"on_delete": null,
|
||||
"on_update": null,
|
||||
"table": "posts"
|
||||
},
|
||||
"size": null,
|
||||
"type": "uuid"
|
||||
}
|
||||
],
|
||||
"base_filter": null,
|
||||
"check_constraints": [],
|
||||
"custom_indexes": [],
|
||||
"has_create_action": true,
|
||||
"hash": "AD6200C6D2E6E913A0A50201AA5CD9A0A8C21507073225E73AC4F01670C3C637",
|
||||
"identities": [],
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
"global": null,
|
||||
"strategy": null
|
||||
},
|
||||
"repo": "Elixir.AshPostgres.TestRepo",
|
||||
"table": "post_ratings"
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
{
|
||||
"attributes": [
|
||||
{
|
||||
"allow_nil?": false,
|
||||
"default": "fragment(\"uuid_generate_v4()\")",
|
||||
"generated?": false,
|
||||
"name": "id",
|
||||
"primary_key?": true,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "uuid"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "title",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "score",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "bigint"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "public",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "category",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "citext"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "\"sponsored\"",
|
||||
"generated?": false,
|
||||
"name": "type",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "price",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "bigint"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "0",
|
||||
"generated?": false,
|
||||
"name": "decimal",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "decimal"
|
||||
},
|
||||
{
|
||||
"allow_nil?": true,
|
||||
"default": "nil",
|
||||
"generated?": false,
|
||||
"name": "status",
|
||||
"primary_key?": false,
|
||||
"references": null,
|
||||
"size": null,
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"base_filter": "type = 'sponsored'",
|
||||
"check_constraints": [
|
||||
{
|
||||
"attribute": [
|
||||
"price"
|
||||
],
|
||||
"base_filter": "type = 'sponsored'",
|
||||
"check": "price > 0",
|
||||
"name": "price_must_be_positive"
|
||||
}
|
||||
],
|
||||
"custom_indexes": [],
|
||||
"has_create_action": true,
|
||||
"hash": "458B2EB01A37F8768D0D26245B05D2D9B2F1996E0BAF67C8D715AFB5A46D4EE0",
|
||||
"identities": [],
|
||||
"multitenancy": {
|
||||
"attribute": null,
|
||||
"global": null,
|
||||
"strategy": null
|
||||
},
|
||||
"repo": "Elixir.AshPostgres.TestRepo",
|
||||
"table": "posts"
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
defmodule AshPostgres.TestRepo.Migrations.MigrateResources2 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
|
||||
alter table(:posts) do
|
||||
add :created_at, :utc_datetime_usec, null: false, default: fragment("now()")
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:posts) do
|
||||
remove :created_at
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
defmodule AshPostgres.TestRepo.Migrations.MigrateResources15 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
|
||||
alter table(:comments) do
|
||||
add :arbitrary_timestamp, :utc_datetime_usec
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:comments) do
|
||||
remove :arbitrary_timestamp
|
||||
end
|
||||
end
|
||||
end
|
|
@ -24,6 +24,7 @@ defmodule AshPostgres.TestRepo.Migrations.MigrateResources1 do
|
|||
add :price, :bigint
|
||||
add :decimal, :decimal, default: 0
|
||||
add :status, :text
|
||||
add :created_at, :utc_datetime_usec, null: false, default: fragment("now()")
|
||||
end
|
||||
|
||||
create table(:post_ratings, primary_key: false) do
|
||||
|
@ -72,6 +73,7 @@ defmodule AshPostgres.TestRepo.Migrations.MigrateResources1 do
|
|||
add :id, :uuid, null: false, default: fragment("uuid_generate_v4()"), primary_key: true
|
||||
add :title, :text
|
||||
add :likes, :bigint
|
||||
add :arbitrary_timestamp, :utc_datetime_usec
|
||||
add :created_at, :utc_datetime_usec, null: false, default: fragment("now()")
|
||||
|
||||
add :post_id,
|
|
@ -236,9 +236,10 @@ defmodule AshPostgres.CalculationTest do
|
|||
|
||||
@tag mustexec: true
|
||||
test "calculations load nullable timestamp aggregates compared to a fragment" do
|
||||
post = Post
|
||||
|> Ash.Changeset.new(%{title: "aaa", score: 0})
|
||||
|> Api.create!()
|
||||
post =
|
||||
Post
|
||||
|> Ash.Changeset.new(%{title: "aaa", score: 0})
|
||||
|> Api.create!()
|
||||
|
||||
Post
|
||||
|> Ash.Changeset.new(%{title: "aaa", score: 1})
|
||||
|
|
Loading…
Reference in a new issue