vendredi 23 octobre 2015

Heroku create db with default data

I'm noobie in rails and I have a problem with db. My database.yml:

    development:
      adapter: sqlite3
      database: db/development.sqlite3
      pool: 5
      timeout: 5000

    test:
      adapter: sqlite3
      database: db/test.sqlite3
      pool: 5
      timeout: 5000

    production:
      adapter: sqlite3
      database: db/production.sqlite3
      pool: 5
      timeout: 5000

And I succeeded in filling my db with this

    namespace :db do
      desc "Erase and fill database"
      task :populate => :environment do
        require 'populator'
        require 'faker'

        [Country, Region, City, Turbaza].each(&:delete_all)

        ActiveRecord::Base.transaction do
          Country.populate 5 do |country|
            country.name = Faker::Address.country
            Region.populate 1..2 do |region|
              region.country_id = country.id
              region.name = Faker::Address.state
              City.populate 1..2 do |city|
                city.region_id = region.id
                city.name = Faker::Address.city
                Turbaza.populate 1..2 do |turbaza|
                  turbaza.city_id = city.id
                  turbaza.name = Populator.words(1..3).titleize
                end
              end
            end
          end
        end
      end
    end

So I've got my development db filled with data, but I cannot understand how I can do this to my production db and. Please, could anyone help me with this?

Aucun commentaire:

Enregistrer un commentaire