Class: MysqlFramework::Scripts::Base
- Inherits:
-
Object
- Object
- MysqlFramework::Scripts::Base
- Defined in:
- lib/mysql_framework/scripts/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #apply(_client) ⇒ Object
- #column_exists?(client, table_name, column_name) ⇒ Boolean
- #identifier ⇒ Object
- #index_exists?(client, table_name, index_name) ⇒ Boolean
- #index_up_to_date?(client, table_name, index_name, columns) ⇒ Boolean
- #rollback(_client) ⇒ Object
- #tags ⇒ Object
- #update_procedure(client, proc_name, proc_file) ⇒ Object
Class Method Details
.descendants ⇒ Object
19 20 21 |
# File 'lib/mysql_framework/scripts/base.rb', line 19 def self.descendants ObjectSpace.each_object(Class).select { |klass| klass < self } end |
Instance Method Details
#apply(_client) ⇒ Object
11 12 13 |
# File 'lib/mysql_framework/scripts/base.rb', line 11 def apply(_client) raise NotImplementedError end |
#column_exists?(client, table_name, column_name) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/mysql_framework/scripts/base.rb', line 37 def column_exists?(client, table_name, column_name) result = client.query(" SHOW COLUMNS FROM \#{table_name} WHERE Field=\"\#{column_name}\";\n SQL\n\n result.count == 1\nend\n") |
#identifier ⇒ Object
6 7 8 9 |
# 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) ⇒ Boolean
45 46 47 48 49 50 51 |
# File 'lib/mysql_framework/scripts/base.rb', line 45 def index_exists?(client, table_name, index_name) result = client.query(" SHOW INDEX FROM \#{table_name} WHERE Key_name=\"\#{index_name}\";\n SQL\n\n result.count >= 1\nend\n") |
#index_up_to_date?(client, table_name, index_name, columns) ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mysql_framework/scripts/base.rb', line 53 def index_up_to_date?(client, table_name, index_name, columns) result = client.query(" SHOW INDEX FROM \#{table_name} WHERE Key_name=\"\#{index_name}\";\n SQL\n\n return false if result.size != columns.size\n\n index_columns = result.sort_by { |column| column[:Seq_in_index] }\n index_columns.each_with_index do |column, i|\n return false if column[:Column_name] != columns[i]\n end\n\n true\nend\n") |
#rollback(_client) ⇒ Object
15 16 17 |
# File 'lib/mysql_framework/scripts/base.rb', line 15 def rollback(_client) raise NotImplementedError end |
#tags ⇒ Object
23 24 25 |
# File 'lib/mysql_framework/scripts/base.rb', line 23 def [] end |
#update_procedure(client, proc_name, proc_file) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/mysql_framework/scripts/base.rb', line 27 def update_procedure(client, proc_name, proc_file) client.query(" DROP PROCEDURE IF EXISTS \#{proc_name};\n SQL\n\n proc_sql = File.read(proc_file)\n\n client.query(proc_sql)\nend\n") |