footing 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -8,4 +8,5 @@ end
8
8
  group :test do
9
9
  gem "rspec"
10
10
  gem "grumpy_old_man"
11
+ gem "micro_mock"
11
12
  end
data/Gemfile.lock CHANGED
@@ -5,6 +5,7 @@ GEM
5
5
  diff-lcs (1.1.3)
6
6
  grumpy_old_man (0.1.3)
7
7
  method_source (0.8)
8
+ micro_mock (0.0.1)
8
9
  pry (0.9.10)
9
10
  coderay (~> 1.0.5)
10
11
  method_source (~> 0.8)
@@ -25,6 +26,7 @@ PLATFORMS
25
26
 
26
27
  DEPENDENCIES
27
28
  grumpy_old_man
29
+ micro_mock
28
30
  pry
29
31
  rspec
30
32
  yard
@@ -1,6 +1,6 @@
1
1
  # Extend Rails to support adding timestamp indexes for created_at & updated_at using day granularity.
2
2
  #
3
- # Example:
3
+ # @example Make these statements available to ActiveRecord::Migration change, up, down methods
4
4
  # # rails_root/config/application.rb
5
5
  # config.after_initialize do
6
6
  # Footing.patch! ActiveRecord::ConnectionAdapters::AbstractAdapter, Footing::PGSchemaStatements
@@ -10,22 +10,66 @@ module Footing
10
10
  module PGSchemaStatements
11
11
 
12
12
  # Adds indexes to the created_at and updated_at timestamp columns with 'day' granularity.
13
- # This method is available to ActiveRecord::Migration change, up, down methods.
14
13
  def add_timestamp_indexes(table_name)
15
14
  %w(created_at updated_at).each do |column_name|
16
- name = "index_#{table_name}_on_#{column_name}"
17
- execute "create index #{name} on #{quote_table_name(table_name)} (date_trunc('day', #{quote_column_name(column_name)}))"
15
+ add_datetime_index(table_name, column_name, :precision => :day)
18
16
  end
19
17
  end
20
18
 
21
19
  # Removes indexes to the created_at and updated_at timestamp columns with 'day' granularity.
22
- # This method is available to ActiveRecord::Migration change, up, down methods.
23
20
  def remove_timestamp_indexes(table_name)
24
21
  %w(created_at updated_at).each do |column_name|
25
- name = "index_#{table_name}_on_#{column_name}"
26
- execute "drop index if exists #{name}"
22
+ remove_datetime_index(table_name, column_name, :precision => :day)
27
23
  end
28
24
  end
29
25
 
26
+ # Adds an index on a datetime column using the specified precision.
27
+ # @param [Symbol,String] table_name The name of the table to migrate.
28
+ # @param [Symbol,String] column_name The name of the column to migrate.
29
+ # @param [Hash] options
30
+ # @option options [Symbol,String] :precision
31
+ # - microseconds
32
+ # - milliseconds
33
+ # - second
34
+ # - minute *default
35
+ # - hour
36
+ # - day
37
+ # - week
38
+ # - month
39
+ # - quarter
40
+ # - year
41
+ # - decade
42
+ # - century
43
+ # - millennium
44
+ def add_datetime_index(table_name, column_name, options={})
45
+ options[:precision] ||= :minute
46
+ index_name = "index_#{table_name}_on_#{column_name}_by_#{options[:precision]}"
47
+ execute "create index #{index_name} on #{quote_table_name(table_name)} (date_trunc('#{options[:precision]}', #{quote_column_name(column_name)}))"
48
+ end
49
+
50
+ # Removes an index on a datetime column using the specified precision.
51
+ # @param [Symbol,String] table_name The name of the table to migrate.
52
+ # @param [Symbol,String] column_name The name of the column to migrate.
53
+ # @param [Hash] options
54
+ # @option options [Symbol,String] :precision
55
+ # - microseconds
56
+ # - milliseconds
57
+ # - second
58
+ # - minute *default
59
+ # - hour
60
+ # - day
61
+ # - week
62
+ # - month
63
+ # - quarter
64
+ # - year
65
+ # - decade
66
+ # - century
67
+ # - millennium
68
+ def remove_datetime_index(table_name, column_name, options={})
69
+ options[:precision] ||= :minute
70
+ index_name = "index_#{table_name}_on_#{column_name}_by_#{options[:precision]}"
71
+ execute "drop index if exists #{index_name}"
72
+ end
73
+
30
74
  end
31
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: footing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-06 00:00:00.000000000 Z
12
+ date: 2012-09-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! ' Footing is a utillity belt library that employs sane monkey patching.
15
15