From 52e5e02ab6742da487e904b2e1d96c6a0c3f0eaa Mon Sep 17 00:00:00 2001 From: shibao Date: Mon, 25 Jul 2022 20:20:26 -0400 Subject: [PATCH] add step_context --- lib/memex/steps/step_context.ex | 21 +++++++++++++++++++ .../20220726002021_create_step_contexts.exs | 16 ++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lib/memex/steps/step_context.ex create mode 100644 priv/repo/migrations/20220726002021_create_step_contexts.exs diff --git a/lib/memex/steps/step_context.ex b/lib/memex/steps/step_context.ex new file mode 100644 index 0000000..0f14d6c --- /dev/null +++ b/lib/memex/steps/step_context.ex @@ -0,0 +1,21 @@ +defmodule Memex.Steps.StepContext do + use Ecto.Schema + import Ecto.Changeset + + @primary_key {:id, :binary_id, autogenerate: true} + @foreign_key_type :binary_id + schema "step_contexts" do + + field :step_id, :binary_id + field :context_id, :binary_id + + timestamps() + end + + @doc false + def changeset(step_context, attrs) do + step_context + |> cast(attrs, []) + |> validate_required([]) + end +end diff --git a/priv/repo/migrations/20220726002021_create_step_contexts.exs b/priv/repo/migrations/20220726002021_create_step_contexts.exs new file mode 100644 index 0000000..39620fd --- /dev/null +++ b/priv/repo/migrations/20220726002021_create_step_contexts.exs @@ -0,0 +1,16 @@ +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