Class: MatViews::Services::DeleteView

Inherits:
BaseService show all
Defined in:
lib/mat_views/services/delete_view.rb

Overview

Service that safely drops a PostgreSQL materialised view.

Options:

  • ‘cascade:` (Boolean, default: false) → drop with CASCADE instead of RESTRICT

  • ‘row_count_strategy:` (Symbol, default: :none) → one of `:estimated`, `:exact`, or `:none or nil` to control row count reporting

Returns a MatViews::ServiceResponse

Examples:

Drop a view if it exists

svc = MatViews::Services::DeleteView.new(defn, **options)
svc.call

Force drop with CASCADE

MatViews::Services::DeleteView.new(defn, cascade: true).call

via job, this is the typical usage and will create a run record in the DB

MatViews::Jobs::Adapter.enqueue(MatViews::Services::DeleteViewJob, definition.id, **options)

See Also:

Constant Summary

Constants inherited from BaseService

BaseService::ALLOWED_ROW_STRATEGIES, BaseService::DEFAULT_NIL_STRATEGY, BaseService::DEFAULT_ROW_STRATEGY, BaseService::UNKNOWN_ROW_COUNT

Instance Attribute Summary collapse

Attributes inherited from BaseService

#definition, #request, #response, #row_count_strategy, #use_transaction

Instance Method Summary collapse

Methods inherited from BaseService

#call

Constructor Details

#initialize(definition, cascade: false, row_count_strategy: :estimated) ⇒ DeleteView

Returns a new instance of DeleteView.

Parameters:

  • definition (MatViews::MatViewDefinition)
  • cascade (Boolean) (defaults to: false)

    drop with CASCADE instead of RESTRICT

  • row_count_strategy (Symbol, nil) (defaults to: :estimated)

    one of ‘:estimated`, `:exact`, or `nil` (default: `:estimated`)



43
44
45
46
# File 'lib/mat_views/services/delete_view.rb', line 43

def initialize(definition, cascade: false, row_count_strategy: :estimated)
  super(definition, row_count_strategy: row_count_strategy)
  @cascade = cascade ? true : false
end

Instance Attribute Details

#cascadeBoolean (readonly)

Whether to cascade the drop (default: false).

Returns:

  • (Boolean)


37
38
39
# File 'lib/mat_views/services/delete_view.rb', line 37

def cascade
  @cascade
end