balls/priv/repo/migrations/20241119124303_initial.exs

54 lines
1.7 KiB
Elixir

defmodule BallsPDS.Repo.Migrations.Initial do
use Ecto.Migration
def change do
create table(:agents) do
add :acl, :text, null: false
add :public_key, :text, null: false
add :disabled, :boolean, default: false, null: false
timestamps()
end
create unique_index(:agents, [:acl])
create table(:objects) do
# Fake path that always resembles a slash-separated, slash-prepended filesystem path.
add :path, :text, null: false
add :content_type, :text, null: false
# Mainly used to identify collections.
add :activitypub_type, :text
# In practice, filename on filesystem. Null for collections.
add :storage_key, :text
# Query shortcut for public objects to avoid join.
add :public, :boolean, default: false, null: false
# Only used for collections to avoid counting.
add :total_items, :integer
timestamps()
end
create unique_index(:objects, [:path])
create index(:objects, [:activitypub_type])
# Who can read an object (only the owner can write right now.)
create table(:object_read_agents, primary_key: false) do
add :object_id, references(:objects), null: false
add :agent_id, references(:agents), null: false
end
create unique_index(:object_read_agents, [:object_id, :agent_id])
create table(:collection_objects) do
add :collection_id, references(:objects), null: false
add :object_id, references(:objects)
add :remote_id, :string
# Results are sorted in ascending order on this arbitrary value.
add :order_num, :integer
end
create unique_index(:collection_objects, [:collection_id, :remote_id])
end
end