Skip to content

Commit

Permalink
improvement: track actor tenant, use it for fetching actor
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Apr 5, 2024
1 parent 9ea3075 commit 34e7077
Show file tree
Hide file tree
Showing 18 changed files with 808 additions and 9,012 deletions.
3 changes: 3 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ Hooks.Actor = {
"actor_primary_key" + "=" + payload.primary_key + ";path=/";
document.cookie = "actor_action" + "=" + payload.action + ";path=/";
document.cookie = "actor_domain" + "=" + payload.domain + ";path=/";
document.cookie = "actor_tenant" + "=" + payload.tenant + ";path=/";
});
this.handleEvent("clear_actor", () => {
document.cookie = "actor_resource" + "=" + ";path=/";
document.cookie = "actor_primary_key" + "=" + ";path=/";
document.cookie = "actor_action" + ";path=/";
document.cookie = "actor_tenant" + ";path=/";
document.cookie = "actor_domain" + "=" + ";path=/";
document.cookie = "actor_authorizing=false;path=/";
document.cookie = "actor_paused=true;path=/";
Expand Down Expand Up @@ -169,6 +171,7 @@ let params = () => {
tenant: getCookie("tenant"),
actor_resource: getCookie("actor_resource"),
actor_primary_key: getCookie("actor_primary_key"),
actor_tenant: getCookie("actor_tenant"),
actor_action: getCookie("actor_action"),
actor_domain: getCookie("actor_domain"),
actor_authorizing: getCookie("actor_authorizing"),
Expand Down
107 changes: 107 additions & 0 deletions dev/repo/migrations/20240405104516_migrate_resources5.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
defmodule Demo.Repo.Migrations.MigrateResources5 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(:users) do
modify(:updated_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
modify(:inserted_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
modify(:id, :uuid, default: fragment("gen_random_uuid()"))
add(:org, :text)
end

alter table(:tickets) do
modify(:updated_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
modify(:inserted_at, :utc_datetime_usec, default: fragment("(now() AT TIME ZONE 'utc')"))
modify(:id, :uuid, default: fragment("gen_random_uuid()"))
end

drop(constraint(:ticket_comments, "ticket_comments_resource_id_fkey"))

alter table(:ticket_comments) do
modify(:id, :uuid, default: fragment("gen_random_uuid()"))

modify(
:resource_id,
references(:tickets, column: :id, name: "ticket_comments_resource_id_fkey", type: :uuid)
)
end

drop(constraint(:representative_comments, "representative_comments_resource_id_fkey"))

alter table(:representative_comments) do
modify(:id, :uuid, default: fragment("gen_random_uuid()"))

modify(
:resource_id,
references(:users,
column: :id,
name: "representative_comments_resource_id_fkey",
type: :uuid
)
)
end

alter table(:organizations) do
modify(:id, :uuid, default: fragment("gen_random_uuid()"))
end

execute(
"ALTER TABLE representative_comments alter CONSTRAINT representative_comments_resource_id_fkey NOT DEFERRABLE"
)

execute(
"ALTER TABLE ticket_comments alter CONSTRAINT ticket_comments_resource_id_fkey NOT DEFERRABLE"
)
end

def down do
alter table(:organizations) do
modify(:id, :uuid, default: fragment("uuid_generate_v4()"))
end

drop(constraint(:representative_comments, "representative_comments_resource_id_fkey"))

alter table(:representative_comments) do
modify(
:resource_id,
references(:users,
column: :id,
name: "representative_comments_resource_id_fkey",
type: :uuid
)
)

modify(:id, :uuid, default: fragment("uuid_generate_v4()"))
end

drop(constraint(:ticket_comments, "ticket_comments_resource_id_fkey"))

alter table(:ticket_comments) do
modify(
:resource_id,
references(:tickets, column: :id, name: "ticket_comments_resource_id_fkey", type: :uuid)
)

modify(:id, :uuid, default: fragment("uuid_generate_v4()"))
end

alter table(:tickets) do
modify(:id, :uuid, default: fragment("uuid_generate_v4()"))
modify(:inserted_at, :utc_datetime_usec, default: fragment("now()"))
modify(:updated_at, :utc_datetime_usec, default: fragment("now()"))
end

alter table(:users) do
remove(:org)
modify(:id, :uuid, default: fragment("uuid_generate_v4()"))
modify(:inserted_at, :utc_datetime_usec, default: fragment("now()"))
modify(:updated_at, :utc_datetime_usec, default: fragment("now()"))
end
end
end
39 changes: 39 additions & 0 deletions dev/resource_snapshots/repo/organizations/20240405104516.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"attributes": [
{
"default": "fragment(\"gen_random_uuid()\")",
"size": null,
"type": "uuid",
"source": "id",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": true
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "name",
"references": null,
"allow_nil?": true,
"generated?": false,
"primary_key?": false
}
],
"table": "organizations",
"hash": "FE04FAC17C7D0EDB0064F5735F42026A0C533C14D8F66C9E8B2E6C5A9831A041",
"repo": "Elixir.Demo.Repo",
"schema": null,
"identities": [],
"multitenancy": {
"global": 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
@@ -0,0 +1,123 @@
{
"attributes": [
{
"default": "fragment(\"gen_random_uuid()\")",
"size": null,
"type": "uuid",
"source": "id",
"references": null,
"allow_nil?": false,
"generated?": false,
"primary_key?": true
},
{
"default": "nil",
"size": null,
"type": "text",
"source": "comment",
"references": null,
"allow_nil?": true,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "resource_id",
"references": {
"name": "representative_comments_resource_id_fkey",
"table": "users",
"schema": null,
"multitenancy": {
"global": null,
"attribute": null,
"strategy": null
},
"on_update": null,
"primary_key?": true,
"on_delete": null,
"destination_attribute": "id",
"deferrable": false,
"match_type": null,
"match_with": null,
"destination_attribute_default": "fragment(\"gen_random_uuid()\")",
"destination_attribute_generated": false
},
"allow_nil?": false,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "commenting_customer_id",
"references": {
"name": "representative_comments_commenting_customer_id_fkey",
"table": "users",
"schema": "public",
"multitenancy": {
"global": null,
"attribute": null,
"strategy": null
},
"on_update": null,
"primary_key?": true,
"on_delete": null,
"destination_attribute": "id",
"deferrable": false,
"match_type": null,
"match_with": null,
"destination_attribute_default": null,
"destination_attribute_generated": null
},
"allow_nil?": true,
"generated?": false,
"primary_key?": false
},
{
"default": "nil",
"size": null,
"type": "uuid",
"source": "commenting_representative_id",
"references": {
"name": "representative_comments_commenting_representative_id_fkey",
"table": "users",
"schema": "public",
"multitenancy": {
"global": null,
"attribute": null,
"strategy": null
},
"on_update": null,
"primary_key?": true,
"on_delete": null,
"destination_attribute": "id",
"deferrable": false,
"match_type": null,
"match_with": null,
"destination_attribute_default": null,
"destination_attribute_generated": null
},
"allow_nil?": true,
"generated?": false,
"primary_key?": false
}
],
"table": "representative_comments",
"hash": "9FAEADC51CF57CA679CC932FC19C5204ED427748F5EB5A692669D6186E28A6C7",
"repo": "Elixir.Demo.Repo",
"schema": null,
"identities": [],
"multitenancy": {
"global": null,
"attribute": null,
"strategy": null
},
"base_filter": null,
"check_constraints": [],
"custom_indexes": [],
"custom_statements": [],
"has_create_action": true
}
Loading

0 comments on commit 34e7077

Please sign in to comment.