Backend: - Migration: beacon_monitors table (binary_id PK, org/user FK, check_type, target_url, config, monitoring fields) - Schema: BeaconMonitor with changeset (pattern-matched port validation, check_type inclusion) - Query: BeaconMonitorQuery — composable scopes (by org, by user, by type, enabled, ordered, preloaded) - Context: Towerops.Beacons — CRUD, toggle, record_check_result (36/36 tests pass) Frontend: - User LiveView: /beacons — stream-based list, create/edit modals, toggle/delete actions - Admin LiveView: /admin/beacons — cross-org view with preloads (20/20 tests pass) - Form component: LiveComponent modal with validation - Helpers: check_type badges, status indicators, response time formatting - Router: user routes + admin route configured - Nav: sidebar + mobile links added - 30+ gettext translations Verification: compile ✓, format ✓, credo ✓, 56/56 new tests pass
34 lines
1.3 KiB
Elixir
34 lines
1.3 KiB
Elixir
defmodule Towerops.Repo.Migrations.CreateBeaconMonitors do
|
|
use Ecto.Migration
|
|
|
|
def change do
|
|
create table(:beacon_monitors, primary_key: false) do
|
|
add :id, :binary_id, primary_key: true
|
|
add :name, :string, null: false
|
|
|
|
add :organization_id, references(:organizations, type: :binary_id, on_delete: :delete_all),
|
|
null: false
|
|
|
|
add :user_id, references(:users, type: :binary_id, on_delete: :nilify_all), null: false
|
|
add :check_type, :string, null: false, default: "http"
|
|
add :target_url, :string, null: false
|
|
add :target_port, :integer
|
|
add :interval_seconds, :integer, null: false, default: 60
|
|
add :timeout_ms, :integer, null: false, default: 5000
|
|
add :config, :map, default: "{}"
|
|
add :enabled, :boolean, null: false, default: true
|
|
add :last_status, :string
|
|
add :last_response_time_ms, :float
|
|
add :last_checked_at, :utc_datetime_usec
|
|
add :checks_count, :integer, null: false, default: 0
|
|
add :failures_count, :integer, null: false, default: 0
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
|
|
create index(:beacon_monitors, [:organization_id])
|
|
create index(:beacon_monitors, [:user_id])
|
|
create index(:beacon_monitors, [:check_type])
|
|
create index(:beacon_monitors, [:enabled])
|
|
end
|
|
end
|