Class: StrongMigrations::Adapters::MySQLAdapter
Instance Method Summary
collapse
#initialize
Instance Method Details
#add_column_default_safe? ⇒ Boolean
46
47
48
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 46
def add_column_default_safe?
server_version >= Gem::Version.new("8.0.12")
end
|
#analyze_table(table) ⇒ Object
42
43
44
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 42
def analyze_table(table)
connection.execute "ANALYZE TABLE #{connection.quote_table_name(table.to_s)}"
end
|
#change_type_safe?(table, column, type, options, existing_column, existing_type) ⇒ Boolean
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 50
def change_type_safe?(table, column, type, options, existing_column, existing_type)
safe = false
case type.to_s
when "string"
limit = options[:limit] || 255
safe = ["varchar"].include?(existing_type) &&
limit >= existing_column.limit &&
(limit <= 255 || existing_column.limit > 255)
end
safe
end
|
#check_lock_timeout(limit) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 34
def check_lock_timeout(limit)
lock_timeout = connection.select_all("SHOW VARIABLES LIKE 'lock_wait_timeout'").first["Value"]
if lock_timeout.to_i > limit
warn "[strong_migrations] DANGER: Lock timeout is longer than #{limit} seconds: #{lock_timeout}"
end
end
|
#min_version ⇒ Object
10
11
12
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 10
def min_version
"5.7"
end
|
#name ⇒ Object
6
7
8
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 6
def name
"MySQL"
end
|
#rewrite_blocks ⇒ Object
73
74
75
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 73
def rewrite_blocks
"writes"
end
|
#server_version ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 14
def server_version
@server_version ||= begin
target_version(StrongMigrations.target_mysql_version) do
select_all("SELECT VERSION()").first["VERSION()"].split("-").first
end
end
end
|
#set_lock_timeout(timeout) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 27
def set_lock_timeout(timeout)
timeout = timeout.value if timeout.is_a?(ActiveSupport::Duration)
select_all("SET lock_wait_timeout = #{connection.quote(timeout)}")
end
|
#set_statement_timeout(timeout) ⇒ Object
22
23
24
25
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 22
def set_statement_timeout(timeout)
select_all("SET max_execution_time = #{connection.quote((timeout.to_f * 1000).ceil)}")
end
|
#strict_mode? ⇒ Boolean
68
69
70
71
|
# File 'lib/strong_migrations/adapters/mysql_adapter.rb', line 68
def strict_mode?
sql_modes = sql_modes()
sql_modes.include?("STRICT_ALL_TABLES") || sql_modes.include?("STRICT_TRANS_TABLES")
end
|