An application that loads when using a sql dump to create a test database.

Due to some non-standard options for creating a table, I have to use a sql dump instead of the standard schema.rb (i.e., I uncommented this line in environment.rb config.active_record.schema_format = :sql). I noticed that when I use the sql dump, my devices are not loading into the database. Some data is loaded into it, but I'm not sure where it comes from. This is normal? and if this is normal, will someone tell me where this other data comes from?

+3
source share
2 answers

If you load the database from the script you dumped, that should be all there. If you see anything else, I will try to reset db and recreate it from the script to make sure.

Alternatively, if you just want to load appliances, you can run:

rake db:fixtures:load

Update:

You might want to find a way to include your options in the migration. In my experience, it almost always pays off to do things with rails. If this helps, I would add custom options for using the mysql cluster using the: options option for create table:

class CreateYourTable < ActiveRecord::Migration
  def self.up
    create_table :your_table, :options => "ENGINE=NDBCLUSTER" do |t|
    #...
  end 
end
0
source

This is a very old question, but even after almost 10 years the answer remains the same - it seems that the devices ignore the format of the circuit and are hard-coded to search for YAML files. Here is the Rake task with Rails 5.2-stable:

https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/railties/databases.rake#L198

214 Dir["#{fixtures_dir}/**/*.yml"] , .yml.

SQL , YAML yaml_db - . , :

namespace :db do
  desc 'Convert development DB to Rails test fixtures'
  task to_fixtures: :environment do
    TABLES_TO_SKIP = %w[ar_internal_metadata delayed_jobs schema_info schema_migrations].freeze

    begin
      ActiveRecord::Base.establish_connection
      ActiveRecord::Base.connection.tables.each do |table_name|
        next if TABLES_TO_SKIP.include?(table_name)

        conter = '000'
        file_path = "#{Rails.root}/test/fixtures/#{table_name}.yml"
        File.open(file_path, 'w') do |file|
          rows = ActiveRecord::Base.connection.select_all("SELECT * FROM #{table_name}")
          data = rows.each_with_object({}) do |record, hash|
            suffix = record['id'].blank? ? conter.succ! : record['id']
            hash["#{table_name.singularize}_#{suffix}"] = record
          end
          puts "Writing table '#{table_name}' to '#{file_path}'"
          file.write(data.to_yaml)
        end
      end
    ensure
      ActiveRecord::Base.connection.close if ActiveRecord::Base.connection
    end
  end
end

16 2017 . . - lib/tasks/to_fixtures.rake. SQL / , RAILS_ENV=test bundle exec rake db:to_fixtures. Rails 5.2.3.

0

All Articles