{"record":{"id":"10f9822004a08a96","repo":"discourse/discourse","slug":"error-the-database-must-be-started-before-it-can","errorCode":null,"errorMessage":"Error: the database must be started before it can be migrated.","messagePattern":"Error: the database must be started before it can be migrated\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/temporary_db.rb","lineNumber":162,"sourceCode":"    ENV[\"PATH\"] = \"#{pg_bin_path}:#{old_path}\"\n\n    yield\n  ensure\n    ENV[\"PGHOST\"] = old_host\n    ENV[\"PGUSER\"] = old_user\n    ENV[\"PGPORT\"] = old_port\n    ENV[\"DISCOURSE_DEV_DB\"] = old_dev_db\n    ENV[\"RAILS_DB\"] = old_rails_db\n    ENV[\"PATH\"] = old_path\n  end\n\n  def remove\n    raise \"Error: the database must be stopped before it can be removed\" if @started\n    FileUtils.rm_rf @pg_temp_path\n  end\n\n  def migrate\n    raise \"Error: the database must be started before it can be migrated.\" if !@started\n    ActiveRecord::Base.establish_connection(connection_hash)\n\n    puts \"Running migrations on blank database!\"\n\n    old_stdout = $stdout.clone\n    old_stderr = $stderr.clone\n    $stdout.reopen(File.new(\"/dev/null\", \"w\"))\n    $stderr.reopen(File.new(\"/dev/null\", \"w\"))\n\n    SeedFu.quiet = true\n    Rake::Task[\"db:migrate\"].invoke\n  ensure\n    $stdout.reopen(old_stdout) if old_stdout\n    $stderr.reopen(old_stderr) if old_stderr\n  end\n\n  private\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/discourse/discourse/blob/1b2d7253e854205d2c95c80b2c6a1cdd42e45059/lib/temporary_db.rb#L144-L180","documentation":"Error \"Error: the database must be started before it can be migrated.\" thrown in discourse/discourse.","triggerScenarios":"Thrown at lib/temporary_db.rb:162 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1b2d7253e854205d2c95c80b2c6a1cdd42e45059","analyzedAt":"2026-08-26T03:11:08.302Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}