Module: SafePgMigrations::UselessStatementsLogger

Defined in:
lib/safe-pg-migrations/plugins/useless_statements_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.warn_useless(action, link = nil, *args) ⇒ Object



6
7
8
9
10
11
# File 'lib/safe-pg-migrations/plugins/useless_statements_logger.rb', line 6

def warn_useless(action, link = nil, *args)
  Helpers::Logger.say(
    "/!\\ No need to explicitly use #{action}, safe-pg-migrations does it for you", *args
  )
  Helpers::Logger.say "\t see #{link} for more details", *args if link
end

Instance Method Details

#add_check_constraint(table_name, expression, **options) ⇒ Object



31
32
33
34
35
36
# File 'lib/safe-pg-migrations/plugins/useless_statements_logger.rb', line 31

def add_check_constraint(table_name, expression, **options)
  if options[:validate] == false
    UselessStatementsLogger.warn_useless '`validate: :false`', 'https://github.com/doctolib/safe-pg-migrations#safe_add_check_constraint'
  end
  super
end

#add_foreign_key(from_table, to_table, **options) ⇒ Object



24
25
26
27
28
29
# File 'lib/safe-pg-migrations/plugins/useless_statements_logger.rb', line 24

def add_foreign_key(from_table, to_table, **options)
  if options[:validate] == false
    UselessStatementsLogger.warn_useless '`validate: :false`', 'https://github.com/doctolib/safe-pg-migrations#safe_add_foreign_key'
  end
  super
end

#add_index(table_name, column_name, **options) ⇒ Object



14
15
16
17
# File 'lib/safe-pg-migrations/plugins/useless_statements_logger.rb', line 14

def add_index(table_name, column_name, **options)
  warn_for_index(**options)
  super
end

#remove_index(table_name, column_name = nil, **options) ⇒ Object



19
20
21
22
# File 'lib/safe-pg-migrations/plugins/useless_statements_logger.rb', line 19

def remove_index(table_name, column_name = nil, **options)
  warn_for_index(**options) unless options.empty?
  super
end

#warn_for_index(**options) ⇒ Object



38
39
40
41
42
# File 'lib/safe-pg-migrations/plugins/useless_statements_logger.rb', line 38

def warn_for_index(**options)
  return unless options[:algorithm] == :concurrently

  UselessStatementsLogger.warn_useless '`algorithm: :concurrently`', 'https://github.com/doctolib/safe-pg-migrations#safe_add_remove_index'
end