2017-04-30 6 views
6

मैं अपने रेल app के साथ Heroku सीआई (बीटा) का उपयोग कर रहा हूँ और जब मेरे परीक्षण वे सभी निम्न त्रुटि के साथ विफल चलाने के साथ Heroku सीआई:रेल जुड़नार

WARNING: Rails was not able to disable referential integrity. 
This is most likely caused due to missing permissions. 
Rails needs superuser privileges to disable referential integrity. 
    cause: PG::InsufficientPrivilege: ERROR: permission denied: "RI_ConstraintTrigger_a_5199633" is a system trigger 

यह कैसे रेल से संबंधित है के हटाए जाने के हैंडल स्थिरता रिकॉर्ड। ऑर्डर को निकालने का प्रयास करने के बजाय जिसमें रिकॉर्ड्स हटा दिए जाते हैं, वे केवल उन ट्रिगर्स को बंद कर देते हैं जो संदर्भित अखंडता को बनाए रखते हैं।

यह हेरोकू सीआई पर परीक्षण चलाने पर एक विकल्प नहीं है। क्या किसी के पास इसका उचित समाधान है?

+0

यक, मुझे लगता है कि कारखानों और डेटाबेस_क्लेनर के पास मेरे मुकाबले बहुत अधिक योग्यता है। – max

+0

हमें इसके लिए निश्चित रूप से एक समाधान की आवश्यकता है !! कोई समाधान? – CreativeJourney

उत्तर

3

रेल पीआर जो तय इस मुद्दे को वापस लाया गया था:

# config/initializers/disable_referential_integrity.rb 
require "activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb" 
require "activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb" 

अपने lib/ दो फ़ाइलों में जोड़े (रेल से पीआर कोड):

# lib/activerecord/lib/active_record/connection_adapters/postgresql/referential_integrity.rb 
module ActiveRecord 
    module ConnectionAdapters 
    module PostgreSQL 
     module ReferentialIntegrity # :nodoc: 
     def supports_disable_referential_integrity? # :nodoc: 
      true 
     end 

     def disable_referential_integrity(&block) # :nodoc: 
      if supports_disable_referential_integrity? 
      if supports_alter_constraint? 
       disable_referential_integrity_with_alter_constraint(&block) 
      else 
       disable_referential_integrity_with_disable_trigger(&block) 
      end 
      else 
      yield 
      end 
     end 

     private 

      def disable_referential_integrity_with_alter_constraint 
      tables_constraints = execute(<<-SQL).values 
       SELECT table_name, constraint_name 
       FROM information_schema.table_constraints 
       WHERE constraint_type = 'FOREIGN KEY' 
       AND is_deferrable = 'NO' 
      SQL 

      execute(
       tables_constraints.collect { |table, constraint| 
       "ALTER TABLE #{quote_table_name(table)} ALTER CONSTRAINT #{constraint} DEFERRABLE" 
       }.join(";") 
      ) 

      begin 
       transaction do 
       execute("SET CONSTRAINTS ALL DEFERRED") 

       yield 
       end 
      ensure 
       execute(
       tables_constraints.collect { |table, constraint| 
        "ALTER TABLE #{quote_table_name(table)} ALTER CONSTRAINT #{constraint} NOT DEFERRABLE" 
       }.join(";") 
      ) 
      end 
      end 

      def disable_referential_integrity_with_disable_trigger 
      original_exception = nil 

      begin 
       transaction(requires_new: true) do 
       execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(";")) 
       end 
      rescue ActiveRecord::ActiveRecordError => e 
       original_exception = e 
      end 

      begin 
       yield 
      rescue ActiveRecord::InvalidForeignKey => e 
       warn <<-WARNING 
WARNING: Rails was not able to disable referential integrity. 
This is most likely caused due to missing permissions. 
Rails needs superuser privileges to disable referential integrity. 
    cause: #{original_exception.try(:message)} 
       WARNING 
       raise e 
      end 

      begin 
       transaction(requires_new: true) do 
       execute(tables.collect { |name| "ALTER TABLE #{quote_table_name(name)} ENABLE TRIGGER ALL" }.join(";")) 
       end 
      rescue ActiveRecord::ActiveRecordError 
      end 
      end 
     end 
    end 
    end 
end 

https://github.com/rails/rails/pull/27636

वर्कअराउंड बंदर पैच है और दूसरी फ़ाइल:

# lib/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb 
module ActiveRecord 
    module ConnectionAdapters 
    class PostgreSQLAdapter < AbstractAdapter 

     def supports_alter_constraint? 
     # PostgreSQL 9.4 introduces ALTER TABLE ... ALTER CONSTRAINT but it has a bug and fixed in 9.4.2 
     # https://www.postgresql.org/docs/9.4/static/release-9-4-2.html 
     postgresql_version >= 90402 
     end 

    end 
    end 
end 
+0

यह सुनिश्चित करने के लिए कि बंदर-पैच लागू होता है, मुझे यह सुनिश्चित करना था कि मेरे प्रारंभकर्ता द्वारा चलाए जाने वाले पोस्टग्रेस एडाप्टर कोड को लोड किया जाए। इसे 'कॉन्फ़िगर/प्रारंभकर्ता/disabled_referential_integrity.rb' की पहली पंक्ति के रूप में जोड़ें:' ActiveRecord :: Base.connection' – Brad

संबंधित मुद्दे