Skip to content

Commit

Permalink
All models to use public schema (#2249)
Browse files Browse the repository at this point in the history
* All models to use public schema

* Fix mailer test
  • Loading branch information
stuartc authored Jul 2, 2024
1 parent 7beff87 commit fd98017
Show file tree
Hide file tree
Showing 40 changed files with 97 additions and 174 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to

### Changed

- All models to use the `public` schema.
[#2249](https://github.com/OpenFn/lightning/pull/2249)
- In the workflow diagram, smartly update the view when adding new nodes
[#2174](https://github.com/OpenFn/lightning/issues/2174)
- In the workflow diagram, remove the "autofit" toggle in the control bar
Expand Down
5 changes: 1 addition & 4 deletions lib/lightning/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ defmodule Lightning.Accounts.User do
@moduledoc """
The User model.
"""
use Ecto.Schema
use Lightning.Schema

import Ecto.Changeset
import Ecto.Query
import EctoEnum

Expand All @@ -19,8 +18,6 @@ defmodule Lightning.Accounts.User do
:superuser
])

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "users" do
field :first_name, :string
field :last_name, :string
Expand Down
6 changes: 1 addition & 5 deletions lib/lightning/accounts/user_backup_code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ defmodule Lightning.Accounts.UserBackupCode do
User backup codes schema
"""

use Ecto.Schema
import Ecto.Changeset
use Lightning.Schema

@type t :: %__MODULE__{
id: Ecto.UUID.t() | nil
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id

schema "user_backup_codes" do
field :code, Lightning.Encrypted.Binary,
redact: true,
Expand Down
5 changes: 1 addition & 4 deletions lib/lightning/accounts/user_token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ defmodule Lightning.Accounts.UserToken do
session they deem invalid.
"""

use Ecto.Schema
use Lightning.Schema
use Joken.Config

import Ecto.Changeset
import Ecto.Query

alias Lightning.Accounts.User
Expand All @@ -37,8 +36,6 @@ defmodule Lightning.Accounts.UserToken do
@sudo_session_validity_in_seconds 60 * 5
@auth_validity_in_seconds 30

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "user_tokens" do
field :token, :binary
field :context, :string
Expand Down
6 changes: 1 addition & 5 deletions lib/lightning/accounts/user_totp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ defmodule Lightning.Accounts.UserTOTP do
@moduledoc """
User Time based OTPs schema
"""
use Ecto.Schema
import Ecto.Changeset
use Lightning.Schema

@type t :: %__MODULE__{
id: Ecto.UUID.t() | nil,
Expand All @@ -13,9 +12,6 @@ defmodule Lightning.Accounts.UserTOTP do
Lightning.Accounts.User.t() | Ecto.Association.NotLoaded.t() | nil
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id

schema "user_totps" do
field :secret, :binary, redact: true
field :code, :string, virtual: true
Expand Down
7 changes: 2 additions & 5 deletions lib/lightning/auditing/audit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ defmodule Lightning.Auditing.Audit do
@moduledoc """
Macro module to add common model behaviour to a given Ecto model
"""
use Ecto.Schema

import Ecto.Changeset
use Lightning.Schema

require Ecto.Query
require Logger
Expand Down Expand Up @@ -92,8 +90,7 @@ defmodule Lightning.Auditing.Audit do
defmodule Changes do
@moduledoc false

use Ecto.Schema
import Ecto.Changeset
use Lightning.Schema

@primary_key false
embedded_schema do
Expand Down
5 changes: 1 addition & 4 deletions lib/lightning/auth_providers/auth_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ defmodule Lightning.AuthProviders.AuthConfig do
@moduledoc """
AuthProvider model
"""
use Ecto.Schema
import Ecto.Changeset
use Lightning.Schema

@type t :: %__MODULE__{
__meta__: Ecto.Schema.Metadata.t(),
Expand All @@ -14,8 +13,6 @@ defmodule Lightning.AuthProviders.AuthConfig do
redirect_uri: String.t() | nil
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "auth_providers" do
field :name, :string

Expand Down
3 changes: 1 addition & 2 deletions lib/lightning/auth_providers/common.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ defmodule Lightning.AuthProviders.Common do
Defines a schema for OAuth token information.
"""

use Ecto.Schema
import Ecto.Changeset
use Lightning.Schema

@primary_key false
embedded_schema do
Expand Down
8 changes: 2 additions & 6 deletions lib/lightning/credentials/credential.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ defmodule Lightning.Credentials.Credential do
@moduledoc """
The Credential model.
"""
use Ecto.Schema

import Ecto.Changeset
use Lightning.Schema

alias Lightning.Accounts.User
alias Lightning.Credentials.OauthClient
Expand All @@ -16,8 +14,6 @@ defmodule Lightning.Credentials.Credential do
body: nil | %{}
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "credentials" do
field :name, :string
field :body, Lightning.Encrypted.Map, redact: true
Expand All @@ -31,7 +27,7 @@ defmodule Lightning.Credentials.Credential do
has_many :project_credentials, ProjectCredential
has_many :projects, through: [:project_credentials, :project]

timestamps(type: :utc_datetime)
timestamps()
end

@doc false
Expand Down
8 changes: 2 additions & 6 deletions lib/lightning/credentials/oauth_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ defmodule Lightning.Credentials.OauthClient do
projects through relational fields.
"""

use Ecto.Schema

import Ecto.Changeset
use Lightning.Schema

alias Lightning.Accounts.User
alias Lightning.Credentials.Credential
Expand All @@ -21,8 +19,6 @@ defmodule Lightning.Credentials.OauthClient do
name: String.t()
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "oauth_clients" do
field :name, :string
field :client_id, :string
Expand All @@ -42,7 +38,7 @@ defmodule Lightning.Credentials.OauthClient do
has_many :project_oauth_clients, ProjectOauthClient
has_many :projects, through: [:project_oauth_clients, :project]

timestamps(type: :utc_datetime)
timestamps()
end

@doc """
Expand Down
5 changes: 1 addition & 4 deletions lib/lightning/invocation/dataclip.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ defmodule Lightning.Invocation.Dataclip do
* `:saved_input`
An arbitrary input, created by a user. (Only configuration will be overwritten.)
"""
use Ecto.Schema
import Ecto.Changeset
use Lightning.Schema

alias Lightning.Invocation.Step
alias Lightning.Projects.Project
Expand All @@ -37,8 +36,6 @@ defmodule Lightning.Invocation.Dataclip do
@type source_type :: :http_request | :global | :step_result | :saved_input
@source_types [:http_request, :global, :step_result, :saved_input]

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "dataclips" do
field :body, :map, load_in_query: false
field :request, :map, load_in_query: false
Expand Down
5 changes: 1 addition & 4 deletions lib/lightning/invocation/log_line.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ defmodule Lightning.Invocation.LogLine do
See [`LogMessage`](`Lightning.LogMessage`) for more information.
"""
use Ecto.Schema

import Ecto.Changeset
use Lightning.Schema

alias Lightning.Invocation.Step
alias Lightning.LogMessage
Expand All @@ -33,7 +31,6 @@ defmodule Lightning.Invocation.LogLine do
only: [:id, :source, :level, :message, :timestamp, :step_id, :run_id]}

@primary_key false
@foreign_key_type :binary_id
schema "log_lines" do
field :id, Ecto.UUID
field :source, :string
Expand Down
6 changes: 1 addition & 5 deletions lib/lightning/invocation/run_step.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ defmodule Lightning.RunStep do
@moduledoc """
Ecto model for an the Steps in a Run.
"""
use Ecto.Schema

import Ecto.Changeset
use Lightning.Schema

alias Lightning.Invocation.Step
alias Lightning.Run
Expand All @@ -16,8 +14,6 @@ defmodule Lightning.RunStep do
step: Step.t() | Ecto.Association.NotLoaded.t()
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "run_steps" do
belongs_to :run, Run
belongs_to :step, Step
Expand Down
6 changes: 1 addition & 5 deletions lib/lightning/invocation/step.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ defmodule Lightning.Invocation.Step do
- `"exception"`
- `"lost"`
"""
use Ecto.Schema

import Ecto.Changeset
use Lightning.Schema

alias Lightning.Credentials.Credential
alias Lightning.Invocation.Dataclip
Expand All @@ -37,8 +35,6 @@ defmodule Lightning.Invocation.Step do
job: Job.t() | Ecto.Association.NotLoaded.t() | nil
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "steps" do
field :exit_reason, :string
field :error_type, :string
Expand Down
6 changes: 1 addition & 5 deletions lib/lightning/projects/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ defmodule Lightning.Projects.Project do
@moduledoc """
Project model
"""
use Ecto.Schema

import Ecto.Changeset
use Lightning.Schema

alias Lightning.Projects.ProjectCredential
alias Lightning.Projects.ProjectOauthClient
Expand All @@ -21,8 +19,6 @@ defmodule Lightning.Projects.Project do

@retention_periods [7, 14, 30, 90, 180, 365]

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "projects" do
field :name, :string
field :description, :string
Expand Down
6 changes: 1 addition & 5 deletions lib/lightning/projects/project_credential.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ defmodule Lightning.Projects.ProjectCredential do
@moduledoc """
Join table to assign credentials to a project
"""
use Ecto.Schema

import Ecto.Changeset
use Lightning.Schema

alias Lightning.Credentials.Credential
alias Lightning.Projects.Project
Expand All @@ -16,8 +14,6 @@ defmodule Lightning.Projects.ProjectCredential do
project: Project.t() | Ecto.Association.NotLoaded.t() | nil
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "project_credentials" do
belongs_to :credential, Credential
belongs_to :project, Project
Expand Down
6 changes: 1 addition & 5 deletions lib/lightning/projects/project_oauth_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ defmodule Lightning.Projects.ProjectOauthClient do
rules such as uniqueness of the association.
"""

use Ecto.Schema

import Ecto.Changeset
use Lightning.Schema

alias Lightning.Credentials.OauthClient
alias Lightning.Projects.Project
Expand All @@ -39,8 +37,6 @@ defmodule Lightning.Projects.ProjectOauthClient do
project: Project.t() | Ecto.Association.NotLoaded.t() | nil
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "project_oauth_clients" do
belongs_to :oauth_client, OauthClient
belongs_to :project, Project
Expand Down
5 changes: 1 addition & 4 deletions lib/lightning/projects/project_user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ defmodule Lightning.Projects.ProjectUser do
@moduledoc """
Join table to assign users to a project
"""
use Ecto.Schema
use Lightning.Schema

import Ecto.Changeset
import EctoEnum

alias Lightning.Accounts.User
Expand All @@ -31,8 +30,6 @@ defmodule Lightning.Projects.ProjectUser do
:monthly
])

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "project_users" do
belongs_to :user, User
belongs_to :project, Project
Expand Down
6 changes: 2 additions & 4 deletions lib/lightning/runs/handlers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ defmodule Lightning.Runs.Handlers do
@moduledoc """
Schema to validate the input attributes of a started step.
"""
use Ecto.Schema
import Ecto.Changeset
use Lightning.Schema
import Ecto.Query

import Lightning.ChangesetUtils
Expand Down Expand Up @@ -142,8 +141,7 @@ defmodule Lightning.Runs.Handlers do
@moduledoc """
Schema to validate the input attributes of a completed step.
"""
use Ecto.Schema
import Ecto.Changeset
use Lightning.Schema
import Ecto.Query

import Lightning.ChangesetUtils
Expand Down
5 changes: 1 addition & 4 deletions lib/lightning/runs/run.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ defmodule Lightning.Run do
"""
use Ecto.Schema
use Lightning.Schema

import Ecto.Changeset
import Lightning.Validators

alias Lightning.Accounts.User
Expand Down Expand Up @@ -45,8 +44,6 @@ defmodule Lightning.Run do
work_order: WorkOrder.t() | Ecto.Association.NotLoaded.t()
}

@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "runs" do
belongs_to :work_order, WorkOrder

Expand Down
Loading

0 comments on commit fd98017

Please sign in to comment.