Sha256: 3a769de0d1b42c9f81769dfcd453ce8d9b68a9e3656fbe3d160a5fe2798b2b96

Contents?: true

Size: 1.27 KB

Versions: 81

Compression:

Stored size: 1.27 KB

Contents

class Jets::Commands::Db::Tasks
  # Ugly but it loads ActiveRecord database tasks
  def self.load!
    # Lazy require rails so Rails const is only defined in jets db:* tasks
    require "rails"
    require "active_record"

    # Jets.boot # Jets.boot here screws up jets -h, the db_config doesnt seem to match exactly
    # but seems to be working anyway.
    db_configs = Jets.application.config.database
    ActiveRecord::Tasks::DatabaseTasks.database_configuration = db_configs
    ActiveRecord::Tasks::DatabaseTasks.migrations_paths = ["db/migrate"]
    ActiveRecord::Tasks::DatabaseTasks.seed_loader = Seeder.new("#{Jets.root}/db/seeds.rb")

    # Need to mock out the usage of Rails.application in:
    # activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb
    Rails.application = Dummy::App.new
    load "active_record/railties/databases.rake"
    load File.expand_path("../environment-task.rake", __FILE__)
  end


  # Thanks: https://stackoverflow.com/questions/19206764/how-can-i-load-activerecord-database-tasks-on-a-ruby-project-outside-rails/24840749
  class Seeder
    def initialize(seed_file)
      @seed_file = seed_file
    end

    def load_seed
      raise "Seed file '#{@seed_file}' does not exist" unless File.file?(@seed_file)
      load @seed_file
    end
  end
end

Version data entries

81 entries across 81 versions & 2 rubygems

Version Path
jets-4.0.12 lib/jets/commands/db/tasks.rb
jets-4.0.11 lib/jets/commands/db/tasks.rb
jets-4.0.10 lib/jets/commands/db/tasks.rb
jets-4.0.9 lib/jets/commands/db/tasks.rb
jets-4.0.8 lib/jets/commands/db/tasks.rb
jets-4.0.7 lib/jets/commands/db/tasks.rb
jets-4.0.6 lib/jets/commands/db/tasks.rb
jets-4.0.5 lib/jets/commands/db/tasks.rb
jets-4.0.4 lib/jets/commands/db/tasks.rb
jets-4.0.3 lib/jets/commands/db/tasks.rb
jets-4.0.2 lib/jets/commands/db/tasks.rb
jets-4.0.1 lib/jets/commands/db/tasks.rb
jets-4.0.0 lib/jets/commands/db/tasks.rb
jets-3.2.2 lib/jets/commands/db/tasks.rb
jets-3.2.1 lib/jets/commands/db/tasks.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/commands/db/tasks.rb
jets-3.2.0 lib/jets/commands/db/tasks.rb
jets-3.1.5 lib/jets/commands/db/tasks.rb
jets-3.1.4 lib/jets/commands/db/tasks.rb
jets-3.1.3 lib/jets/commands/db/tasks.rb