Module: AfterMigrate::Mysql

Extended by:
Sql
Defined in:
lib/after_migrate/adapters/mysql.rb

Constant Summary

Constants included from Sql

Sql::IDENT, Sql::PATTERNS

Class Method Summary collapse

Methods included from Sql

parse_tables

Class Method Details

.all_tables(schema: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/after_migrate/adapters/mysql.rb', line 17

def all_tables(schema: nil)
  connection = ActiveRecord::Base.connection
  database = schema.to_s.presence || connection.current_database

  connection.select_values(<<~SQL.squish)
    SELECT table_name
    FROM information_schema.tables
    WHERE table_schema = #{connection.quote(database)}
      AND table_type = 'BASE TABLE'           -- exclude views
      AND table_name NOT LIKE 'ar_internal_metadata'
      AND table_name NOT LIKE 'schema_migrations'
    ORDER BY table_name
  SQL
end

.optimize_tables(connection:, table_names:) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/after_migrate/adapters/mysql.rb', line 9

def optimize_tables(connection:, table_names:, **)
  table_names.each do |t|
    quoted = connection.quote_table_name(t)
    AfterMigrate.log("ANALYZE TABLE #{quoted}")
    connection.execute("ANALYZE TABLE #{quoted}")
  end
end