Skip to content

Commit

Permalink
add discord in client table
Browse files Browse the repository at this point in the history
  • Loading branch information
yujonglee committed Jun 24, 2024
1 parent 66733d5 commit 4b08cc2
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 89 deletions.
21 changes: 19 additions & 2 deletions core/lib/canary/clients/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
41 changes: 41 additions & 0 deletions core/priv/repo/migrations/20240624123902_add_discord_client.exs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"source": "id",
"references": null,
"allow_nil?": false,
"primary_key?": true,
"generated?": false
"generated?": false,
"primary_key?": true
},
{
"default": "nil",
Expand All @@ -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",
Expand All @@ -46,8 +46,8 @@
"source": "type",
"references": null,
"allow_nil?": true,
"primary_key?": false,
"generated?": false
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"source": "id",
"references": null,
"allow_nil?": false,
"primary_key?": true,
"generated?": true
"generated?": true,
"primary_key?": true
},
{
"default": "nil",
Expand All @@ -17,8 +17,8 @@
"source": "updated_at",
"references": null,
"allow_nil?": true,
"primary_key?": false,
"generated?": false
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
Expand All @@ -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",
Expand All @@ -56,28 +56,28 @@
"source": "source_url",
"references": null,
"allow_nil?": true,
"primary_key?": false,
"generated?": false
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "content",
"references": null,
"allow_nil?": true,
"primary_key?": false,
"generated?": false
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"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",
Expand All @@ -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": [
{
Expand All @@ -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
}
Loading

0 comments on commit 4b08cc2

Please sign in to comment.