From 2d78c2bd1bfb9bdea43ca45b4aa24551855eef7d Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 4 May 2025 21:49:13 +0300 Subject: [PATCH] Update DBIServer to add a relationship to itself and the sync on attribute. --- .../metadata/dbi_server.ex | 15 +- ...onship_to_itself_and_sync_on_attribute.exs | 32 +++++ .../repo/dbi_servers/20250504183409.json | 129 ++++++++++++++++++ 3 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20250504183408_update_dbi_server_to_add_relationship_to_itself_and_sync_on_attribute.exs create mode 100644 priv/resource_snapshots/repo/dbi_servers/20250504183409.json diff --git a/lib/decentralised_book_index/metadata/dbi_server.ex b/lib/decentralised_book_index/metadata/dbi_server.ex index 3a2ddb0..7f8261a 100644 --- a/lib/decentralised_book_index/metadata/dbi_server.ex +++ b/lib/decentralised_book_index/metadata/dbi_server.ex @@ -21,12 +21,12 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do create :create do primary? true - accept [:name, :url] + accept [:name, :url, :sync_on?] end update :update do primary? true - accept [:name, :url] + accept [:name, :url, :sync_on?] end read :by_id do @@ -51,6 +51,10 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do bypass actor_attribute_equals(:role, :admin) do authorize_if always() end + + policy action_type(:read) do + authorize_if always() + end end attributes do @@ -66,6 +70,11 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do public? true end + attribute :sync_on?, :boolean do + allow_nil? true + default false + end + timestamps do writable? true public? true @@ -73,6 +82,8 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do end relationships do + belongs_to :dbi_server, Metadata.DBIServer + has_many :author, Metadata.Author has_many :author_alias_registries, Metadata.AuthorAliasRegistry has_many :author_roles, Metadata.AuthorRole diff --git a/priv/repo/migrations/20250504183408_update_dbi_server_to_add_relationship_to_itself_and_sync_on_attribute.exs b/priv/repo/migrations/20250504183408_update_dbi_server_to_add_relationship_to_itself_and_sync_on_attribute.exs new file mode 100644 index 0000000..a065d7f --- /dev/null +++ b/priv/repo/migrations/20250504183408_update_dbi_server_to_add_relationship_to_itself_and_sync_on_attribute.exs @@ -0,0 +1,32 @@ +defmodule DecentralisedBookIndex.Repo.Migrations.UpdateDbiServerToAddRelationshipToItselfAndSyncOnAttribute 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(:dbi_servers) do + add :sync_on?, :boolean, default: false + + add :dbi_server_id, + references(:dbi_servers, + column: :id, + name: "dbi_servers_dbi_server_id_fkey", + type: :uuid, + prefix: "public" + ) + end + end + + def down do + drop constraint(:dbi_servers, "dbi_servers_dbi_server_id_fkey") + + alter table(:dbi_servers) do + remove :dbi_server_id + remove :sync_on? + end + end +end diff --git a/priv/resource_snapshots/repo/dbi_servers/20250504183409.json b/priv/resource_snapshots/repo/dbi_servers/20250504183409.json new file mode 100644 index 0000000..7ca5ec3 --- /dev/null +++ b/priv/resource_snapshots/repo/dbi_servers/20250504183409.json @@ -0,0 +1,129 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"gen_random_uuid()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "name", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "url", + "type": "text" + }, + { + "allow_nil?": true, + "default": "false", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "sync_on?", + "type": "boolean" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "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": "dbi_servers_dbi_server_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "dbi_servers" + }, + "size": null, + "source": "dbi_server_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [ + { + "all_tenants?": false, + "concurrently": false, + "error_fields": [], + "fields": [ + { + "type": "string", + "value": "name gin_trgm_ops" + } + ], + "include": null, + "message": null, + "name": "server_name_gin_index", + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": false, + "using": "GIN", + "where": null + } + ], + "custom_statements": [], + "has_create_action": true, + "hash": "9EDA6BBD6005F48CE5FAFDEE80AEF0C1B3A98440F9287B4294CF64D5BB02F199", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "dbi_servers" +} \ No newline at end of file