class MysqlFramework::Scripts::Base

Public Class Methods

descendants() click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 19
def self.descendants
  ObjectSpace.each_object(Class).select { |klass| klass < self }
end

Public Instance Methods

apply(_client) click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 11
def apply(_client)
  raise NotImplementedError
end
column_exists?(client, table_name, column_name) click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 37
      def column_exists?(client, table_name, column_name)
        result = client.query(<<~SQL)
          SHOW COLUMNS FROM #{table_name} WHERE Field="#{column_name}";
        SQL

        result.count == 1
      end
identifier() click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 6
def identifier
  raise NotImplementedError if @identifier.nil?
  @identifier
end
index_exists?(client, table_name, index_name) click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 45
      def index_exists?(client, table_name, index_name)
        result = client.query(<<~SQL)
          SHOW INDEX FROM #{table_name} WHERE Key_name="#{index_name}" LIMIT 1;
        SQL

        result.count == 1
      end
rollback(_client) click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 15
def rollback(_client)
  raise NotImplementedError
end
tags() click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 23
def tags
  []
end
update_procedure(client, proc_name, proc_file) click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 27
      def update_procedure(client, proc_name, proc_file)
        client.query(<<~SQL)
          DROP PROCEDURE IF EXISTS #{proc_name};
        SQL

        proc_sql = File.read(proc_file)

        client.query(proc_sql)
      end

Protected Instance Methods

generate_partition_sql() click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 55
def generate_partition_sql
  (1..partitions).each_with_index.map { |_, i| "PARTITION p#{i} VALUES IN (#{i})" }.join(",\n\t")
end

Private Instance Methods

partitions() click to toggle source
# File lib/mysql_framework/scripts/base.rb, line 61
def partitions
  @partitions ||= Integer(ENV.fetch('MYSQL_PARTITIONS', '500'))
end