]> git.openstreetmap.org Git - rails.git/commitdiff
Make database offline mode work
authorTom Hughes <tom@compton.nu>
Tue, 15 Jun 2010 09:07:39 +0000 (10:07 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 15 Jun 2010 09:07:39 +0000 (10:07 +0100)
config/environment.rb
config/initializers/abstract_adapter.rb
config/initializers/postgresql_adapter.rb
config/initializers/query_cache.rb
config/initializers/sql_session_store.rb
vendor/plugins/deadlock_retry/init.rb
vendor/plugins/file_column/init.rb
vendor/plugins/validates_email_format_of/rails/init.rb

index 0a67be745582228590a6461f86282118558e8d5d..55c2df4ae4185ed2d28e3ef3e0faaf35659000bc 100644 (file)
@@ -51,7 +51,9 @@ Rails::Initializer.run do |config|
   # config.gem "bj"
   # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
   # config.gem "aws-s3", :lib => "aws/s3"
-  config.gem 'composite_primary_keys', :version => '2.2.2'
+  unless  OSM_STATUS == :database_offline
+    config.gem 'composite_primary_keys', :version => '2.2.2'
+  end
   config.gem 'libxml-ruby', :version => '>= 1.1.1', :lib => 'libxml'
   config.gem 'rmagick', :lib => 'RMagick'
   config.gem 'oauth', :version => '>= 0.3.6'
@@ -86,7 +88,9 @@ Rails::Initializer.run do |config|
   # Use the database for sessions instead of the cookie-based default,
   # which shouldn't be used to store highly confidential information
   # (create the session table with 'rake db:sessions:create')
-  config.action_controller.session_store = :sql_session_store
+  unless  OSM_STATUS == :database_offline
+    config.action_controller.session_store = :sql_session_store
+  end
 
   # Use SQL instead of Active Record's schema dumper when creating the test database.
   # This is necessary if your schema can't be completely dumped by the schema dumper,
index 5cc24d25c38489183a869661f7f3c68db3227a83..9042823c28ccd22995be969739a7d9cd93f19ad1 100644 (file)
@@ -1,24 +1,26 @@
-module ActiveRecord
-  module ConnectionAdapters
-    class AbstractAdapter
-    protected
-      alias_method :old_log, :log
-
-      def log(sql, name)
-        if block_given?
-          old_log(sql, name) do
-            yield
+if defined?(ActionRecord::ConnectionAdaptors::AbstractAdaptor)
+  module ActiveRecord
+    module ConnectionAdapters
+      class AbstractAdapter
+      protected
+        alias_method :old_log, :log
+  
+        def log(sql, name)
+          if block_given?
+            old_log(sql, name) do
+              yield
+            end
+          else
+            old_log(sql, name)
+          end
+        rescue ActiveRecord::StatementInvalid => ex
+          if ex.message =~ /^OSM::APITimeoutError: /
+            raise OSM::APITimeoutError.new
+          elsif ex.message =~ /^Timeout::Error: /
+            raise Timeout::Error.new("time's up!")
+          else
+            raise
           end
-        else
-          old_log(sql, name)
-        end
-      rescue ActiveRecord::StatementInvalid => ex
-        if ex.message =~ /^OSM::APITimeoutError: /
-          raise OSM::APITimeoutError.new
-        elsif ex.message =~ /^Timeout::Error: /
-          raise Timeout::Error.new("time's up!")
-        else
-          raise
         end
       end
     end
index c5a69a1d9baa3444ac16a3ddd12895bb5b399f26..b9adf38bbe60b2abca258702d63d3b7b1f12885c 100644 (file)
@@ -1,54 +1,56 @@
-module ActiveRecord
-  module ConnectionAdapters
-    class PostgreSQLAdapter
-      def pk_and_sequence_for(table)
-        # First try looking for a sequence with a dependency on the
-        # given table's primary key.
-        result = query(<<-end_sql, 'PK and serial sequence')[0]
-          SELECT attr.attname, seq.relname
-          FROM pg_class      seq,
-               pg_attribute  attr,
-               pg_depend     dep,
-               pg_namespace  name,
-               pg_constraint cons
-          WHERE seq.oid           = dep.objid
-            AND seq.relkind       = 'S'
-            AND attr.attrelid     = dep.refobjid
-            AND attr.attnum       = dep.refobjsubid
-            AND attr.attrelid     = cons.conrelid
-            AND attr.attnum       = cons.conkey[1]
-            AND cons.contype      = 'p'
-            AND dep.classid       = '"pg_class"'::regclass
-            AND dep.refclassid    = '"pg_class"'::regclass
-            AND dep.refobjid      = '#{quote_table_name(table)}'::regclass
-        end_sql
-
-        if result.nil? or result.empty?
-          # If that fails, try parsing the primary key's default value.
-          # Support the 7.x and 8.0 nextval('foo'::text) as well as
-          # the 8.1+ nextval('foo'::regclass).
-          result = query(<<-end_sql, 'PK and custom sequence')[0]
-            SELECT attr.attname,
-              CASE
-                WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
-                  substr(split_part(def.adsrc, '''', 2),
-                         strpos(split_part(def.adsrc, '''', 2), '.')+1)
-                ELSE split_part(def.adsrc, '''', 2)
-              END
-            FROM pg_class       t
-            JOIN pg_attribute   attr ON (t.oid = attrelid)
-            JOIN pg_attrdef     def  ON (adrelid = attrelid AND adnum = attnum)
-            JOIN pg_constraint  cons ON (conrelid = adrelid AND adnum = conkey[1])
-            WHERE t.oid = '#{quote_table_name(table)}'::regclass
-              AND cons.contype = 'p'
-              AND def.adsrc ~* 'nextval'
+if defined?(ActionRecord::ConnectionAdaptors::PostgreSQLAdaptor)
+  module ActiveRecord
+    module ConnectionAdapters
+      class PostgreSQLAdapter
+        def pk_and_sequence_for(table)
+          # First try looking for a sequence with a dependency on the
+          # given table's primary key.
+          result = query(<<-end_sql, 'PK and serial sequence')[0]
+            SELECT attr.attname, seq.relname
+            FROM pg_class      seq,
+                 pg_attribute  attr,
+                 pg_depend     dep,
+                 pg_namespace  name,
+                 pg_constraint cons
+            WHERE seq.oid           = dep.objid
+              AND seq.relkind       = 'S'
+              AND attr.attrelid     = dep.refobjid
+              AND attr.attnum       = dep.refobjsubid
+              AND attr.attrelid     = cons.conrelid
+              AND attr.attnum       = cons.conkey[1]
+              AND cons.contype      = 'p'
+              AND dep.classid       = '"pg_class"'::regclass
+              AND dep.refclassid    = '"pg_class"'::regclass
+              AND dep.refobjid      = '#{quote_table_name(table)}'::regclass
           end_sql
+  
+          if result.nil? or result.empty?
+            # If that fails, try parsing the primary key's default value.
+            # Support the 7.x and 8.0 nextval('foo'::text) as well as
+            # the 8.1+ nextval('foo'::regclass).
+            result = query(<<-end_sql, 'PK and custom sequence')[0]
+              SELECT attr.attname,
+                CASE
+                  WHEN split_part(def.adsrc, '''', 2) ~ '.' THEN
+                    substr(split_part(def.adsrc, '''', 2),
+                           strpos(split_part(def.adsrc, '''', 2), '.')+1)
+                  ELSE split_part(def.adsrc, '''', 2)
+                END
+              FROM pg_class       t
+              JOIN pg_attribute   attr ON (t.oid = attrelid)
+              JOIN pg_attrdef     def  ON (adrelid = attrelid AND adnum = attnum)
+              JOIN pg_constraint  cons ON (conrelid = adrelid AND adnum = conkey[1])
+              WHERE t.oid = '#{quote_table_name(table)}'::regclass
+                AND cons.contype = 'p'
+                AND def.adsrc ~* 'nextval'
+            end_sql
+          end
+  
+          # [primary_key, sequence]
+          [result.first, result.last]
+        rescue
+          nil
         end
-
-        # [primary_key, sequence]
-        [result.first, result.last]
-      rescue
-        nil
       end
     end
   end
index 83d42feecc29b941e25c0a4f9f7d269a400a5623..92372faf3c18762125f9dd8abf2e3e760a566477 100644 (file)
@@ -1,10 +1,12 @@
-module ActiveRecord
-  module ConnectionAdapters
-    module QueryCache
-      private
-        def cache_sql(sql)
-         yield
-        end
+if defined?(ActionRecord::ConnectionAdaptors::QueryCache)
+  module ActiveRecord
+    module ConnectionAdapters
+      module QueryCache
+        private
+          def cache_sql(sql)
+         yield
+          end
+      end
     end
   end
 end
index 986037afe3d107d047be03a5c192c57e24b345d0..2b9543fc2f2f9800e9556b9110e5efd273bca6c1 100644 (file)
@@ -4,4 +4,6 @@ adapter = Rails.configuration.database_configuration[environment]["adapter"]
 session_class = adapter + "_session"
 
 # Configure SqlSessionStore
-SqlSessionStore.session_class = session_class.camelize.constantize
+unless  OSM_STATUS == :database_offline
+  SqlSessionStore.session_class = session_class.camelize.constantize
+end
index e090f68aff88265c275c6b5d6df1270b620e01af..9c00ea234cec8d77dc331e1d0c39beb5980a947f 100644 (file)
@@ -1,2 +1,5 @@
 require 'deadlock_retry'
-ActiveRecord::Base.send :include, DeadlockRetry
+
+if defined?(ActionRecord::Base)
+  ActiveRecord::Base.send :include, DeadlockRetry
+end
index d31ef1b9c109244d1610258598b4e8a1b9053d3f..6ecbba5f6726c0c13873a057f08c762aa6e7c10f 100644 (file)
@@ -8,6 +8,11 @@ require 'file_column_helper'
 require 'validations'
 require 'test_case'
 
-ActiveRecord::Base.send(:include, FileColumn)
-ActionView::Base.send(:include, FileColumnHelper)
-ActiveRecord::Base.send(:include, FileColumn::Validations)
\ No newline at end of file
+if defined?(ActionRecord::Base)
+  ActiveRecord::Base.send(:include, FileColumn)
+  ActiveRecord::Base.send(:include, FileColumn::Validations)
+end
+
+if defined?(ActionView::Base)
+  ActionView::Base.send(:include, FileColumnHelper)
+end
index bdc8b5794f7ea71f62917ac8e0df6c380730a3b8..bf4d5e80a53993a081a917ac71c40dbd0992594a 100644 (file)
@@ -1 +1,3 @@
-require 'validates_email_format_of'
+if defined?(ActionRecord::Base)
+  require 'validates_email_format_of'
+end