From 1ba5b9ec41201450ca814efa840459f4b3e6dbcd Mon Sep 17 00:00:00 2001 From: shibao Date: Sat, 26 Nov 2022 20:37:10 -0500 Subject: [PATCH] remove step contexts and context notes --- lib/memex/contexts/context_note.ex | 35 ---------------- lib/memex/pipelines/step.ex | 5 +-- lib/memex/pipelines/step_context.ex | 41 ------------------- .../20220726002021_create_step_contexts.exs | 16 -------- .../20220726002129_create_context_notes.exs | 16 -------- 5 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 lib/memex/contexts/context_note.ex delete mode 100644 lib/memex/pipelines/step_context.ex delete mode 100644 priv/repo/migrations/20220726002021_create_step_contexts.exs delete mode 100644 priv/repo/migrations/20220726002129_create_context_notes.exs diff --git a/lib/memex/contexts/context_note.ex b/lib/memex/contexts/context_note.ex deleted file mode 100644 index cf8c7c9..0000000 --- a/lib/memex/contexts/context_note.ex +++ /dev/null @@ -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 diff --git a/lib/memex/pipelines/step.ex b/lib/memex/pipelines/step.ex index ae65c28..f7df400 100644 --- a/lib/memex/pipelines/step.ex +++ b/lib/memex/pipelines/step.ex @@ -5,8 +5,7 @@ defmodule Memex.Pipelines.Step do use Ecto.Schema import Ecto.Changeset alias Ecto.{Changeset, UUID} - alias Memex.{Accounts.User, Contexts.Context} - alias Memex.Pipelines.{Pipeline, StepContext} + alias Memex.{Accounts.User, Pipelines.Pipeline} @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id @@ -18,8 +17,6 @@ defmodule Memex.Pipelines.Step do belongs_to :pipeline, Pipeline belongs_to :user, User - many_to_many :contexts, Context, join_through: StepContext - timestamps() end diff --git a/lib/memex/pipelines/step_context.ex b/lib/memex/pipelines/step_context.ex deleted file mode 100644 index 82fa58d..0000000 --- a/lib/memex/pipelines/step_context.ex +++ /dev/null @@ -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 diff --git a/priv/repo/migrations/20220726002021_create_step_contexts.exs b/priv/repo/migrations/20220726002021_create_step_contexts.exs deleted file mode 100644 index 39620fd..0000000 --- a/priv/repo/migrations/20220726002021_create_step_contexts.exs +++ /dev/null @@ -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 diff --git a/priv/repo/migrations/20220726002129_create_context_notes.exs b/priv/repo/migrations/20220726002129_create_context_notes.exs deleted file mode 100644 index 6e7ff38..0000000 --- a/priv/repo/migrations/20220726002129_create_context_notes.exs +++ /dev/null @@ -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