pgdice 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/pgdice.rb CHANGED
@@ -1,109 +1,71 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'pg'
4
+ require 'yaml'
5
+ require 'json'
4
6
  require 'open3'
5
7
  require 'logger'
6
8
  require 'pgslice'
9
+ require 'forwardable'
7
10
  require 'pgdice/version'
8
- require 'pgdice/validation'
9
- require 'pgdice/table_dropper'
10
- require 'pgdice/configuration'
11
- require 'pgdice/pg_slice_manager'
12
- require 'pgdice/partition_manager'
13
- require 'pgdice/partition_helper'
14
- require 'pgdice/database_connection'
11
+ require 'pgdice/error'
15
12
 
16
- # This is a stupid comment
17
- module PgDice
18
- class Error < StandardError
19
- end
20
- class PgSliceError < Error
21
- end
22
- class ValidationError < Error
23
- end
24
- class IllegalTableError < ValidationError
25
- end
26
- class TableNotPartitionedError < Error
27
- end
13
+ require 'pgdice/table'
14
+ require 'pgdice/log_helper'
28
15
 
29
- # Rubocop is stupid
30
- class InsufficientTablesError < Error
31
- def initialize(direction, table_name, table_count, period)
32
- super("Insufficient #{direction} tables exist for table: #{table_name}. "\
33
- "Expected: #{table_count} having period of: #{period}")
34
- end
35
- end
16
+ require 'pgdice/date_helper'
17
+ require 'pgdice/table_finder'
36
18
 
37
- # Rubocop is stupid
38
- class InsufficientFutureTablesError < InsufficientTablesError
39
- def initialize(table_name, table_count, period)
40
- super('future', table_name, table_count, period)
41
- end
42
- end
19
+ require 'pgdice/period_fetcher'
20
+ require 'pgdice/period_fetcher_factory'
43
21
 
44
- # Rubocop is stupid
45
- class InsufficientPastTablesError < InsufficientTablesError
46
- def initialize(table_name, table_count, period)
47
- super('past', table_name, table_count, period)
48
- end
49
- end
22
+ require 'pgdice/validation'
23
+ require 'pgdice/validation_factory'
50
24
 
51
- # Rubocop is stupid
52
- class CustomValidationError < ValidationError
53
- def initialize(params, validators, error = nil)
54
- error_message = "Custom validation failed with params: #{params}. "
55
- error_message += "Caused by error: #{error} " if error
56
- error_message += "Validators: #{validators.map { |validator| source_location(validator) }.flatten}"
57
- super(error_message)
58
- end
25
+ require 'pgdice/configuration'
26
+ require 'pgdice/configuration_file_loader'
59
27
 
60
- private
28
+ require 'pgdice/approved_tables'
61
29
 
62
- # Helps users know what went wrong in their custom validators
63
- def source_location(proc)
64
- return proc.source_location if proc.respond_to?(:source_location)
30
+ require 'pgdice/partition_lister'
31
+ require 'pgdice/partition_lister_factory'
65
32
 
66
- proc.to_s
67
- end
68
- end
33
+ require 'pgdice/pg_slice_manager'
34
+ require 'pgdice/pg_slice_manager_factory'
69
35
 
70
- class ConfigurationError < Error
71
- end
36
+ require 'pgdice/partition_helper'
37
+ require 'pgdice/partition_helper_factory'
72
38
 
73
- # Rubocop is stupid
74
- class NotConfiguredError < ConfigurationError
75
- def initialize(method_name)
76
- super("Cannot use #{method_name} before PgDice has been configured! "\
77
- 'See README.md for configuration help.')
78
- end
79
- end
39
+ require 'pgdice/partition_manager'
40
+ require 'pgdice/partition_manager_factory'
80
41
 
81
- # Rubocop is stupid
82
- class InvalidConfigurationError < ConfigurationError
83
- def initialize(message)
84
- super("PgDice is not configured properly. #{message}")
85
- end
86
- end
42
+ require 'pgdice/partition_dropper'
43
+ require 'pgdice/partition_dropper_factory'
87
44
 
88
- SUPPORTED_PERIODS = { day: 'YYYYMMDD', month: 'YYYYMM', year: 'YYYY' }.freeze
45
+ require 'pgdice/database_connection'
46
+ require 'pgdice/database_connection_factory'
47
+
48
+ # This is a stupid comment
49
+ module PgDice
50
+ SUPPORTED_PERIODS = { 'day' => 'YYYYMMDD', 'month' => 'YYYYMM', 'year' => 'YYYY' }.freeze
89
51
 
90
52
  class << self
91
53
  def partition_manager
92
54
  raise PgDice::NotConfiguredError, 'partition_manager' unless configuration
93
55
 
94
- @partition_manager ||= PgDice::PartitionManager.new(configuration)
56
+ configuration.partition_manager
95
57
  end
96
58
 
97
59
  def partition_helper
98
60
  raise PgDice::NotConfiguredError, 'partition_helper' unless configuration
99
61
 
100
- @partition_helper ||= PgDice::PartitionHelper.new(configuration)
62
+ configuration.partition_helper
101
63
  end
102
64
 
103
65
  def validation
104
66
  raise PgDice::NotConfiguredError, 'validation' unless configuration
105
67
 
106
- @validation ||= PgDice::Validation.new(configuration)
68
+ configuration.validation
107
69
  end
108
70
  end
109
71
  end
data/pgdice.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ['Andrew Newell']
11
11
  spec.email = ['andrew@andrewcn.com illuminuslimited@gmail.com']
12
12
 
13
- spec.summary = 'Postgres partitioning with a Ruby API!'
14
- spec.description = 'Postgres partitioning with a Ruby API built on top of https://github.com/ankane/pgslice'
13
+ spec.summary = 'Postgres table partitioning with a Ruby API!'
14
+ spec.description = 'Postgres table partitioning with a Ruby API built on top of https://github.com/ankane/pgslice'
15
15
  spec.homepage = 'https://github.com/IlluminusLimited/pgdice'
16
16
  spec.license = 'MIT'
17
17
 
@@ -26,9 +26,8 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  # Locked because we depend on internal behavior for table commenting
28
28
  spec.add_runtime_dependency 'pg', '~> 1.1.0', '>= 1.1.0'
29
- spec.add_runtime_dependency 'pgslice', '0.4.4'
29
+ spec.add_runtime_dependency 'pgslice', '0.4.5'
30
30
 
31
- spec.add_development_dependency 'activesupport', '~> 5.0.0', '>= 5.0.0'
32
31
  spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16'
33
32
  spec.add_development_dependency 'coveralls', '~> 0.8.22', '>= 0.8.22'
34
33
  spec.add_development_dependency 'guard', '~> 2.14.2', '>= 2.14.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgdice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-17 00:00:00.000000000 Z
11
+ date: 2018-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -36,34 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.4.4
39
+ version: 0.4.5
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: 0.4.4
47
- - !ruby/object:Gem::Dependency
48
- name: activesupport
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: 5.0.0
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 5.0.0
57
- type: :development
58
- prerelease: false
59
- version_requirements: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: 5.0.0
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: 5.0.0
46
+ version: 0.4.5
67
47
  - !ruby/object:Gem::Dependency
68
48
  name: bundler
69
49
  requirement: !ruby/object:Gem::Requirement
@@ -298,7 +278,7 @@ dependencies:
298
278
  - - ">="
299
279
  - !ruby/object:Gem::Version
300
280
  version: 0.16.1
301
- description: Postgres partitioning with a Ruby API built on top of https://github.com/ankane/pgslice
281
+ description: Postgres table partitioning with a Ruby API built on top of https://github.com/ankane/pgslice
302
282
  email:
303
283
  - andrew@andrewcn.com illuminuslimited@gmail.com
304
284
  executables: []
@@ -306,11 +286,13 @@ extensions: []
306
286
  extra_rdoc_files: []
307
287
  files:
308
288
  - ".circleci/config.yml"
289
+ - ".codeclimate.yml"
309
290
  - ".coveralls.yml"
310
291
  - ".gitignore"
311
292
  - ".rubocop.yml"
312
293
  - ".ruby-gemset"
313
294
  - ".ruby-version"
295
+ - CHANGELOG.md
314
296
  - CODE_OF_CONDUCT.md
315
297
  - Gemfile
316
298
  - Guardfile
@@ -321,14 +303,32 @@ files:
321
303
  - bin/console
322
304
  - bin/guard
323
305
  - bin/setup
306
+ - examples/config.yml
324
307
  - lib/pgdice.rb
308
+ - lib/pgdice/approved_tables.rb
325
309
  - lib/pgdice/configuration.rb
310
+ - lib/pgdice/configuration_file_loader.rb
326
311
  - lib/pgdice/database_connection.rb
312
+ - lib/pgdice/database_connection_factory.rb
313
+ - lib/pgdice/date_helper.rb
314
+ - lib/pgdice/error.rb
315
+ - lib/pgdice/log_helper.rb
316
+ - lib/pgdice/partition_dropper.rb
317
+ - lib/pgdice/partition_dropper_factory.rb
327
318
  - lib/pgdice/partition_helper.rb
319
+ - lib/pgdice/partition_helper_factory.rb
320
+ - lib/pgdice/partition_lister.rb
321
+ - lib/pgdice/partition_lister_factory.rb
328
322
  - lib/pgdice/partition_manager.rb
323
+ - lib/pgdice/partition_manager_factory.rb
324
+ - lib/pgdice/period_fetcher.rb
325
+ - lib/pgdice/period_fetcher_factory.rb
329
326
  - lib/pgdice/pg_slice_manager.rb
330
- - lib/pgdice/table_dropper.rb
327
+ - lib/pgdice/pg_slice_manager_factory.rb
328
+ - lib/pgdice/table.rb
329
+ - lib/pgdice/table_finder.rb
331
330
  - lib/pgdice/validation.rb
331
+ - lib/pgdice/validation_factory.rb
332
332
  - lib/pgdice/version.rb
333
333
  - pgdice.gemspec
334
334
  homepage: https://github.com/IlluminusLimited/pgdice
@@ -354,5 +354,5 @@ rubyforge_project:
354
354
  rubygems_version: 2.7.6
355
355
  signing_key:
356
356
  specification_version: 4
357
- summary: Postgres partitioning with a Ruby API!
357
+ summary: Postgres table partitioning with a Ruby API!
358
358
  test_files: []
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Entry point for TableDropperHelper
4
- module PgDice
5
- # Simple class used to provide a mechanism that users can hook into if they want to override this
6
- # default behavior for dropping a table.
7
- class TableDropper
8
- def initialize(configuration = PgDice::Configuration.new)
9
- @configuration = configuration
10
- end
11
-
12
- def call(table_to_drop, _logger)
13
- @configuration.database_connection.execute(drop_partition(table_to_drop))
14
- end
15
-
16
- private
17
-
18
- def drop_partition(table_name)
19
- <<~SQL
20
- BEGIN;
21
- DROP TABLE IF EXISTS #{table_name} CASCADE;
22
- COMMIT;
23
- SQL
24
- end
25
- end
26
- end