title: Elixir Ecto.Schema error: __schema__/1 undefined
body: <p>I'm currently facing an error that I flat out do not understand--it's a symptom of something and I don't know conceptually what it might be. Here's what I think is the relevant code.</p>
  
  <p>In my model definition, I have:</p>
  
  <pre><code>defmodule EventBridge.Event do
    use Ecto.Schema
    use Timex.Ecto.Timestamps
  
    import Ecto
    import Ecto.Changeset
  
    alias Timex.Parse.DateTime.Parser
  
    schema "events" do
      field :occurred_at, Timex.Ecto.DateTime
      field :action, :string
      field :source_application, :string
      field :athlete_id, :integer
      field :coach_id, :integer
      field :detail, :string
      field :deleted, :integer, default: 0
      field :deleted_at, Timex.Ecto.DateTime
      field :partner_name, :string, default: "Source Partner 1"
      field :coach_email, :string
      field :coach_first_name, :string
      field :coach_last_name, :string
      field :coach_position, :string
      field :college_name, :string
      field :athlete_email, :string
      field :athlete_first_name, :string
      field :athlete_last_name, :string
      field :coach_sport, :map, default: %{}
      field :athlete_sport, :map, default: %{}
    end
  
    ...
  end
  </code></pre>
  
  <p>Here is the place where the error comes from:</p>
  
  <pre><code>defmodule EventBridge.Migrate.ProducerConsumer do
    use GenStage
  
    import Ecto.Query
    import Ecto.Changeset
    import Ecto.Query, only: [from: 1, from: 2]
  
    alias EventBridge.CoachActivityRepo
    alias EventBridge.Event
    alias EventBridge.C3poEvent
    alias EventBridge.SportsMap
    alias EventBridge.TimeUtils
  
    def start_link do
      GenStage.start_link(__MODULE__, :state_doesnt_matter, name: __MODULE__)
    end
  
    def init(number) do
      {:producer_consumer, number}
    end
  
    def handle_events(events, _from, number) do
      changesets = Enum.map(events, fn(event) -&gt;
        transform_event(event)
      end)
      |&gt; List.flatten()
  
      {:noreply, changesets, number}
    end
  
    #==========
    defp transform_event(%C3poEvent{action: "search appearance"} = c3po_event), do: search_appearance_event(c3po_event)
    defp transform_event(%C3poEvent{action: "view"} = c3po_event), do: view_event(c3po_event)
    defp transform_event(c3po_event), do: nil
    #==========
  
    defp single_event(c3po_event) do
      ...
    end
  
    defp search_appearance_event(c3po_event) do
      counter = real_count(c3po_event)
  
      case counter do
        x when x &gt; 0 -&gt;
          create_search_appearance_events(c3po_event, counter, [])
        x when x &lt; 0 -&gt;
          delete_search_appearance_events(c3po_event, counter)
        _ -&gt;
          []
      end
    end
  
    defp delete_search_appearance_events(c3po_event, counter) do
      from(t in CoachActivityRepo,      # ERROR FROM HERE
        where: t.athlete_id == ^c3po_event.athlete_id,
        where: t.coach_id == ^c3po_event.coach_id,
        where: t.action == 'search appearance',
        order_by: [desc: t.occurred_at],
        limit: ^counter,
        offset: 0)
      |&gt; CoachActivityRepo.delete_all
      []
    end
  
    defp create_search_appearance_events(c3po_event, counter, accumulator) do
      ...
    end
  
    defp shifted_datetime(days) do
      ...
    end
  
    defp view_event(c3po_event) do
      ...
    end
  
    defp convert_event_parameters(c3po_event, occurred_at) do
      ...
    end
    defp convert_event_parameters(c3po_event) do
      ...
    end
  
    defp real_count(c3po_event) do
      c3po_event - from(t in CoachActivityRepo,  # ERROR FROM HERE
        select: count(t.id),
        where: t.athlete_id == ^c3po_event.athlete_id,
        where: t.coach_id == ^c3po_event.coach_id,
        where: t.action == 'search appearance')
    end
  end
  </code></pre>
  
  <p>This is the Repo definition:</p>
  
  <pre><code>defmodule EventBridge.CoachActivityRepo do
   use Ecto.Repo, otp_app: :event_bridge
  end
  </code></pre>
  
  <p>I suspect this is too much information. I'm not looking for the Right Code here, I mostly want to know if anyone can describe what causes the original error in the case of a model being used. Do my </p>