Class: PgHaMigrations::QuarterlyPartmanRenameAdapter

Inherits:
AbstractPartmanRenameAdapter show all
Defined in:
lib/pg_ha_migrations/partman_rename_adapter.rb

Constant Summary collapse

QUARTER_MONTH_MAPPING =
{
  "1" => "01",
  "2" => "04",
  "3" => "07",
  "4" => "10",
}

Instance Method Summary collapse

Methods inherited from AbstractPartmanRenameAdapter

#alter_table_sql, #initialize

Constructor Details

This class inherits a constructor from PgHaMigrations::AbstractPartmanRenameAdapter

Instance Method Details

#source_datetime_stringObject



87
88
89
# File 'lib/pg_ha_migrations/partman_rename_adapter.rb', line 87

def source_datetime_string
  "YYYY\"q\"Q"
end

#source_name_suffix_patternObject



91
92
93
# File 'lib/pg_ha_migrations/partman_rename_adapter.rb', line 91

def source_name_suffix_pattern
  /\A.+_p\d{4}q(1|2|3|4)\z/
end

#target_datetime_stringObject



95
96
97
# File 'lib/pg_ha_migrations/partman_rename_adapter.rb', line 95

def target_datetime_string
  "YYYYMMDD"
end

#target_table_name(table_name) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/pg_ha_migrations/partman_rename_adapter.rb', line 77

def target_table_name(table_name)
  base_name = table_name[0...-6]

  year = table_name.last(6).first(4)

  month = QUARTER_MONTH_MAPPING.fetch(table_name.last(1))

  base_name + year + month + "01"
end