Skip to content

Commit

Permalink
Rebase, rename the world
Browse files Browse the repository at this point in the history
  • Loading branch information
nshoes committed Nov 28, 2024
1 parent d3db206 commit 5b70ac5
Show file tree
Hide file tree
Showing 56 changed files with 418 additions and 418 deletions.
4 changes: 2 additions & 2 deletions lib/nerves_hub/accounts/remove_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule NervesHub.Accounts.RemoveAccount do
alias NervesHub.{
Accounts,
Firmwares,
Deployments.DeploymentGroup,
ManagedDeployments.DeploymentGroup,
Products,
Repo,
OrgKey,
Expand All @@ -25,7 +25,7 @@ defmodule NervesHub.Accounts.RemoveAccount do
|> Multi.delete_all(:invites, &query_by_org_id(Invite, &1))
|> Multi.delete_all(:device_certificates, &query_by_org_id(DeviceCertificate, &1))
|> Multi.delete_all(:ca_certificates, &query_by_org_id(CACertificate, &1))
|> Multi.delete_all(:deployments, &query_by_org_id(DeploymentGroup, &1))
|> Multi.delete_all(:deployment_groups, &query_by_org_id(DeploymentGroup, &1))
|> Multi.delete_all(:firmware_deltas, &query_firmware_deltas/1)
|> Multi.delete_all(:firmware_transfers, &query_by_org_id(FirmwareTransfer, &1))
|> Multi.merge(&delete_firmwares/1)
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ defmodule NervesHub.Application do
defp deployments_supervisor("test"), do: []

defp deployments_supervisor(_) do
[NervesHub.Deployments.Supervisor]
[NervesHub.ManagedDeployments.Supervisor]
end

defp endpoints("test") do
Expand Down
2 changes: 1 addition & 1 deletion lib/nerves_hub/audit_logs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule NervesHub.AuditLogs do
import Ecto.Query

alias NervesHub.AuditLogs.AuditLog
alias NervesHub.Deployments.DeploymentGroup
alias NervesHub.ManagedDeployments.DeploymentGroup
alias NervesHub.Repo
alias NimbleCSV.RFC4180, as: CSV

Expand Down
12 changes: 6 additions & 6 deletions lib/nerves_hub/audit_logs/templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule NervesHub.AuditLogs.Templates do
def audit_resolve_changed_deployment(device, reference_id) do
description =
if device.deployment_id do
"device #{device.identifier} reloaded deployment and is attached to deployment #{device.deployment.name}"
"device #{device.identifier} reloaded deployment and is attached to deployment #{device.deployment_group.name}"
else
"device #{device.identifier} reloaded deployment and is no longer attached to a deployment"
end
Expand All @@ -13,18 +13,18 @@ defmodule NervesHub.AuditLogs.Templates do
end

def audit_device_deployment_update_triggered(device, reference_id) do
deployment = device.deployment
firmware = deployment.firmware
deployment_group = device.deployment_group
firmware = deployment_group.firmware

description =
"deployment #{deployment.name} update triggered device #{device.identifier} to update firmware #{firmware.uuid}"
"deployment #{deployment_group.name} update triggered device #{device.identifier} to update firmware #{firmware.uuid}"

AuditLogs.audit_with_ref!(deployment, device, description, reference_id)
AuditLogs.audit_with_ref!(deployment_group, device, description, reference_id)
end

def audit_device_assigned(device, reference_id) do
description =
"device #{device.identifier} reloaded deployment and is attached to deployment #{device.deployment.name}"
"device #{device.identifier} reloaded deployment and is attached to deployment #{device.deployment_group.name}"

AuditLogs.audit_with_ref!(device, device, description, reference_id)
end
Expand Down
15 changes: 0 additions & 15 deletions lib/nerves_hub/deployments/inflight_deployment_check.ex

This file was deleted.

19 changes: 0 additions & 19 deletions lib/nerves_hub/deployments/supervisor.ex

This file was deleted.

20 changes: 10 additions & 10 deletions lib/nerves_hub/devices.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ defmodule NervesHub.Devices do
alias NervesHub.Accounts.User
alias NervesHub.AuditLogs
alias NervesHub.Certificate
alias NervesHub.Deployments.DeploymentGroup
alias NervesHub.Deployments.Orchestrator
alias NervesHub.ManagedDeployments.DeploymentGroup
alias NervesHub.ManagedDeployments.Orchestrator
alias NervesHub.Devices.CACertificate
alias NervesHub.Devices.Alarms
alias NervesHub.Devices.Connections
Expand Down Expand Up @@ -85,12 +85,12 @@ defmodule NervesHub.Devices do
|> where([d], d.product_id == ^product_id)
|> join(:left, [d], o in assoc(d, :org))
|> join(:left, [d, o], p in assoc(d, :product))
|> join(:left, [d, o, p], dp in assoc(d, :deployment))
|> join(:left, [d, o, p], dp in assoc(d, :deployment_group))
|> join(:left, [d, o, p, dp], f in assoc(dp, :firmware))
|> Repo.exclude_deleted()
|> order_by(^sort_devices(sorting))
|> filtering(filters)
|> preload([d, o, p, dp, f], org: o, product: p, deployment: {dp, firmware: f})
|> preload([d, o, p, dp, f], org: o, product: p, deployment_group: {dp, firmware: f})
|> Connections.preload_latest_connection()
|> Flop.run(flop)
end
Expand Down Expand Up @@ -313,7 +313,7 @@ defmodule NervesHub.Devices do
{:error, :not_found}

device ->
{:ok, Repo.preload(device, [:org, :product, deployment: [:firmware]])}
{:ok, Repo.preload(device, [:org, :product, deployment_group: [:firmware]])}
end
end

Expand All @@ -340,9 +340,9 @@ defmodule NervesHub.Devices do
|> where(identifier: ^identifier)
|> where(org_id: ^org_id)
|> join(:left, [d], o in assoc(d, :org))
|> join(:left, [d], dp in assoc(d, :deployment))
|> join(:left, [d], dp in assoc(d, :deployment_group))
|> join_and_preload(preload_assoc)
|> preload([d, o, dp], org: o, deployment: dp)
|> preload([d, o, dp], org: o, deployment_group: dp)
end

defp join_and_preload(query, nil), do: query
Expand Down Expand Up @@ -765,7 +765,7 @@ defmodule NervesHub.Devices do
end

def resolve_update(device) do
deployment = Repo.preload(device.deployment, [:firmware])
deployment = Repo.preload(device.deployment_group, [:firmware])

case verify_update_eligibility(device, deployment) do
{:ok, _device} ->
Expand All @@ -776,7 +776,7 @@ defmodule NervesHub.Devices do
update_available: true,
firmware_url: url,
firmware_meta: meta,
deployment: deployment,
deployment_group: deployment,
deployment_id: deployment.id
}

Expand Down Expand Up @@ -819,7 +819,7 @@ defmodule NervesHub.Devices do

def matches_deployment?(_, _), do: false

@spec update_deployment(Device.t(), Deployment.t()) :: Device.t()
@spec update_deployment(Device.t(), DeploymentGroup.t()) :: Device.t()
def update_deployment(device, deployment) do
device
|> Ecto.Changeset.change()
Expand Down
4 changes: 2 additions & 2 deletions lib/nerves_hub/devices/device.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule NervesHub.Devices.Device do
alias NervesHub.Devices.DeviceCertificate
alias NervesHub.Devices.DeviceConnection
alias NervesHub.Extensions.ExtensionsSetting
alias NervesHub.Deployments.DeploymentGroup
alias NervesHub.ManagedDeployments.DeploymentGroup
alias NervesHub.Firmwares.FirmwareMetadata
alias NervesHub.Products.Product

Expand Down Expand Up @@ -39,7 +39,7 @@ defmodule NervesHub.Devices.Device do
schema "devices" do
belongs_to(:org, Org, where: [deleted_at: nil])
belongs_to(:product, Product, where: [deleted_at: nil])
belongs_to(:deployment, DeploymentGroup)
belongs_to(:deployment_group, DeploymentGroup, foreign_key: :deployment_id)
embeds_one(:firmware_metadata, FirmwareMetadata, on_replace: :update)
has_many(:device_certificates, DeviceCertificate, on_delete: :delete_all)
has_many(:device_connections, DeviceConnection, on_delete: :delete_all)
Expand Down
4 changes: 2 additions & 2 deletions lib/nerves_hub/devices/inflight_update.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ defmodule NervesHub.Devices.InflightUpdate do

alias NervesHub.Devices.Device
alias NervesHub.Devices.InflightUpdate
alias NervesHub.Deployments.DeploymentGroup
alias NervesHub.ManagedDeployments.DeploymentGroup
alias NervesHub.Firmwares.Firmware

@required_params [:device_id, :deployment_id, :firmware_id, :firmware_uuid, :expires_at]

schema "inflight_updates" do
belongs_to(:device, Device)
belongs_to(:deployment, DeploymentGroup)
belongs_to(:deployment_group, DeploymentGroup, foreign_key: :deployment_id)
belongs_to(:firmware, Firmware)

field(:firmware_uuid, Ecto.UUID)
Expand Down
8 changes: 4 additions & 4 deletions lib/nerves_hub/devices/update_payload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule NervesHub.Devices.UpdatePayload do
"""

alias NervesHub.Firmwares.FirmwareMetadata
alias NervesHub.Deployments.DeploymentGroup
alias NervesHub.ManagedDeployments.DeploymentGroup

@derive {Jason.Encoder,
only: [
Expand All @@ -17,22 +17,22 @@ defmodule NervesHub.Devices.UpdatePayload do
defstruct update_available: false,
firmware_url: nil,
firmware_meta: nil,
deployment: nil,
deployment_group: nil,
deployment_id: nil

@type t ::
%__MODULE__{
update_available: false,
firmware_meta: nil,
firmware_url: nil,
deployment: nil,
deployment_group: nil,
deployment_id: nil
}
| %__MODULE__{
update_available: true,
firmware_meta: FirmwareMetadata.t(),
firmware_url: String.t(),
deployment: DeploymentGroup.t(),
deployment_group: DeploymentGroup.t(),
deployment_id: non_neg_integer()
}
end
10 changes: 5 additions & 5 deletions lib/nerves_hub/firmwares/firmware.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule NervesHub.Firmwares.Firmware do

alias NervesHub.Accounts.Org
alias NervesHub.Accounts.OrgKey
alias NervesHub.Deployments.DeploymentGroup
alias NervesHub.ManagedDeployments.DeploymentGroup
alias NervesHub.Products.Product

alias __MODULE__
Expand Down Expand Up @@ -46,7 +46,7 @@ defmodule NervesHub.Firmwares.Firmware do
belongs_to(:org, Org, where: [deleted_at: nil])
belongs_to(:product, Product, where: [deleted_at: nil])
belongs_to(:org_key, OrgKey)
has_many(:deployments, DeploymentGroup)
has_many(:deployment_groups, DeploymentGroup)

field(:architecture, :string)
field(:author, :string)
Expand All @@ -68,20 +68,20 @@ defmodule NervesHub.Firmwares.Firmware do
|> cast(params, @required_params ++ @optional_params)
|> validate_required(@required_params)
|> unique_constraint(:uuid, name: :firmwares_product_id_uuid_index)
|> foreign_key_constraint(:deployments, name: :deployments_firmware_id_fkey)
|> foreign_key_constraint(:deployment_groups, name: :deployment_groups_firmware_id_fkey)
end

def update_changeset(%Firmware{} = firmware, params) do
firmware
|> cast(params, @required_params ++ @optional_params)
|> validate_required(@required_params)
|> unique_constraint(:uuid, name: :firmwares_product_id_uuid_index)
|> foreign_key_constraint(:deployments, name: :deployments_firmware_id_fkey)
|> foreign_key_constraint(:deployment_groups, name: :deployment_groups_firmware_id_fkey)
end

def delete_changeset(%Firmware{} = firmware, params) do
firmware
|> cast(params, @required_params ++ @optional_params)
|> no_assoc_constraint(:deployments, message: "Firmware has associated deployments")
|> no_assoc_constraint(:deployment_groups, message: "Firmware has associated deployments")
end
end
Loading

0 comments on commit 5b70ac5

Please sign in to comment.