From 4b08cc22c3130416f339f166394cbb7b45da7b1f Mon Sep 17 00:00:00 2001 From: yujonglee Date: Mon, 24 Jun 2024 21:42:19 +0900 Subject: [PATCH] add discord in client table --- core/lib/canary/clients/client.ex | 21 +++++- .../20240624123902_add_discord_client.exs | 41 ++++++++++++ ...0240624052524.json => 20240624123902.json} | 58 ++++++++++------- ...0240624052524.json => 20240624123902.json} | 64 +++++++++---------- ...0240624052524.json => 20240624123902.json} | 52 ++++++--------- 5 files changed, 147 insertions(+), 89 deletions(-) create mode 100644 core/priv/repo/migrations/20240624123902_add_discord_client.exs rename core/priv/resource_snapshots/repo/clients/{20240624052524.json => 20240624123902.json} (69%) rename core/priv/resource_snapshots/repo/source_documents/{20240624052524.json => 20240624123902.json} (76%) rename core/priv/resource_snapshots/repo/sources/{20240624052524.json => 20240624123902.json} (69%) diff --git a/core/lib/canary/clients/client.ex b/core/lib/canary/clients/client.ex index 977b8007..ba6428ed 100644 --- a/core/lib/canary/clients/client.ex +++ b/core/lib/canary/clients/client.ex @@ -10,10 +10,12 @@ defmodule Canary.Clients.Client do allow_nil? false end - attribute :type, :atom, constraints: [one_of: [:web]] + attribute :type, :atom, constraints: [one_of: [:web, :discord]] attribute :web_base_url, :string - attribute :web_public_key, :string, default: &Ash.UUID.generate/0 + attribute :web_public_key, :string + + attribute :discord_server_id, :integer end actions do @@ -29,6 +31,21 @@ defmodule Canary.Clients.Client do end change set_attribute(:type, :web) + change set_attribute(:web_base_url, expr(^arg(:web_base_url))) + change set_attribute(:web_public_key, &Ash.UUID.generate/0) + end + + create :create_discord do + argument :account_id, :uuid do + allow_nil? false + end + + argument :discord_server_id, :integer do + allow_nil? false + end + + change set_attribute(:type, :discord) + change set_attribute(:discord_server_id, expr(^arg(:discord_server_id))) end end diff --git a/core/priv/repo/migrations/20240624123902_add_discord_client.exs b/core/priv/repo/migrations/20240624123902_add_discord_client.exs new file mode 100644 index 00000000..661f35c2 --- /dev/null +++ b/core/priv/repo/migrations/20240624123902_add_discord_client.exs @@ -0,0 +1,41 @@ +defmodule Canary.Repo.Migrations.AddDiscordClient 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(:sources) do + remove :last_fetched_at + end + + alter table(:source_documents) do + modify :content_hash, :binary, null: false + modify :content, :text, null: false + end + + alter table(:clients) do + modify :web_public_key, :text, default: nil + add :discord_server_id, :bigint + end + end + + def down do + alter table(:clients) do + remove :discord_server_id + modify :web_public_key, :text, default: fragment("gen_random_uuid()") + end + + alter table(:source_documents) do + modify :content, :text, null: true + modify :content_hash, :binary, null: true + end + + alter table(:sources) do + add :last_fetched_at, :utc_datetime_usec + end + end +end diff --git a/core/priv/resource_snapshots/repo/clients/20240624052524.json b/core/priv/resource_snapshots/repo/clients/20240624123902.json similarity index 69% rename from core/priv/resource_snapshots/repo/clients/20240624052524.json rename to core/priv/resource_snapshots/repo/clients/20240624123902.json index be35e87f..1b405220 100644 --- a/core/priv/resource_snapshots/repo/clients/20240624052524.json +++ b/core/priv/resource_snapshots/repo/clients/20240624123902.json @@ -7,8 +7,8 @@ "source": "id", "references": null, "allow_nil?": false, - "primary_key?": true, - "generated?": false + "generated?": false, + "primary_key?": true }, { "default": "nil", @@ -18,26 +18,26 @@ "references": { "name": "clients_account_id_fkey", "table": "accounts", - "primary_key?": true, "schema": "public", + "on_delete": null, "multitenancy": { "global": null, - "strategy": null, - "attribute": null + "attribute": null, + "strategy": null }, + "primary_key?": true, "destination_attribute": "id", - "on_delete": null, - "on_update": null, "deferrable": false, - "match_with": null, - "match_type": null, "index?": false, + "match_type": null, + "match_with": null, + "on_update": null, "destination_attribute_default": null, "destination_attribute_generated": null }, "allow_nil?": false, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false }, { "default": "nil", @@ -46,8 +46,8 @@ "source": "type", "references": null, "allow_nil?": true, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false }, { "default": "nil", @@ -56,33 +56,43 @@ "source": "web_base_url", "references": null, "allow_nil?": true, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false }, { - "default": "fragment(\"gen_random_uuid()\")", + "default": "nil", "size": null, "type": "text", "source": "web_public_key", "references": null, "allow_nil?": true, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "bigint", + "source": "discord_server_id", + "references": null, + "allow_nil?": true, + "generated?": false, + "primary_key?": false } ], "table": "clients", - "hash": "0AFBAB6CE2B3F030E4357D6A2BAF91D778864BF42F714D5F2BD1A0D24DEEECDB", + "hash": "3AA6A68700A2FA737594DEDA0529CCCBFBA0A0E4589F49F888501EB3B421F43F", "repo": "Elixir.Canary.Repo", "identities": [], "schema": null, - "base_filter": null, - "check_constraints": [], - "custom_indexes": [], "multitenancy": { "global": null, - "strategy": null, - "attribute": null + "attribute": null, + "strategy": null }, + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], "custom_statements": [], "has_create_action": true } \ No newline at end of file diff --git a/core/priv/resource_snapshots/repo/source_documents/20240624052524.json b/core/priv/resource_snapshots/repo/source_documents/20240624123902.json similarity index 76% rename from core/priv/resource_snapshots/repo/source_documents/20240624052524.json rename to core/priv/resource_snapshots/repo/source_documents/20240624123902.json index 71222564..376438df 100644 --- a/core/priv/resource_snapshots/repo/source_documents/20240624052524.json +++ b/core/priv/resource_snapshots/repo/source_documents/20240624123902.json @@ -7,8 +7,8 @@ "source": "id", "references": null, "allow_nil?": false, - "primary_key?": true, - "generated?": true + "generated?": true, + "primary_key?": true }, { "default": "nil", @@ -17,8 +17,8 @@ "source": "updated_at", "references": null, "allow_nil?": true, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false }, { "default": "nil", @@ -28,26 +28,26 @@ "references": { "name": "source_documents_source_id_fkey", "table": "sources", - "primary_key?": true, "schema": "public", + "on_delete": null, "multitenancy": { "global": null, - "strategy": null, - "attribute": null + "attribute": null, + "strategy": null }, + "primary_key?": true, "destination_attribute": "id", - "on_delete": null, - "on_update": null, "deferrable": false, - "match_with": null, - "match_type": null, "index?": false, + "match_type": null, + "match_with": null, + "on_update": null, "destination_attribute_default": null, "destination_attribute_generated": null }, "allow_nil?": false, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false }, { "default": "nil", @@ -56,8 +56,8 @@ "source": "source_url", "references": null, "allow_nil?": true, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false }, { "default": "nil", @@ -65,9 +65,9 @@ "type": "text", "source": "content", "references": null, - "allow_nil?": true, - "primary_key?": false, - "generated?": false + "allow_nil?": false, + "generated?": false, + "primary_key?": false }, { "default": "nil", @@ -75,9 +75,9 @@ "type": "binary", "source": "content_hash", "references": null, - "allow_nil?": true, - "primary_key?": false, - "generated?": false + "allow_nil?": false, + "generated?": false, + "primary_key?": false }, { "default": "nil", @@ -86,12 +86,12 @@ "source": "content_embedding", "references": null, "allow_nil?": true, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false } ], "table": "source_documents", - "hash": "4C595F976262EBD14A9B5B101B9F31BD2DD737765F79F48DD3658413ECB2B21B", + "hash": "4865EA3D0F7F765466D50DA3F088CEF38A6DE2F903E7F2239D1FAA85F0175315", "repo": "Elixir.Canary.Repo", "identities": [ { @@ -107,21 +107,21 @@ } ], "where": null, - "index_name": "source_documents_unique_content_index", - "base_filter": null, + "nils_distinct?": true, "all_tenants?": false, - "nils_distinct?": true + "index_name": "source_documents_unique_content_index", + "base_filter": null } ], "schema": null, - "base_filter": null, - "check_constraints": [], - "custom_indexes": [], "multitenancy": { "global": null, - "strategy": null, - "attribute": null + "attribute": null, + "strategy": null }, + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], "custom_statements": [], "has_create_action": true } \ No newline at end of file diff --git a/core/priv/resource_snapshots/repo/sources/20240624052524.json b/core/priv/resource_snapshots/repo/sources/20240624123902.json similarity index 69% rename from core/priv/resource_snapshots/repo/sources/20240624052524.json rename to core/priv/resource_snapshots/repo/sources/20240624123902.json index a00a2ac0..0b3a05ff 100644 --- a/core/priv/resource_snapshots/repo/sources/20240624052524.json +++ b/core/priv/resource_snapshots/repo/sources/20240624123902.json @@ -7,8 +7,8 @@ "source": "id", "references": null, "allow_nil?": false, - "primary_key?": true, - "generated?": false + "generated?": false, + "primary_key?": true }, { "default": "nil", @@ -18,26 +18,26 @@ "references": { "name": "sources_account_id_fkey", "table": "accounts", - "primary_key?": true, "schema": "public", + "on_delete": null, "multitenancy": { "global": null, - "strategy": null, - "attribute": null + "attribute": null, + "strategy": null }, + "primary_key?": true, "destination_attribute": "id", - "on_delete": null, - "on_update": null, "deferrable": false, - "match_with": null, - "match_type": null, "index?": false, + "match_type": null, + "match_with": null, + "on_update": null, "destination_attribute_default": null, "destination_attribute_generated": null }, "allow_nil?": false, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false }, { "default": "nil", @@ -46,18 +46,8 @@ "source": "type", "references": null, "allow_nil?": true, - "primary_key?": false, - "generated?": false - }, - { - "default": "nil", - "size": null, - "type": "utc_datetime_usec", - "source": "last_fetched_at", - "references": null, - "allow_nil?": true, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false }, { "default": "nil", @@ -66,23 +56,23 @@ "source": "web_base_url", "references": null, "allow_nil?": true, - "primary_key?": false, - "generated?": false + "generated?": false, + "primary_key?": false } ], "table": "sources", - "hash": "96F3446E8426859FE77A678B87AA805B508B548AE1F8B0801D28756118ED73BA", + "hash": "EB0A38D0F9AF31AF9385CAF39616928BD5CBEE449F68397681A0EB0CBC937E07", "repo": "Elixir.Canary.Repo", "identities": [], "schema": null, - "base_filter": null, - "check_constraints": [], - "custom_indexes": [], "multitenancy": { "global": null, - "strategy": null, - "attribute": null + "attribute": null, + "strategy": null }, + "base_filter": null, + "check_constraints": [], + "custom_indexes": [], "custom_statements": [], "has_create_action": true } \ No newline at end of file