Class: PartitionGardener::SqlRunRecordStore
- Inherits:
-
Object
- Object
- PartitionGardener::SqlRunRecordStore
- Defined in:
- lib/partition_gardener/sql_run_record_store.rb
Constant Summary collapse
- TABLE_NAME =
"partition_gardener_run_records"
Instance Method Summary collapse
- #clear(table_name) ⇒ Object
- #ensure_schema! ⇒ Object
-
#initialize ⇒ SqlRunRecordStore
constructor
A new instance of SqlRunRecordStore.
- #load(table_name) ⇒ Object
- #save(table_name, attributes) ⇒ Object
Constructor Details
#initialize ⇒ SqlRunRecordStore
Returns a new instance of SqlRunRecordStore.
5 6 7 8 |
# File 'lib/partition_gardener/sql_run_record_store.rb', line 5 def initialize @schema_mutex = Mutex.new @schema_ready = false end |
Instance Method Details
#clear(table_name) ⇒ Object
31 32 33 34 35 |
# File 'lib/partition_gardener/sql_run_record_store.rb', line 31 def clear(table_name) ensure_schema! sql = clear_sql(table_name) connection.execute(sql) end |
#ensure_schema! ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/partition_gardener/sql_run_record_store.rb', line 37 def ensure_schema! return if @schema_ready @schema_mutex.synchronize do return if @schema_ready connection.execute(create_table_sql) @schema_ready = true end end |
#load(table_name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/partition_gardener/sql_run_record_store.rb', line 10 def load(table_name) ensure_schema! sql = load_sql(table_name) row = connection.execute(sql).first return unless row { table_name: row["table_name"], phase: row["phase"], plan_signature: row["plan_signature"], staging_row_count: row["staging_row_count"].to_i } end |
#save(table_name, attributes) ⇒ Object
25 26 27 28 29 |
# File 'lib/partition_gardener/sql_run_record_store.rb', line 25 def save(table_name, attributes) ensure_schema! sql = save_sql(table_name, attributes) connection.execute(sql) end |