Closed jrweb247 closed 6 years ago
@jrweb247, hi!
This gem is not a standalone solution and aimed to be used with existing applications that are using ActiveRecord (Ruby on Rails or Sinatra or anything).
In case of Rails, this gem is intended to use an existing configuration of your application. So just configure your database.yml
or specify DATABASE_URL
environment variable.
If you want to use it as a standalone application, you can place exerything in single file like this:
#!/usr/bin/env ruby
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord'
gem 'evil-seed'
gem 'mysql2'
end
require 'tempfile'
class Category < ActiveRecord::Base
has_many :translations, class_name: "Category::Translation"
end
class Category::Translation < ActiveRecord::Base
belongs_to :category, inverse_of: :translations
end
EvilSeed.configure do |config|
config.root("Category", "id < ?", 1000)
end
ActiveRecord::Base.establish_connection(ENV.fetch("DATABASE_URL"))
EvilSeed.dump(File.join(__dir__, "dump.sql").to_s)
And launch it like so:
DATABASE_URL=mysql2://user:pass@host/db ruby path/to/your/script.rb
Here you need to
@jrweb247, feel free to reopen this issue if you have any questions left.
Hi,
I'm very interesting by your script but I not a ruby developer, so I don't know how to configure active records according to my mysql credentials !
thanks a lot