Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "active_record"
- require 'logger'
- namespace :db do
- desc "Migrate the database ('VERSION=YYYMMDDHHIISS' migrates to specified Version)"
- task(:migrate => :environment) do
- log = Logger.new(STDOUT)
- log.level = Logger::INFO
- ActiveRecord::Base.logger = log
- ActiveRecord::Migration.verbose = true
- ActiveRecord::Migrator.migrate("db/migrate", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
- Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
- end
- namespace :schema do
- desc "Create a db/schema.rb file that can be portably used against any DB supported by AR (with 'SCHEMA=filename' the schema-file can be specified)"
- task :dump => :environment do
- require 'active_record/schema_dumper'
- File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
- end
- Rake::Task["db:schema:dump"].reenable
- end
- desc "Load a schema.rb file into the database (with 'SCHEMA=filename' the schema-file can be specified)"
- task :load => :environment do
- file = ENV['SCHEMA'] || "db/schema.rb"
- if File.exists?(file)
- load(file)
- else
- abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again.}
- end
- end
- end
- end
- task :environment do
- config_file = File.read("pfad/zur/config-datei")
- ActiveRecord::Base.establish_connection(
- :adapter => "mysql",
- :host => config_file.match(%r(.*\$GLOBAL_CONFIG\[.db.\]\[.host.\]\s*=\s*.(.*).;\s*\n))[1],
- :username => config_file.match(%r(.*\$GLOBAL_CONFIG\[.db.\]\[.user.\]\s*=\s*.(.*).;\s*\n))[1],
- :password => config_file.match(%r(.*\$GLOBAL_CONFIG\[.db.\]\[.pass.\]\s*=\s*.(.*).;\s*\n))[1],
- :database => config_file.match(%r(.*\$GLOBAL_CONFIG\[.db.\]\[.name.\]\s*=\s*.(.*).;\s*\n))[1]
- )
- end
Add Comment
Please, Sign In to add comment