{"record":{"id":"79ca1a13277dfa4c","repo":"scenic-views/scenic","slug":"define-view-query-in-path-before-migrating","errorCode":null,"errorMessage":"Define view query in #{path} before migrating.","messagePattern":"Define view query in #(.+?) before migrating\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"lib/scenic/definition.rb","lineNumber":12,"sourceCode":"module Scenic\n  # @api private\n  class Definition\n    def initialize(name, version)\n      @name = name.to_s\n      @version = version.to_i\n    end\n\n    def to_sql\n      File.read(full_path).tap do |content|\n        if content.empty?\n          raise \"Define view query in #{path} before migrating.\"\n        end\n      end\n    end\n\n    def full_path\n      Rails.root.join(path)\n    end\n\n    def path\n      File.join(\"db\", \"views\", filename)\n    end\n\n    def version\n      @version.to_s.rjust(2, \"0\")\n    end\n\n    private\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/scenic-views/scenic/blob/f2162dbddb0fb0eb5d4b04d640dcec5303a387e8/lib/scenic/definition.rb#L1-L30","documentation":"Scenic resolves each view's SQL from db/views/<name>_vNN.sql (version zero-padded to two digits) under Rails.root. Definition#to_sql reads that file and raises RuntimeError ('Define view query in <path> before migrating.') when the content is empty. The scenic:view generator deliberately scaffolds an empty stub for you to fill in, and migrating before writing the SELECT into it triggers this. A missing file raises Errno::ENOENT instead - this message means the file exists but has zero bytes.","triggerScenarios":"Running rails g scenic:view searches followed by db:migrate without editing db/views/searches_v01.sql; bumping to create_view :searches, version: 2 while db/views/searches_v02.sql is empty; a definition file truncated to zero bytes by a bad merge, editor crash, or file-sync tool.","commonSituations":"Committing the generated stub so CI's migration job hits it; a merge conflict resolved by keeping an empty side; definition files emptied by sync or filter processes (LFS, Docker copy, formatting hooks).","solutions":["Open the exact path named in the message and write the view query (for example: SELECT id, email FROM users WHERE active;)","If the version file was never created, run rails g scenic:view <name> (add --materialized for matviews), fill the stub, then migrate","If content was lost in a merge or sync, recover it from git history: git log --oneline -- db/views/searches_v01.sql and restore the last non-empty revision"],"exampleFix":"# before: db/views/searches_v01.sql exists but is empty\n# migration => Define view query in db/views/searches_v01.sql before migrating.\n\n# after: db/views/searches_v01.sql\nSELECT id, email FROM users WHERE active;","handlingStrategy":"validation","validationCode":"Dir[Rails.root.join('db/views/*.sql')].each do |f|\n  abort f + ' is empty; fill in the view query before migrating' if File.read(f).strip.empty?\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enhance db:migrate with a preflight task that aborts on any empty db/views/*.sql","Never commit a generated view stub without its query; review generator output before pushing","When CI hits this error, check git status for zero-byte definition files caused by merges or sync tools"],"tags":["rails","migration","scenic","filesystem","configuration"],"backgroundTag":"empty-definition-file","analyzedSha":"f2162dbddb0fb0eb5d4b04d640dcec5303a387e8","analyzedAt":"2026-08-23T09:20:35.041Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}