remove step contexts and context notes

This commit is contained in:
shibao 2022-11-26 20:37:10 -05:00
parent 443ff86aee
commit 1ba5b9ec41
5 changed files with 1 additions and 112 deletions

View File

@ -1,35 +0,0 @@
defmodule Memex.Contexts.ContextNote do
@moduledoc """
Represents a mapping of a note to a context
"""
use Ecto.Schema
import Ecto.Changeset
alias Memex.{Contexts.Context, Contexts.ContextNote, Notes.Note}
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "context_notes" do
belongs_to :context, Context
belongs_to :note, Note
timestamps()
end
@type t :: %ContextNote{
context: Context.t() | nil,
context_id: Context.id(),
note: Note.t(),
note_id: Note.id(),
inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t()
}
@type new_context_note :: %ContextNote{}
@doc false
def create_changeset(%Context{id: context_id}, %Note{id: note_id}) do
%ContextNote{}
|> change(context_id: context_id, note_id: note_id)
|> validate_required([:context_id, :note_id])
end
end

View File

@ -5,8 +5,7 @@ defmodule Memex.Pipelines.Step do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
alias Ecto.{Changeset, UUID} alias Ecto.{Changeset, UUID}
alias Memex.{Accounts.User, Contexts.Context} alias Memex.{Accounts.User, Pipelines.Pipeline}
alias Memex.Pipelines.{Pipeline, StepContext}
@primary_key {:id, :binary_id, autogenerate: true} @primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id @foreign_key_type :binary_id
@ -18,8 +17,6 @@ defmodule Memex.Pipelines.Step do
belongs_to :pipeline, Pipeline belongs_to :pipeline, Pipeline
belongs_to :user, User belongs_to :user, User
many_to_many :contexts, Context, join_through: StepContext
timestamps() timestamps()
end end

View File

@ -1,41 +0,0 @@
defmodule Memex.Pipelines.StepContext do
@moduledoc """
Represents a has-many relation between a step and related contexts
"""
use Ecto.Schema
import Ecto.Changeset
alias Ecto.{Changeset, UUID}
alias Memex.{Contexts.Context, Pipelines.Step}
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "step_contexts" do
belongs_to :step, Step
belongs_to :context, Context
timestamps()
end
@type t :: %__MODULE__{
step: Step.t() | Ecto.Association.NotLoaded.t(),
step_id: Step.id(),
context: Context.t() | Ecto.Association.NotLoaded.t(),
context_id: Context.id(),
inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t()
}
@type id :: UUID.t()
@type changeset :: Changeset.t(t())
@doc false
@spec create_changeset(Step.t(), Context.t()) :: changeset()
def create_changeset(
%Step{id: step_id, user_id: user_id},
%Context{id: context_id, user_id: user_id}
) do
%__MODULE__{}
|> change(step_id: step_id, context_id: context_id)
|> validate_required([:step_id, :context_id])
end
end

View File

@ -1,16 +0,0 @@
defmodule Memex.Repo.Migrations.CreateStepContexts do
use Ecto.Migration
def change do
create table(:step_contexts, primary_key: false) do
add :id, :binary_id, primary_key: true
add :step_id, references(:steps, on_delete: :nothing, type: :binary_id)
add :context_id, references(:contexts, on_delete: :nothing, type: :binary_id)
timestamps()
end
create index(:step_contexts, [:step_id])
create index(:step_contexts, [:context_id])
end
end

View File

@ -1,16 +0,0 @@
defmodule Memex.Repo.Migrations.CreateContextNotes do
use Ecto.Migration
def change do
create table(:context_notes, primary_key: false) do
add :id, :binary_id, primary_key: true
add :context_id, references(:contexts, on_delete: :nothing, type: :binary_id)
add :note_id, references(:notes, on_delete: :nothing, type: :binary_id)
timestamps()
end
create index(:context_notes, [:context_id])
create index(:context_notes, [:note_id])
end
end