Module: AfterMigrate::Executor
Class Method Summary collapse
- .all_tables(schema:) ⇒ Object
- .call(schema: nil) ⇒ Object
- .optimize_tables(schema:, table_names:) ⇒ Object
- .run_optimize(schema:, tables:) ⇒ Object
- .target_tables ⇒ Object
Instance Method Summary collapse
Class Method Details
.all_tables(schema:) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/after_migrate/executor.rb', line 68 def all_tables(schema:) connection = ActiveRecord::Base.connection case connection.adapter_name when 'PostgreSQL' AfterMigrate::Postgresql.all_tables(schema:) when 'SQLite' AfterMigrate::Sqlite.all_tables(schema:) when 'Mysql2', 'Trilogy' AfterMigrate::Mysql.all_tables(schema:) else [] end end |
.call(schema: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/after_migrate/executor.rb', line 14 def call(schema: nil) return unless AfterMigrate.configuration.vacuum || AfterMigrate.configuration.analyze != 'none' tables = target_tables return if tables.blank? if schema.present? run_optimize(schema:, tables: tables[schema]) if tables[schema].present? else tables.each { |s, t| run_optimize(schema: s, tables: t) } end ensure AfterMigrate.reset! end |
.optimize_tables(schema:, table_names:) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/after_migrate/executor.rb', line 42 def optimize_tables(schema:, table_names:) connection = ActiveRecord::Base.connection case connection.adapter_name when 'PostgreSQL' AfterMigrate::Postgresql.optimize_tables(schema:, table_names:, connection:) when 'SQLite' AfterMigrate::Sqlite.optimize_tables(schema:, table_names:, connection:) when 'Mysql2', 'Trilogy' AfterMigrate::Mysql.optimize_tables(schema:, table_names:, connection:) else AfterMigrate.log("No maintenance implemented for #{connection.adapter_name}") end end |
.run_optimize(schema:, tables:) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/after_migrate/executor.rb', line 33 def run_optimize(schema:, tables:) table_names = tables.to_a.sort return if table_names.empty? = "Migration touched #{table_names.size} table(s) in schema #{schema.inspect}: #{table_names.join(', ')}" AfterMigrate.log() optimize_tables(schema:, table_names:) end |
.target_tables ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/after_migrate/executor.rb', line 56 def target_tables case AfterMigrate.configuration.analyze when 'all_tables' AfterMigrate.affected_tables.keys.each_with_object({}) do |schema, hash| hash[schema] = all_tables(schema:) end else # 'only_affected_tables' or 'none' — vacuum still needs the affected list AfterMigrate.affected_tables end end |
Instance Method Details
#call(schema: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/after_migrate/executor.rb', line 14 def call(schema: nil) return unless AfterMigrate.configuration.vacuum || AfterMigrate.configuration.analyze != 'none' tables = target_tables return if tables.blank? if schema.present? run_optimize(schema:, tables: tables[schema]) if tables[schema].present? else tables.each { |s, t| run_optimize(schema: s, tables: t) } end ensure AfterMigrate.reset! end |