From c26d10563eaa29961ae895a9fbe3afae7d24a9b1 Mon Sep 17 00:00:00 2001 From: Pete Deffendol Date: Sat, 3 May 2008 21:41:10 -0600 Subject: PostgreSQL: update rake tasks to use full settings from database.yml Signed-off-by: Michael Koziarski --- railties/lib/tasks/databases.rake | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 20fdcce205..63f71448f8 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -46,7 +46,7 @@ namespace :db do @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8' begin ActiveRecord::Base.establish_connection(config.merge('database' => 'template1')) - ActiveRecord::Base.connection.create_database(config['database'], :encoding => @encoding) + ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding)) ActiveRecord::Base.establish_connection(config) rescue $stderr.puts $!, *($!.backtrace) @@ -314,14 +314,9 @@ namespace :db do ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"]) when "postgresql" - ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] - ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] - ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"] - enc_option = "-E #{abcs["test"]["encoding"]}" if abcs["test"]["encoding"] - ActiveRecord::Base.clear_active_connections! - `dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` - `createdb #{enc_option} -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}` + drop_database(abcs['test']) + create_database(abcs['test']) when "sqlite","sqlite3" dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"] File.delete(dbfile) if File.exist?(dbfile) -- cgit v1.2.3 From 4a07103687084496b773e18a03b1f2f5e686f7ad Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Sun, 4 May 2008 12:53:50 +0200 Subject: Add 'script/dbconsole' -- the database analog of 'script/console' --- railties/bin/dbconsole | 3 +++ railties/lib/commands/dbconsole.rb | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 railties/bin/dbconsole create mode 100644 railties/lib/commands/dbconsole.rb (limited to 'railties') diff --git a/railties/bin/dbconsole b/railties/bin/dbconsole new file mode 100755 index 0000000000..caa60ce829 --- /dev/null +++ b/railties/bin/dbconsole @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/dbconsole' diff --git a/railties/lib/commands/dbconsole.rb b/railties/lib/commands/dbconsole.rb new file mode 100644 index 0000000000..03477f9b69 --- /dev/null +++ b/railties/lib/commands/dbconsole.rb @@ -0,0 +1,49 @@ +require 'optparse' +OptionParser.new do |opt| + opt.banner = "Usage: dbconsole [environment]" + opt.parse!(ARGV) + abort opt.to_s unless (0..1).include?(ARGV.size) +end + +env = ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development' + +def find_cmd(*commands) + dirs_on_path = ENV['PATH'].split(File::PATH_SEPARATOR) + commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/ + commands.detect do |cmd| + dirs_on_path.detect do |path| + File.executable? File.join(path, cmd) + end + end || abort("couldn't find matching executable: #{commands.join(', ')}") +end + + +require 'yaml' +config = YAML::load(File.read(RAILS_ROOT + "/config/database.yml"))[env] + +unless config + abort "No database is configured for the environment '#{env}'" +end + +case config["adapter"] +when "mysql" + exec(find_cmd(*%w(mysql5 mysql)), + *({ 'host' => '--host', + 'port' => '--port', + 'socket' => '--socket', + 'username' => '--user', + 'password' => '--password', + 'encoding' => '--default-character-set' + }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact + + [config['database']])) +when "postgresql" + ENV['PGHOST'] = config["host"] if config["host"] + ENV['PGPORT'] = config["port"].to_s if config["port"] + ENV['PGPASSWORD'] = config["password"].to_s if config["password"] + exec(find_cmd('psql'), '-U', config["username"], config["database"]) +when "sqlite" + exec(find_cmd('sqlite'), config["database"]) +when "sqlite3" + exec(find_cmd('sqlite3'), config["database"]) +else abort "not supported for this database type" +end -- cgit v1.2.3 From b510d8bfd8355e63432514814e3177244a26275a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 7 May 2008 12:46:03 -0700 Subject: Add script/dbconsole to app generator --- railties/CHANGELOG | 2 ++ .../lib/rails_generator/generators/applications/app/app_generator.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index f52206d4d3..2ca1965d97 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* script/dbconsole fires up the command-line database client. #102 [Steve Purcell] + * Fix bug where plugin init.rb files from frozen gem specs weren't being run. (pjb3) [#122 state:resolved] * Made the location of the routes file configurable with config.routes_configuration_file (Scott Fleckenstein) [#88] diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 85c417f7cd..2f2dd82682 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -72,7 +72,7 @@ class AppGenerator < Rails::Generator::Base m.file "environments/test.rb", "config/environments/test.rb" # Scripts - %w( about console destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file| + %w( about console dbconsole destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file| m.file "bin/#{file}", "script/#{file}", script_options end -- cgit v1.2.3 From 2561732a08ae97fa44706a8eca4db147c4a7c286 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 7 May 2008 13:50:46 -0700 Subject: Some dbconsole tweaks. [#102 state:resolved] --- railties/lib/commands/dbconsole.rb | 46 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'railties') diff --git a/railties/lib/commands/dbconsole.rb b/railties/lib/commands/dbconsole.rb index 03477f9b69..28c3a3e41f 100644 --- a/railties/lib/commands/dbconsole.rb +++ b/railties/lib/commands/dbconsole.rb @@ -1,49 +1,55 @@ +require 'yaml' require 'optparse' + OptionParser.new do |opt| opt.banner = "Usage: dbconsole [environment]" opt.parse!(ARGV) abort opt.to_s unless (0..1).include?(ARGV.size) end -env = ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development' +env = ARGV.first || ENV['RAILS_ENV'] || 'development' +unless config = YAML.load_file(RAILS_ROOT + "/config/database.yml")[env] + abort "No database is configured for the environment '#{env}'" +end + def find_cmd(*commands) - dirs_on_path = ENV['PATH'].split(File::PATH_SEPARATOR) + dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR) commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/ commands.detect do |cmd| dirs_on_path.detect do |path| File.executable? File.join(path, cmd) end - end || abort("couldn't find matching executable: #{commands.join(', ')}") + end || abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.") end +case config["adapter"] +when "mysql" + args = { + 'host' => '--host', + 'port' => '--port', + 'socket' => '--socket', + 'username' => '--user', + 'password' => '--password', + 'encoding' => '--default-character-set' + }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact -require 'yaml' -config = YAML::load(File.read(RAILS_ROOT + "/config/database.yml"))[env] + args << config['database'] -unless config - abort "No database is configured for the environment '#{env}'" -end + exec(find_cmd('mysql5', 'mysql'), *args) -case config["adapter"] -when "mysql" - exec(find_cmd(*%w(mysql5 mysql)), - *({ 'host' => '--host', - 'port' => '--port', - 'socket' => '--socket', - 'username' => '--user', - 'password' => '--password', - 'encoding' => '--default-character-set' - }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact + - [config['database']])) when "postgresql" ENV['PGHOST'] = config["host"] if config["host"] ENV['PGPORT'] = config["port"].to_s if config["port"] ENV['PGPASSWORD'] = config["password"].to_s if config["password"] exec(find_cmd('psql'), '-U', config["username"], config["database"]) + when "sqlite" exec(find_cmd('sqlite'), config["database"]) + when "sqlite3" exec(find_cmd('sqlite3'), config["database"]) -else abort "not supported for this database type" + +else + abort "Unknown command-line client for #{config['database']}. Submit a Rails patch to add support!" end -- cgit v1.2.3 From dc4eec1129520ce9863c9373d7cb79d8636ab7ca Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 9 May 2008 10:38:02 +0100 Subject: Merge docrails: commit e6afd8b2736364322b673bbdcca3e9b38b6d3da0 Author: Xavier Noria Date: Thu May 8 23:49:36 2008 +0200 Overall documentation improvement and markup corrections. Zillion changes. commit 2fead68b3192332eee27945ed95a94a64ca73f70 Author: Austin Putman Date: Wed May 7 19:35:46 2008 -0700 Documented class methods on ActionController::Routing. These are dangerous, and mostly used for testing. commit f5b84182dbc39bea79c8ee319c688d00fa99f9d1 Author: Teflon Ted Date: Wed May 7 16:08:49 2008 -0400 Added explanation about errant inflections not being patched in the future in order to avoid breaking legacy applications. commit 370f4f51722cec49ace17093d29e9ce9e8f15cfb Author: Sunny Ripert Date: Wed May 7 14:00:59 2008 +0200 Applied list conventions in AR::Base commit 5bd18429f09d44e75191bec42a6db04bd33f3030 Author: Sunny Ripert Date: Wed May 7 13:53:35 2008 +0200 Renamed Options list to Attributes list whenever they weren't option hashes in AR::Base commit d912bd5672316454457ae83f6e9dda5197beeb6f Author: Yaroslav Markin Date: Wed May 7 13:50:28 2008 +0400 Add a filter_parameter_logging usage hint to generated ApplicationController. This may help to remind the developer to filter sensitive information from application logs. Closes #11578 commit b243de0db3c2605121e055079854af5090d06374 Author: Jack Danger Canty Date: Tue May 6 23:39:47 2008 -0700 doc: disambiguating an example ActiveRecord class commit f81d771f0657ae8375b84a77a059812cce5d6fd9 Author: Jack Danger Canty Date: Tue May 6 23:35:05 2008 -0700 doc: ActiveRecord::Reflection::AssociationReflection#through_reflection Added documentation demonstrating the use of #through_reflection for finding intervening reflection objects for HasManyThrough and HasOneThrough. commit ae6b46f00b5b8b2939c6b37ce3329c83de7e71db Author: Cheah Chu Yeow Date: Wed May 7 13:47:41 2008 +0800 Document AttributeAssignmentError and MultiparameterAssignmentErrors. commit 8f463550b597db2156b67733f31aed13487fbc3a Author: John Barnette Date: Tue May 6 22:46:44 2008 -0700 Killing/fixing a bunch of outdated language in the AR README. commit aca44bcd92ef783abdf484b58abdde6786db0f89 Author: Cheah Chu Yeow Date: Wed May 7 13:34:52 2008 +0800 Make a note about ActiveResource::Timeouterror being raised when ARes calls timeout. commit 284a930a93fbee16e25d06392779dbf2f03e9e12 Author: Jonathan Dance Date: Tue May 6 14:58:26 2008 -0400 improvements to the page caching docs commit 9482da621390c874da7c921c8bd6230caae7035a Author: Sunny Ripert Date: Mon May 5 18:13:40 2008 +0200 validates_numericality_of() "integer" option really is "only_integer" commit e9afd6790a8f530528f6597a7f59bb283be754f6 Author: Sunny Ripert Date: Mon May 5 12:11:59 2008 +0200 Harmonized hash notation in AR::Base commit 67ebf14a91ffd970b582be4ff2991d691a9cf3e1 Author: Sunny Ripert Date: Mon May 5 12:06:19 2008 +0200 Turned options into rdoc-lists in AR::Base commit 0ec7c0a41d889d4e5382b9dff72f1aaba89bf297 Author: Marshall Huss Date: Sun May 4 23:21:33 2008 -0400 Added information of how to set element_name in the case the user has a name confliction with an existing model Signed-off-by: Pratik Naik --- railties/helpers/application.rb | 5 +++++ railties/lib/initializer.rb | 8 +++++--- railties/lib/rails/plugin.rb | 16 ++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) (limited to 'railties') diff --git a/railties/helpers/application.rb b/railties/helpers/application.rb index 9a79f69a41..0a3ed822a4 100644 --- a/railties/helpers/application.rb +++ b/railties/helpers/application.rb @@ -7,4 +7,9 @@ class ApplicationController < ActionController::Base # See ActionController::RequestForgeryProtection for details # Uncomment the :secret if you're not using the cookie session store protect_from_forgery # :secret => '<%= app_secret %>' + + # See ActionController::Base for details + # Uncomment this to filter the contents of submitted sensitive data parameters + # from your application log (in this case, all fields with names like "password"). + # filter_parameter_logging :password end diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 6db96f0158..dfd43042be 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -572,11 +572,13 @@ module Rails attr_accessor :plugin_loader # Enables or disables plugin reloading. You can get around this setting per plugin. - # If reload_plugins? is false, add this to your plugin's init.rb to make it reloadable: + # If reload_plugins? is false, add this to your plugin's init.rb + # to make it reloadable: # # Dependencies.load_once_paths.delete lib_path # - # If reload_plugins? is true, add this to your plugin's init.rb to only load it once: + # If reload_plugins? is true, add this to your plugin's init.rb + # to only load it once: # # Dependencies.load_once_paths << lib_path # @@ -676,7 +678,7 @@ module Rails YAML::load(ERB.new(IO.read(database_configuration_file)).result) end - # The path to the current environment's file (development.rb, etc.). By + # The path to the current environment's file (development.rb, etc.). By # default the file is at config/environments/#{environment}.rb. def environment_path "#{root_path}/config/environments/#{environment}.rb" diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index b45ec7de0e..04f7e37a20 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,14 +1,14 @@ module Rails # The Plugin class should be an object which provides the following methods: # - # * +name+ - used during initialisation to order the plugin (based on name and - # the contents of config.plugins) - # * +valid?+ - returns true if this plugin can be loaded - # * +load_paths+ - each path within the returned array will be added to the $LOAD_PATH - # * +load+ - finally 'load' the plugin. + # * +name+ - Used during initialisation to order the plugin (based on name and + # the contents of config.plugins). + # * +valid?+ - Returns true if this plugin can be loaded. + # * +load_paths+ - Each path within the returned array will be added to the $LOAD_PATH. + # * +load+ - Finally 'load' the plugin. # # These methods are expected by the Rails::Plugin::Locator and Rails::Plugin::Loader classes. - # The default implementation returns the lib directory as its load_paths, + # The default implementation returns the lib directory as its load_paths, # and evaluates init.rb when load is called. # # You can also inspect the about.yml data programmatically: @@ -31,13 +31,13 @@ module Rails File.directory?(directory) && (has_lib_directory? || has_init_file?) end - # Returns a list of paths this plugin wishes to make available in $LOAD_PATH + # Returns a list of paths this plugin wishes to make available in $LOAD_PATH. def load_paths report_nonexistant_or_empty_plugin! unless valid? has_lib_directory? ? [lib_path] : [] end - # Evaluates a plugin's init.rb file + # Evaluates a plugin's init.rb file. def load(initializer) return if loaded? report_nonexistant_or_empty_plugin! unless valid? -- cgit v1.2.3