app/models/switchman/shard.rb
# ten trillion possible ids per shard. yup.
ten trillion possible ids per shard. yup.
ten trillion possible ids per shard . yup .
def drop_database
      raise("Cannot drop the database of the default shard") if self.default?
      return unless read_attribute(:name)
      begin
        adapter = self.database_server.config[:adapter]
        sharding_config = Switchman.config || {}
        drop_statement = sharding_config[adapter]&.[](:drop_statement)
        drop_statement ||= sharding_config[:drop_statement]
        if drop_statement
          drop_statement = Array(drop_statement).dup.
              map { |statement| statement.gsub('%{name}', self.name) }
        end
        case adapter
          when 'mysql', 'mysql2'
            self.activate do
              ::GuardRail.activate(:deploy) do
                drop_statement ||= "DROP DATABASE #{self.name}"
                Array(drop_statement).each do |stmt|
                  ::ActiveRecord::Base.connection.execute(stmt)
                end
              end
            end
          when 'postgresql'
            self.activate do
              ::GuardRail.activate(:deploy) do
                conn = ::ActiveRecord::Base.connection
                old_proc = conn.raw_connection.set_notice_processor {}
                begin
                  drop_statement ||= "DROP SCHEMA #{self.name} CASCADE"
                  Array(drop_statement).each do |stmt|
                    ::ActiveRecord::Base.connection.execute(stmt)
                  end
                ensure
                  conn.raw_connection.set_notice_processor(&old_proc) if old_proc
                end
              end
            end
        end
      rescue
        logger.info "Drop failed: #{$!}"
      end
    end
def drop_database raise ( "Cannot drop the database of the default shard" ) if self . default? return unless read_attribute ( :name ) begin adapter = self . database_server . config [ :adapter ] sharding_config = Switchman . config || { } drop_statement = sharding_config [ adapter ] &. [] ( :drop_statement ) drop_statement ||= sharding_config [ :drop_statement ] if drop_statement drop_statement = Array ( drop_statement ) . dup . map { | statement | statement . gsub ( '%{name}' , self . name ) } end case adapter when 'mysql' , 'mysql2' self . activate do :: GuardRail . activate ( :deploy ) do drop_statement ||= "DROP DATABASE #{self.name}" Array ( drop_statement ) . each do | stmt | :: ActiveRecord :: Base . connection . execute ( stmt ) end end end when 'postgresql' self . activate do :: GuardRail . activate ( :deploy ) do conn = :: ActiveRecord :: Base . connection old_proc = conn . raw_connection . set_notice_processor { } begin drop_statement ||= "DROP SCHEMA #{self.name} CASCADE" Array ( drop_statement ) . each do | stmt | :: ActiveRecord :: Base . connection . execute ( stmt ) end ensure conn . raw_connection . set_notice_processor ( & old_proc ) if old_proc end end end end rescue logger . info "Drop failed: #{$!}" end end
ten trillion possible ids per shard.
ten trillion possible ids per shard .
# Shut up, Postgres!