mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-19 13:03:14 +12:00
chore: Update primary keys & formatting (#44)
This commit is contained in:
parent
cb46aab14f
commit
a9db1f3601
8 changed files with 73 additions and 72 deletions
|
@ -12,6 +12,7 @@ locals_without_parens = [
|
|||
]
|
||||
|
||||
[
|
||||
import_deps: [:ash],
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
|
||||
locals_without_parens: locals_without_parens,
|
||||
export: [
|
||||
|
|
|
@ -11,12 +11,12 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
|
||||
postgres do
|
||||
table "posts"
|
||||
repo(AshPostgres.TestRepo)
|
||||
repo AshPostgres.TestRepo
|
||||
end
|
||||
|
||||
actions do
|
||||
read(:read)
|
||||
create(:create)
|
||||
read :read
|
||||
create :create
|
||||
end
|
||||
|
||||
unquote(body)
|
||||
|
@ -54,13 +54,13 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
defposts do
|
||||
resource do
|
||||
identities do
|
||||
identity(:title, [:title])
|
||||
identity :title, [:title]
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:title, :string)
|
||||
uuid_primary_key :id
|
||||
attribute :title, :string
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -129,13 +129,13 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
defposts do
|
||||
resource do
|
||||
identities do
|
||||
identity(:title, [:title])
|
||||
identity :title, [:title]
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:title, :string)
|
||||
uuid_primary_key :id
|
||||
attribute :title, :string
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -157,14 +157,14 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
defposts do
|
||||
resource do
|
||||
identities do
|
||||
identity(:title, [:title])
|
||||
identity :title, [:title]
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:title, :string)
|
||||
attribute(:name, :string, allow_nil?: false)
|
||||
uuid_primary_key :id
|
||||
attribute :title, :string
|
||||
attribute :name, :string, allow_nil?: false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -187,8 +187,8 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
test "when renaming a field, it asks if you are renaming it, and renames it if you are" do
|
||||
defposts do
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:name, :string, allow_nil?: false)
|
||||
uuid_primary_key :id
|
||||
attribute :name, :string, allow_nil?: false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -212,8 +212,8 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
test "when renaming a field, it asks if you are renaming it, and adds it if you aren't" do
|
||||
defposts do
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:name, :string, allow_nil?: false)
|
||||
uuid_primary_key :id
|
||||
attribute :name, :string, allow_nil?: false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -238,9 +238,9 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
test "when renaming a field, it asks which field you are renaming it to, and renames it if you are" do
|
||||
defposts do
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:name, :string, allow_nil?: false)
|
||||
attribute(:subject, :string, allow_nil?: false)
|
||||
uuid_primary_key :id
|
||||
attribute :name, :string, allow_nil?: false
|
||||
attribute :subject, :string, allow_nil?: false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -265,9 +265,9 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
test "when renaming a field, it asks which field you are renaming it to, and adds it if you arent" do
|
||||
defposts do
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:name, :string, allow_nil?: false)
|
||||
attribute(:subject, :string, allow_nil?: false)
|
||||
uuid_primary_key :id
|
||||
attribute :name, :string, allow_nil?: false
|
||||
attribute :subject, :string, allow_nil?: false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -292,9 +292,9 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
test "when changing the primary key, it changes properly" do
|
||||
defposts do
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: false, default: &Ecto.UUID.generate/0)
|
||||
attribute(:guid, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:title, :string)
|
||||
attribute :id, :uuid, primary_key?: false, default: &Ecto.UUID.generate/0
|
||||
uuid_primary_key :guid
|
||||
attribute :title, :string
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -317,16 +317,16 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
test "when multiple schemas apply to the same table, all attributes are added" do
|
||||
defposts do
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:title, :string)
|
||||
attribute(:foobar, :string)
|
||||
uuid_primary_key :id
|
||||
attribute :title, :string
|
||||
attribute :foobar, :string
|
||||
end
|
||||
end
|
||||
|
||||
defposts Post2 do
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:name, :string)
|
||||
uuid_primary_key :id
|
||||
attribute :name, :string
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -359,8 +359,8 @@ defmodule AshPostgres.MigrationGeneratorTest do
|
|||
|
||||
defposts do
|
||||
attributes do
|
||||
attribute(:id, :integer, generated?: true, allow_nil?: false, primary_key?: true)
|
||||
attribute(:views, :integer)
|
||||
attribute :id, :integer, generated?: true, allow_nil?: false, primary_key?: true
|
||||
attribute :views, :integer
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ defmodule AshPostgres.Test.Api do
|
|||
use Ash.Api
|
||||
|
||||
resources do
|
||||
resource(AshPostgres.Test.Post)
|
||||
resource(AshPostgres.Test.Comment)
|
||||
resource AshPostgres.Test.Post
|
||||
resource AshPostgres.Test.Comment
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ defmodule AshPostgres.MultitenancyTest.Api do
|
|||
use Ash.Api
|
||||
|
||||
resources do
|
||||
resource(AshPostgres.MultitenancyTest.Org)
|
||||
resource(AshPostgres.MultitenancyTest.Post)
|
||||
resource AshPostgres.MultitenancyTest.Org
|
||||
resource AshPostgres.MultitenancyTest.Post
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,20 +5,20 @@ defmodule AshPostgres.MultitenancyTest.Org do
|
|||
|
||||
resource do
|
||||
identities do
|
||||
identity(:unique_by_name, [:name])
|
||||
identity :unique_by_name, [:name]
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ash.uuid/0)
|
||||
attribute(:name, :string)
|
||||
uuid_primary_key :id
|
||||
attribute :name, :string
|
||||
end
|
||||
|
||||
actions do
|
||||
read(:read)
|
||||
create(:create)
|
||||
update(:update)
|
||||
destroy(:destroy)
|
||||
read :read
|
||||
create :create
|
||||
update :update
|
||||
destroy :destroy
|
||||
end
|
||||
|
||||
postgres do
|
||||
|
@ -31,14 +31,14 @@ defmodule AshPostgres.MultitenancyTest.Org do
|
|||
end
|
||||
|
||||
multitenancy do
|
||||
strategy(:attribute)
|
||||
attribute(:id)
|
||||
global?(true)
|
||||
parse_attribute({__MODULE__, :tenant, []})
|
||||
strategy :attribute
|
||||
attribute :id
|
||||
global? true
|
||||
parse_attribute {__MODULE__, :tenant, []}
|
||||
end
|
||||
|
||||
relationships do
|
||||
has_many(:posts, AshPostgres.MultitenancyTest.Post, destination_field: :org_id)
|
||||
has_many :posts, AshPostgres.MultitenancyTest.Post, destination_field: :org_id
|
||||
end
|
||||
|
||||
def tenant("org_" <> tenant) do
|
||||
|
|
|
@ -4,15 +4,15 @@ defmodule AshPostgres.MultitenancyTest.Post do
|
|||
data_layer: AshPostgres.DataLayer
|
||||
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ash.uuid/0)
|
||||
attribute(:name, :string)
|
||||
uuid_primary_key :id
|
||||
attribute :name, :string
|
||||
end
|
||||
|
||||
actions do
|
||||
create(:create)
|
||||
read(:read)
|
||||
update(:update)
|
||||
destroy(:destroy)
|
||||
create :create
|
||||
read :read
|
||||
update :update
|
||||
destroy :destroy
|
||||
end
|
||||
|
||||
postgres do
|
||||
|
@ -23,10 +23,10 @@ defmodule AshPostgres.MultitenancyTest.Post do
|
|||
multitenancy do
|
||||
# Tells the resource to use the data layer
|
||||
# multitenancy, in this case separate postgres schemas
|
||||
strategy(:context)
|
||||
strategy :context
|
||||
end
|
||||
|
||||
relationships do
|
||||
belongs_to(:org, AshPostgres.MultitenancyTest.Org)
|
||||
belongs_to :org, AshPostgres.MultitenancyTest.Org
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,16 +9,16 @@ defmodule AshPostgres.Test.Comment do
|
|||
end
|
||||
|
||||
actions do
|
||||
read(:read)
|
||||
create(:create)
|
||||
read :read
|
||||
create :create
|
||||
end
|
||||
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:title, :string)
|
||||
uuid_primary_key :id
|
||||
attribute :title, :string
|
||||
end
|
||||
|
||||
relationships do
|
||||
belongs_to(:post, AshPostgres.Test.Post)
|
||||
belongs_to :post, AshPostgres.Test.Post
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,30 +9,30 @@ defmodule AshPostgres.Test.Post do
|
|||
end
|
||||
|
||||
actions do
|
||||
read(:read)
|
||||
create(:create)
|
||||
read :read
|
||||
create :create
|
||||
end
|
||||
|
||||
attributes do
|
||||
attribute(:id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0)
|
||||
attribute(:title, :string)
|
||||
attribute(:score, :integer)
|
||||
attribute(:public, :boolean)
|
||||
uuid_primary_key(:id)
|
||||
attribute :title, :string
|
||||
attribute :score, :integer
|
||||
attribute :public, :boolean
|
||||
end
|
||||
|
||||
relationships do
|
||||
has_many(:comments, AshPostgres.Test.Comment, destination_field: :post_id)
|
||||
has_many :comments, AshPostgres.Test.Comment, destination_field: :post_id
|
||||
end
|
||||
|
||||
aggregates do
|
||||
count(:count_of_comments, :comments)
|
||||
count :count_of_comments, :comments
|
||||
|
||||
count :count_of_comments_called_match, :comments do
|
||||
filter(title: "match")
|
||||
filter title: "match"
|
||||
end
|
||||
|
||||
first :first_comment, :comments, :title do
|
||||
sort(title: :asc_nils_last)
|
||||
sort title: :asc_nils_last
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue