English 中文(简体)
• 如何消除垃圾: 迁徙垃圾
原标题:How to disable db:schema:dump for migrations

我不想让铁路3号公司在我每次移徙时产生我的chem。 如何妥善处置?

增 编

最佳回答

如Alex Kaushovik所建议的那样,制定具体应用任务。

Create a file lib asksdb_schema_override (actual name doesn t matter, you need a .rake file in lib asks) with contents as below (credit to Matthew Bass for remove_task)

Rake::TaskManager.class_eval do
  def remove_task(task_name)
    @tasks.delete(task_name.to_s)
  end
end

Rake.application.remove_task( db:schema:dump )
namespace :db do
  namespace :schema do
    task :dump do
      # Overridden to do nothing
    end
  end
end
问题回答

对于那些在移民后仍寻求解脱垃圾堆放方式的人来说,现在第4号铁路有这样的布局:

config.active_record.dump_schema_after_migration = false

这将防止这种情况发生。 这一改动中增加了这一配置:

根据David Waller的答复作出的修改,保留了操作干.的能力:血清。 涵盖自动援引化物倾销的所有任务。 根据铁路3.2.14号相关任务,当你改变铁路版时,你希望确保任务定义仍然有效。

很严重的是,应当有一种可分开的自动化chem堆放场的选择。

Rake::TaskManager.class_eval do
  def remove_task(task_name)
    @tasks.delete(task_name.to_s)
  end

  Rake.application.remove_task("db:migrate")
  Rake.application.remove_task("db:rollback")
  Rake.application.remove_task("db:forward")
  Rake.application.remove_task("db:migrate:up")
  Rake.application.remove_task("db:migrate:down")

end

namespace :db do

  desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
  task :migrate => [:environment, :load_config] do
    ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
    ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration|
      ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
    end
    # db_namespace[ _dump ].invoke
  end

  desc  Rolls the schema back to the previous version (specify steps w/ STEP=n). 
  task :rollback => [:environment, :load_config] do
    step = ENV[ STEP ] ? ENV[ STEP ].to_i : 1
    ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
    # db_namespace[ _dump ].invoke
  end

  # desc  Pushes the schema to the next version (specify steps w/ STEP=n). 
  task :forward => [:environment, :load_config] do
    step = ENV[ STEP ] ? ENV[ STEP ].to_i : 1
    ActiveRecord::Migrator.forward(ActiveRecord::Migrator.migrations_paths, step)
    # db_namespace[ _dump ].invoke
  end

  namespace :migrate do

    # desc  Runs the "up" for a given migration VERSION. 
    task :up => [:environment, :load_config] do
      version = ENV[ VERSION ] ? ENV[ VERSION ].to_i : nil
      raise  VERSION is required  unless version
      ActiveRecord::Migrator.run(:up, ActiveRecord::Migrator.migrations_paths, version)
      # db_namespace[ _dump ].invoke
    end

    # desc  Runs the "down" for a given migration VERSION. 
    task :down => [:environment, :load_config] do
      version = ENV[ VERSION ] ? ENV[ VERSION ].to_i : nil
      raise  VERSION is required  unless version
      ActiveRecord::Migrator.run(:down, ActiveRecord::Migrator.migrations_paths, version)
      # db_namespace[ _dump ].invoke
    end

  end

end

<>I ve测试如下:

您可以修改铁路局内“数据库”。 对以下法典的表述:

Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby

By default on Ubuntu (and Ubuntu server) it is here: /var/lib/gems/1.8/gems/rails-x.x.x/lib/tasks/databases.rake.

经铁路检查的铁路为2.3.11号,但我确信,它也有铁路3.x.。

Another possible solution (didn t test):

Youssst t has t have modified Railways file, only below.

一种称为“压倒性_rake_task”的铁路板可以用来压倒“db:schema:dump”的铁路任务,如果铁路轮.,该任务就是在内部确定的。

显然,如果你不使用这一假想,如果你以同样的名义在铁路应用中确定一项任务,便会执行两项任务:违约和你。

活性记录的缺省行为是丢弃该表,但只有将化石堆的垃圾堆放到废墟(违约)。

You can disable the schema dump after migrations by setting the schema format to sql. You can safely reverse it to ruby after the migration finishes without consequences.

你们可以这样做:

(1) 您的行文如明文 the为 rub:

config.active_record.schema_format = :ruby

(it could be inside config/application.rb, on config/environment or in the specific environment you are running the migration in).

接着评论:

#config.active_record.schema_format = :ruby

2) 然后添加一条线,在你使用的环境中或在座标/申请中确定SQ格式。 页: 1

config.active_record.schema_format = :sql

不要凌驾于 d行为(在你重新建立移民发展时显然是必要的,但在部署时没有必要) 我建议制定一项单独的任务,如:

# http://stackoverflow.com/questions/13646840/how-to-make-rake-dbmigrate-generate-schema-rb-when-using-sql-schema-format
namespace :db do
  desc "Migrate the database, without dumping the schema.rb"
  task :deploy => :environment do
    ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
    ActiveRecord::Migrator.migrate("db/migrate/", nil)
  end
end

然后,在你部署期间,你只能做事。

rake db:deploy




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签