FIX: migrations-tooling CLI didn't work anymore (#29777)

The previous approach of splitting Thor commands into multiple files caused problems when the same method name was used in multiple commands.

This also loads the Rails environment only for commands that need it. That makes the CLI boot faster for most commands or when the help should be shown. That's also why we can't use `Rails.root` in the CLI.
This commit is contained in:
Gerhard Schlager
2024-11-19 23:51:53 +01:00
committed by GitHub
parent a8ca82b11f
commit 75f4a14568
5 changed files with 114 additions and 96 deletions

View File

@ -1,15 +1,18 @@
# frozen_string_literal: true
module Migrations::CLI::ImportCommand
def self.included(thor)
thor.class_eval do
desc "import", "Import a file"
def import
require "extralite"
require "extralite"
puts "Importing into Discourse #{Discourse::VERSION::STRING}"
puts "Extralite SQLite version: #{Extralite.sqlite3_version}"
end
module Migrations::CLI
class ImportCommand
def initialize(options)
@options = options
end
def execute
::Migrations.load_rails_environment
puts "Importing into Discourse #{Discourse::VERSION::STRING}"
puts "Extralite SQLite version: #{Extralite.sqlite3_version}"
end
end
end