scenic-views/scenic · error · ArgumentError

version is required

Error message

version is required

What it means

replace_view always loads its SQL from a versioned definition file under db/views - unlike create_view and update_view it has no sql_definition parameter. If the version keyword is nil or blank when the statement runs, it raises ArgumentError ('version is required') before touching the database. Note the method signature accepts only name, version, revert_to_version, and materialized, so an inline sql_definition raises an unknown-keyword ArgumentError instead.

Source

Thrown at lib/scenic/statements.rb:164

    # Update a database view to a new version using `CREATE OR REPLACE VIEW`.
    #
    # The existing view is replaced using the supplied `version`
    # parameter.
    #
    # Does not work with materialized views due to lack of database support.
    #
    # @param name [String, Symbol] The name of the database view.
    # @param version [Fixnum] The version number of the view.
    # @param revert_to_version [Fixnum] The version number to rollback to on
    #   `rake db rollback`
    # @return The database response from executing the create statement.
    #
    # @example
    #   replace_view :engagement_reports, version: 3, revert_to_version: 2
    #
    def replace_view(name, version: nil, revert_to_version: nil, materialized: false)
      if version.blank?
        raise ArgumentError, "version is required"
      end

      if materialized
        raise ArgumentError, "Cannot replace materialized views"
      end

      sql_definition = definition(name, version)

      Scenic.database.replace_view(name, sql_definition)
    end

    private

    def definition(name, version)
      Scenic::Definition.new(name, version).to_sql
    end

    def materialized_options(materialized)

View on GitHub (pinned to f2162dbddb)

Solutions

  1. Pass the version whose definition file exists: replace_view :engagement_reports, version: 3 loads db/views/engagement_reports_v03.sql
  2. If the file does not exist yet, generate it first with rails g scenic:view engagement_reports, fill in the SQL, then reference that version
  3. If you wanted inline SQL rather than version files, replace_view is the wrong method - use update_view :name, sql_definition: 'SELECT ...' instead

Example fix

# before (ArgumentError: version is required)
replace_view :engagement_reports, revert_to_version: 2

# after: loads db/views/engagement_reports_v03.sql
replace_view :engagement_reports, version: 3, revert_to_version: 2
Defensive patterns

Strategy: validation

Validate before calling

version = 3
path = Rails.root.join(format('db/views/engagement_reports_v%02d.sql', version))
abort 'version is required and its definition file must exist' if version.nil? || !File.exist?(path)
replace_view :engagement_reports, version: version, revert_to_version: 2

Prevention

When it happens

Trigger: replace_view :engagement_reports with no version keyword; replace_view :engagement_reports, revert_to_version: 2 (version remains nil); a migration template that interpolates an unset variable, leaving version nil or an empty string (both blank), which fails the same check.

Common situations: Refactoring update_view calls into replace_view and assuming version is optional there too; ERB/template-generated migrations with a missing version variable; dropping the keyword during a copy-paste edit.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of scenic-views/scenic@f2162dbddb (2026-08-23). Data as JSON: /api/errors/67978700f0c21ff2. Report an issue: GitHub.