Method: ActiveRecord::Migration#drop_view

Defined in:
lib/pg_trunk/operations/views/drop_view.rb

#drop_view(name, **options) {|v| ... } ⇒ void

This method returns an undefined value.

Drop a view

The operation drops the existing view identified by its qualified name (it can include a schema).

drop_view "views.admin_users"

To make the operation invertible, use the same options as in the create_view operation.

drop_view "views.admin_users" do |v|
  v.sql_definition "SELECT name, email FROM users WHERE admin;"
  v.check :local
  v.comment "Admin users only"
end

You can also use a version-base SQL definition like:

drop_view "views.admin_users", revert_to_version: 1

With the force: :cascade option the operation would remove all the objects which depend on the view.

drop_view "views.admin_users", force: :cascade

With the if_exists: true option the operation won't fail even when the view was absent in the database.

drop_view "views.admin_users", if_exists: true

Both options make an operation irreversible due to uncertainty of the previous state of the database.

Parameters:

  • (nil) The qualified name of the view

  • a customizable set of options

Options Hash (**options):

  • :replace_existing (Boolean) — default: false

    If the view should overwrite an existing one

  • :if_exists (Boolean) — default: false

    Suppress the error when the view is absent

  • :force (Symbol) — default: :restrict

    How to process dependent objects (:cascade or :restrict)

  • :sql_definition (#to_s) — default: nil

    The snippet containing the query

  • :revert_to_version (#to_i) — default: nil

    The alternative way to set sql_definition by referencing to a file containing the snippet

  • :check (#to_s) — default: nil

    Controls the behavior of automatically updatable views Supported values: :local, :cascaded

  • :comment (#to_s) — default: nil

    The comment describing the view

Yields:

  • (v)

    the block with the view's definition

Yield Parameters:

  • Object

    receiver of methods specifying the view



58
# File 'lib/pg_trunk/operations/views/drop_view.rb', line 58

def drop_view(name, **options, &block); end