class MaintenancePoliciesController
Manages maintenance policies: reusable maintenance definitions that can be applied to many tables at once, creating or updating their plans. CRUD plus an apply action with a preview; each action authorizes with Pundit.
Public Instance Methods
Source
# File app/controllers/maintenance_policies_controller.rb, line 67 def apply authorize @policy, :apply? ids = Array(params[:iceberg_table_ids]).reject(&:blank?) result = @policy.apply_to!(IcebergTable.where(id: ids)) notice = t("policies.notices.applied", created: result[:created], updated: result[:updated]) notice += " #{result[:skipped]} #{t('policies.notices.skipped')}" if result[:skipped].positive? redirect_to @policy, notice: notice end
Applies the policy to a set of tables at once, creating/updating their plans.
Source
# File app/controllers/maintenance_policies_controller.rb, line 95 def bulk_apply authorize MaintenancePolicy, :apply? policy = MaintenancePolicy.find(params[:policy_id]) ids = Array(params[:iceberg_table_ids]).reject(&:blank?) if ids.empty? redirect_to iceberg_tables_path, alert: t("policies.notices.no_tables_selected") return end result = policy.apply_to!(IcebergTable.where(id: ids)) notice = t("policies.notices.applied", created: result[:created], updated: result[:updated]) notice += " #{result[:skipped]} #{t('policies.notices.skipped')}" if result[:skipped].positive? redirect_to iceberg_tables_path, notice: notice end
Bulk apply from the tables index: select tables β pick a policy β apply.
Source
# File app/controllers/maintenance_policies_controller.rb, line 30 def create authorize MaintenancePolicy @policy = MaintenancePolicy.new(policy_params) if @policy.save redirect_to @policy, notice: t("policies.notices.created") else render :new, status: :unprocessable_content end end
Creates a policy and redirects to it, or re-renders the form on failure.
Source
# File app/controllers/maintenance_policies_controller.rb, line 60 def destroy authorize @policy @policy.destroy redirect_to maintenance_policies_path, notice: t("policies.notices.destroyed") end
Destroys the policy and redirects to the policies index.
Source
# File app/controllers/maintenance_policies_controller.rb, line 81 def detach authorize @policy, :detach? plan = @policy.maintenance_plans.find_by(id: params[:maintenance_plan_id]) if plan.nil? redirect_to @policy, alert: t("policies.notices.detach_not_found") return end plan.update!(maintenance_policy: nil) redirect_to @policy, notice: t("policies.notices.detached") end
Detaches a plan from this policy: the plan keeps its current cron and steps but stops following the policyβs chain-wide defaults. The plan is not deleted β it becomes a standalone, manually-managed plan.
Source
# File app/controllers/maintenance_policies_controller.rb, line 42 def edit authorize @policy end
Renders the edit form for a policy.
Source
# File app/controllers/maintenance_policies_controller.rb, line 8 def index authorize MaintenancePolicy @policies = MaintenancePolicy.order(:name) end
Lists all maintenance policies ordered by name.
Source
# File app/controllers/maintenance_policies_controller.rb, line 24 def new authorize MaintenancePolicy @policy = MaintenancePolicy.new end
Renders the form for creating a maintenance policy.
Source
# File app/controllers/maintenance_policies_controller.rb, line 15 def show authorize @policy @plans = @policy.maintenance_plans.includes(:iceberg_table) @candidates = IcebergTable.includes(:catalog, maintenance_plan: :maintenance_policy) .order(:namespace, :name) @apply_preview = preview_for(@policy, @candidates) end
Shows a policy with its derived plans, candidate tables, and a preview of what applying the policy would do.
Source
# File app/controllers/maintenance_policies_controller.rb, line 48 def update authorize @policy if @policy.update(policy_params) # Propagate to the plans derived from this policy. count = @policy.propagate! redirect_to @policy, notice: t("policies.notices.updated", count: count) else render :edit, status: :unprocessable_content end end
Updates the policy, propagates the change to its derived plans, and redirects, or re-renders the form on failure.