defmodule CommonsPub.Blocks.Block do use Pointers.Pointable, otp_app: :cpub_blocks, table_id: "B10CK1NGSTVFFAV01DSSEE1NG1", source: "cpub_blocks_block" require Pointers.Changesets alias CommonsPub.Blocks.Block alias Pointers.{Changesets, Pointer} pointable_schema do belongs_to :blocker, Pointer belongs_to :blocked, Pointer end @defaults [ cast: [:blocker_id, :blocked_id], required: [:blocker_id, :blocked_id], ] def changeset(block \\ %Block{}, attrs, opts \\ []), do: Changesets.auto(block, attrs, opts, @defaults) end defmodule CommonsPub.Blocks.Block.Migration do import Ecto.Migration import Pointers.Migration alias CommonsPub.Blocks.Block @block_table Block.__schema__(:source) def migrate_block(index_opts \\ [], dir \\ direction()) def migrate_block(index_opts, :up) do index_opts = Keyword.put_new(index_opts, :using, "hash") create_pointable_table(Block) do add :blocker_id, strong_pointer() add :blocked_id, strong_pointer() end create index(@block_table, [:blocker_id], index_opts) create index(@block_table, [:blocked_id], index_opts) create unique_index(@block_table, [:blocker_id, :blocked_id], index_opts) end def migrate_block(index_opts, :down) do drop unique_index(@block_table, [:blocker_id, :blocked_id], index_opts) drop index(@block_table, [:blocked_id], index_opts) drop index(@block_table, [:blocker_id], index_opts) drop_pointable_table(Follow) end end