brillo 1.1.0 → 1.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1b61984d544d65ece11ac029344d31a7d3bc111
4
- data.tar.gz: 38187ebba9e25dda6be33418813e457a292cfb6f
3
+ metadata.gz: c263c71c0f71009368727fa986bca2553feeea80
4
+ data.tar.gz: 6d529dd2c34696b1e8c5f2c314d0080b0b3228d8
5
5
  SHA512:
6
- metadata.gz: 285e40acd59b6ebd01809c99d4c13285f36b6366022df3ed781c6d0e89198c7448ecd72ba9245bd54ffbe2c08dfb93dbcecacf88d600a4a231c4062421f00b9e
7
- data.tar.gz: 4665c6cf7c9a59736a577e9db36f17725ca453328aba4486a20ef66bb20eada68407b13dc847b452558fa430d64b0d1a16228eecf97f09d8d618c14972a3190b
6
+ metadata.gz: cb5931545ee10c680b82921423315ecbe8aa55bc4a882dc2858fbdef2f8e41d19d4c29095e05327ecd17e3d1f175f0a857a6bcc95225df7772264a47ce4d1a79
7
+ data.tar.gz: 04f7580eda0674af8f4c60cf77519eaab5c190d333de77f9e62dd51ed1bce18d5f6d75a14cb32942ede04a5147d5c4a9f44fb6d8d6fb1c5ad69e92e193241220
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.1.1
4
+ Fixed postgres sequence not being set to MAX(id).
5
+
3
6
  ## 1.1.0
4
7
  **New**
5
8
  - **BREAKING** Brillo used to support loading your credentials from a YAML file at `/etc/ec2_secure_env.yml`
@@ -13,6 +13,10 @@ module Brillo
13
13
  ""
14
14
  end
15
15
 
16
+ def table_footer(klass)
17
+ ""
18
+ end
19
+
16
20
  def dump_structure_and_migrations(config)
17
21
  # Overrides the path the structure is dumped to in Rails >= 3.2
18
22
  ENV['SCHEMA'] = ENV['DB_STRUCTURE'] = config.dump_path.to_s
@@ -6,6 +6,16 @@ module Brillo
6
6
  password = config[:password] ? "-W#{config[:password]}" : ""
7
7
  "psql #{host} -U #{config[:username]} #{password} #{config[:database]}"
8
8
  end
9
+
10
+ # pgdump without schema does not set sequences, so we have to do it ourselves, or the first insert
11
+ # into a scrubbed table will fail on duplicate primary key
12
+ def table_footer(klass)
13
+ table_name = klass.table_name
14
+ <<-SQL
15
+ SELECT setval(pg_get_serial_sequence('#{table_name}', 'id'), coalesce(MAX(id),0) + 1, false)
16
+ FROM #{table_name};
17
+ SQL
18
+ end
9
19
  end
10
20
  end
11
21
  end
data/lib/brillo/config.rb CHANGED
@@ -3,11 +3,11 @@ module Brillo
3
3
  attr_reader :app_name, :compress, :obfuscations, :klass_association_map, :db, :transfer_config
4
4
 
5
5
  def initialize(options = {})
6
- @app_name = options.fetch("name")
7
- @klass_association_map = options["explore"] || {}
8
- @compress = options.fetch("compress", true)
9
- @transfer_config = Transferrer::Config.new(options.fetch("transfer", {}))
10
- @obfuscations = parse_obfuscations(options["obfuscations"] || {})
6
+ @app_name = options.fetch(:name)
7
+ @klass_association_map = options[:explore] || {}
8
+ @compress = options.fetch(:compress, true)
9
+ @transfer_config = Transferrer::Config.new(**options.fetch(:transfer, {}))
10
+ @obfuscations = parse_obfuscations(options[:obfuscations] || {})
11
11
  rescue KeyError => e
12
12
  raise ConfigParseError, e
13
13
  end
@@ -18,7 +18,7 @@ module Brillo
18
18
  raise ConfigParseError, "Scrub strategy '#{strategy}' not found, but required by '#{field}'"
19
19
  end
20
20
  @klass_association_map.each do |klass, _|
21
- next if klass.camelize.safe_constantize
21
+ next if klass.to_s.camelize.safe_constantize
22
22
  raise ConfigParseError, "Class #{klass} not found"
23
23
  end
24
24
  self
@@ -73,13 +73,13 @@ module Brillo
73
73
  end
74
74
 
75
75
  # Convert generic cross table obfuscations to symbols so Polo parses them correctly
76
- # "my_table.field" => "my_table.field"
77
- # "my_field" => :my_field
76
+ # :"my_table.field" => "my_table.field"
77
+ # :my_field => :my_field
78
78
  def parse_obfuscations(obfuscations)
79
79
  obfuscations.each_pair.with_object({}) do |field_and_strategy, hash|
80
80
  field, strategy = field_and_strategy
81
81
  strategy = strategy.to_sym
82
- field.match(/\./) ? hash[field] = strategy : hash[field.to_sym] = strategy
82
+ field.to_s.match(/\./) ? hash[field.to_s] = strategy : hash[field] = strategy
83
83
  end
84
84
  end
85
85
  end
@@ -46,16 +46,19 @@ module Brillo
46
46
  klass_association_map.each do |klass, options|
47
47
  begin
48
48
  klass = deserialize_class(klass)
49
- tactic = deserialize_tactic(options)
49
+ tactic = deserialize_tactic(klass, options)
50
50
  rescue ConfigParseError => e
51
51
  logger.error "Error in brillo.yml: #{e.message}"
52
52
  next
53
53
  end
54
- associations = options.fetch("associations", [])
54
+ associations = options.fetch(:associations, [])
55
55
  explore_class(klass, tactic, associations) do |insert|
56
56
  sql_file.puts(insert)
57
57
  end
58
58
  end
59
+ ActiveRecord::Base.descendants.each do |klass|
60
+ sql_file.puts(adapter.table_footer(klass))
61
+ end
59
62
  sql_file.puts(adapter.footer)
60
63
  end
61
64
  end
@@ -97,13 +100,13 @@ module Brillo
97
100
  end
98
101
 
99
102
  def deserialize_class(klass)
100
- klass.camelize.constantize
103
+ klass.to_s.camelize.constantize
101
104
  rescue
102
- raise Config::ConfigParseError, "Could not process class '#{klass}'"
105
+ raise ConfigParseError, "Could not process class '#{klass}'"
103
106
  end
104
107
 
105
- def deserialize_tactic(options)
106
- options.fetch("tactic").to_sym
108
+ def deserialize_tactic(klass, options)
109
+ options.fetch(:tactic).to_sym
107
110
  rescue KeyError
108
111
  raise ConfigParseError, "Tactic not specified for class #{klass}"
109
112
  end
@@ -24,6 +24,7 @@ module Brillo
24
24
 
25
25
  def download
26
26
  return unless enabled
27
+ logger.info("download from s3 #{bucket} #{path}")
27
28
  FileUtils.rm path, force: true
28
29
  client.get_object({bucket: bucket, key: path.to_s}, target: path)
29
30
  rescue Aws::S3::Errors::NoSuchBucket
@@ -33,6 +34,7 @@ module Brillo
33
34
 
34
35
  def upload
35
36
  return unless enabled
37
+ logger.info("uploading to s3 #{bucket} #{path}")
36
38
  object = resource.bucket(bucket).object(path.to_s)
37
39
  object.upload_file(path)
38
40
  rescue Aws::S3::Errors::NoSuchBucket
@@ -1,3 +1,3 @@
1
1
  module Brillo
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
data/lib/brillo.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'yaml'
2
- require 'active_support'
2
+ require 'active_support/hash_with_indifferent_access'
3
3
  require 'active_support/core_ext/string/inflections'
4
4
  require 'active_record'
5
5
  require "brillo/version"
@@ -44,7 +44,7 @@ module Brillo
44
44
 
45
45
  def self.config
46
46
  @config ||= begin
47
- static_config = YAML.load_file("#{Rails.root.to_s}/config/brillo.yml")
47
+ static_config = YAML.load_file("#{Rails.root.to_s}/config/brillo.yml").deep_symbolize_keys
48
48
  Config.new(static_config)
49
49
  end
50
50
  end
@@ -8,7 +8,7 @@ namespace :db do
8
8
  logger.level = ENV["VERBOSE"] ? Logger::DEBUG : Logger::WARN
9
9
  begin
10
10
  Brillo.scrub!(logger: logger)
11
- rescue CredentialsError => e
11
+ rescue Brillo::CredentialsError => e
12
12
  puts e
13
13
  exit(1)
14
14
  end
@@ -18,7 +18,7 @@ namespace :db do
18
18
  task :load => :environment do
19
19
  begin
20
20
  Brillo.load!
21
- rescue CredentialsError => e
21
+ rescue Brillo::CredentialsError => e
22
22
  puts e
23
23
  exit(1)
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brillo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Bessey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-03 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake