-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup data structures for tracking tests
- Loading branch information
Showing
7 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
defmodule Polar.Machines do | ||
alias __MODULE__.Manager | ||
|
||
defdelegate create_cluster(params), | ||
to: Manager, | ||
as: :create | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule Polar.Machines.Assessment do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
alias Polar.Streams | ||
alias Polar.Machines.Check | ||
alias Polar.Machines.Cluster | ||
s | ||
|
||
schema "assessments" do | ||
field :current_state, :string, default: "created" | ||
|
||
belongs_to :check, Check | ||
belongs_to :cluster, Cluster | ||
|
||
belongs_to :version, Streams.Version | ||
|
||
timestamps(type: :utc_datetime) | ||
end | ||
|
||
@doc false | ||
def changeset(assessment, attrs) do | ||
assessment | ||
|> cast(attrs, [:current_state]) | ||
|> validate_required([:current_state]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule Polar.Machines.Check do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "checks" do | ||
field :slug, :string | ||
field :description, :string | ||
|
||
timestamps(type: :utc_datetime_usec) | ||
end | ||
|
||
@doc false | ||
def changeset(check, attrs) do | ||
check | ||
|> cast(attrs, [:slug, :description]) | ||
|> validate_required([:slug, :description]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defp Polar.Machines.Cluster do | ||
alias Polar.Repo | ||
alias Polar.Machines.Cluster | ||
|
||
def create(params) do | ||
%Cluster{} | ||
|> Cluster.changeset(params) | ||
|> Repo.insert() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule Polar.Repo.Migrations.CreateChecks do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:checks) do | ||
add :slug, :citext, null: false | ||
add :description, :citext, null: false | ||
|
||
timestamps(type: :utc_datetime_usec) | ||
end | ||
|
||
create index(:checks, [:slug], unique: true) | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
priv/repo/migrations/20240619130844_create_assessments.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Polar.Repo.Migrations.CreateAssessments do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:assessments) do | ||
add :current_state, :citext, default: "created", null: false | ||
|
||
add :check_id, references(:checks, on_delete: :restrict), null: false | ||
add :version_id, references(:versions, on_delete: :restrict), null: false | ||
add :cluster_id, references(:clusters, on_delete: :restrict), null: false | ||
|
||
timestamps(type: :utc_datetime_utc) | ||
end | ||
|
||
create index(:assessments, [:check_id]) | ||
create index(:assessments, [:version_id]) | ||
create index(:assessments, [:cluster_id]) | ||
|
||
create index(:assessments, [:check_id, :version_id], unique: true) | ||
end | ||
end |