{"record":{"id":"67978700f0c21ff2","repo":"scenic-views/scenic","slug":"version-is-required","errorCode":null,"errorMessage":"version is required","messagePattern":"version is required","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/scenic/statements.rb","lineNumber":164,"sourceCode":"    # Update a database view to a new version using `CREATE OR REPLACE VIEW`.\n    #\n    # The existing view is replaced using the supplied `version`\n    # parameter.\n    #\n    # Does not work with materialized views due to lack of database support.\n    #\n    # @param name [String, Symbol] The name of the database view.\n    # @param version [Fixnum] The version number of the view.\n    # @param revert_to_version [Fixnum] The version number to rollback to on\n    #   `rake db rollback`\n    # @return The database response from executing the create statement.\n    #\n    # @example\n    #   replace_view :engagement_reports, version: 3, revert_to_version: 2\n    #\n    def replace_view(name, version: nil, revert_to_version: nil, materialized: false)\n      if version.blank?\n        raise ArgumentError, \"version is required\"\n      end\n\n      if materialized\n        raise ArgumentError, \"Cannot replace materialized views\"\n      end\n\n      sql_definition = definition(name, version)\n\n      Scenic.database.replace_view(name, sql_definition)\n    end\n\n    private\n\n    def definition(name, version)\n      Scenic::Definition.new(name, version).to_sql\n    end\n\n    def materialized_options(materialized)","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/scenic-views/scenic/blob/f2162dbddb0fb0eb5d4b04d640dcec5303a387e8/lib/scenic/statements.rb#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the version whose definition file exists: replace_view :engagement_reports, version: 3 loads db/views/engagement_reports_v03.sql","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","If you wanted inline SQL rather than version files, replace_view is the wrong method - use update_view :name, sql_definition: 'SELECT ...' instead"],"exampleFix":"# before (ArgumentError: version is required)\nreplace_view :engagement_reports, revert_to_version: 2\n\n# after: loads db/views/engagement_reports_v03.sql\nreplace_view :engagement_reports, version: 3, revert_to_version: 2","handlingStrategy":"validation","validationCode":"version = 3\npath = Rails.root.join(format('db/views/engagement_reports_v%02d.sql', version))\nabort 'version is required and its definition file must exist' if version.nil? || !File.exist?(path)\nreplace_view :engagement_reports, version: version, revert_to_version: 2","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Learn replace_view's contract: version-only, no sql_definition keyword","Generate the definition file first (rails g scenic:view name) so the version number is concrete before writing the migration","Code-review scenic migrations for missing required keywords; they surface only when the migration runs"],"tags":["rails","migration","argument-error","scenic","keyword-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"f2162dbddb0fb0eb5d4b04d640dcec5303a387e8","analyzedAt":"2026-08-23T09:20:35.041Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}