defmodule Core.Repo.Migrations.CreatePostsTable do
  use Ecto.Migration

  def change do
    create table(:posts, primary_key: false) do
      add :id, :uuid, primary_key: true
      add :tid, :text

      add :kind, :text, null: false
      add :body, :text, null: false

      # blog only fields
      add :slug, :text
      add :title, :text

      add :published_at, :utc_datetime_usec
      add :deleted_at, :utc_datetime_usec
      timestamps()
    end

    create index(:posts, [:kind])
    create unique_index(:posts, [:slug])
    create index(:posts, [:published_at])

    create index(
             :posts,
             ["((published_at at time zone 'UTC' at time zone 'America/New_York')::date)"],
             name: :posts_published_at_date_index
           )

    create index(:posts, [:deleted_at])
    create index(:posts, [:inserted_at])
    create index(:posts, [:updated_at])
  end
end