dump_hook 0.0.2 → 0.0.4

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
  SHA256:
3
- metadata.gz: 7e3ab2dfea012e21d78286bb192ea9991f56f796877d917c9afc5a5720a58c13
4
- data.tar.gz: 9088a1c0514ec39ea1c185d5b560b6c309a4840c28481df7a82a553f647d1363
3
+ metadata.gz: 8d29f2bfed5e365d91f2a090dcf8d0385cffb0dab73d5978f8632e1438148e62
4
+ data.tar.gz: 30231c00145a5ef5fbdc45503c6522e38edef79a57dd4a85f0229a70f060a374
5
5
  SHA512:
6
- metadata.gz: 1e2fcfa0fbfc91aa1203b918f0b654fa2b071cbb8a747a1a0b765263d8615d56cbf574ef60a7777177c0a262a87c152bcc25ed52ccbd0d45f0e522747160ed25
7
- data.tar.gz: 4b9bae4d2badc64e58d94e4aa16f5c0b8b3a1d4d52c2f602f98860006ab3fb70fc7abb3e3addbfd1a3f80633afdf000b9be72d8d2fe0eb00407b9e98e196548f
6
+ metadata.gz: 8ef067168e702f8761127af0cc6cc51ba724aca2ace1c42a009fe2f2259aa83bd1e61b90b819f743d4a2a92edf00dfea0cae003830b40f9ee51704c64fac113d
7
+ data.tar.gz: 4fc68d8c8312fd901ae28aaf9b66abc2ebec3fd2c387cdbec130bdd677ab5f29a8c198d6e0d932f3f5400408ffbec690aba3e0f89530ec05f919fd65ca8c17f1
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in dump-hook.gemspec
3
+ # Specify your gem's dependencies in dump_hook.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -7,7 +7,7 @@ you need to take care about other sources your own.
7
7
  ## Installation
8
8
 
9
9
  ```ruby
10
- gem 'dump-hook'
10
+ gem 'dump_hook'
11
11
  ```
12
12
 
13
13
  For Rspec/Capybara add to `rails_helper.rb`:
@@ -33,7 +33,7 @@ There are several parameters to run and manage it.
33
33
  ```ruby
34
34
  DumpHook.setup do |config|
35
35
  config.database = ActiveRecord::Base.configurations[Rails.env]["database"]
36
- config.actual = Date.today.monday.to_s(:number)
36
+ config.actual = Date.today.monday.strftime('%Y%m%d')
37
37
  end
38
38
  ```
39
39
 
@@ -45,7 +45,7 @@ end
45
45
  * `password` - password to connect, works just for MySql
46
46
  * `database_type` - `postgres`/`mysql`, by default it's `postgres`
47
47
 
48
- It looks like `database` is a single required parameter. Others may be default for you DB connection. In relation to
48
+ It looks like `database` is a single required parameter. Others may be default for your DB connection. In relation to
49
49
  `password` for `postgres` you need to use the url way in `database` parameter in order to set `password`. You may use
50
50
  the gem `database_url` to get this url.
51
51
 
@@ -58,11 +58,18 @@ may set it to `Date.current` to recreate your dumps every day. By default it's e
58
58
  * `remove_old_dumps` - when `actual` is pointed your old dumps will be removed. By default it's `true`.
59
59
  * `dumps_location` - by default it's `tmp/dump_hook`. You may pass something more exciting, e.g your current git branch
60
60
  or some path to store your dumps in your repo and generate them using CI.
61
+ * `recreate` - by default it's `false`. It recreates your dumps in the current session. It helps when you change
62
+ `execute_with_dump`'s body. You can set it through `ENV` variable `DUMP_HOOK=recreate` for some certain tests.
63
+ ```shell
64
+ $ DUMP_HOOK=recreate rails test test/system/your_test.rb
65
+ ```
61
66
 
62
67
  ## Usage
63
68
 
64
69
  *Attention!* It works for clear DB. In case when you have some previous data you may come across with conflicts or
65
- incorrect data which may influence your tests.
70
+ incorrect data which may influence your tests. Yet one vital moment you cannot use the *transactional* way in your tests
71
+ as `dump_hook` will not be able to store anything. Our benchmarks don't note some difference for our system tests and we
72
+ prefer to use the same way as in the production environment. We hope you go by this rule too.
66
73
 
67
74
  There is just single method what wrap your actions and restore dump again
68
75
  ```ruby
@@ -1,3 +1,3 @@
1
1
  module DumpHook
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/dump_hook.rb CHANGED
@@ -7,6 +7,7 @@ module DumpHook
7
7
  :dumps_location,
8
8
  :remove_old_dumps,
9
9
  :actual,
10
+ :recreate,
10
11
  :database_type,
11
12
  :username,
12
13
  :password,
@@ -18,11 +19,12 @@ module DumpHook
18
19
  @database_type = 'postgres'
19
20
  @dumps_location = 'tmp/dump_hook'
20
21
  @remove_old_dumps = true
22
+ @recreate = false
21
23
  end
22
24
  end
23
25
 
24
26
  class << self
25
- attr_accessor :settings
27
+ attr_accessor :settings, :recreate
26
28
  end
27
29
 
28
30
  def self.setup
@@ -35,7 +37,7 @@ module DumpHook
35
37
  actual = opts[:actual] || settings.actual
36
38
  create_dirs_if_not_exists
37
39
  filename = full_filename(name, created_on, actual)
38
- if File.exists?(filename)
40
+ if !recreate?(filename) && File.exist?(filename)
39
41
  restore_dump(filename)
40
42
  else
41
43
  if created_on
@@ -56,7 +58,7 @@ module DumpHook
56
58
  def store_dump(filename)
57
59
  case settings.database_type
58
60
  when 'postgres'
59
- args = ['-a', '-x', '-O', '-f', filename, '-Fc', '-T', 'schema_migrations']
61
+ args = ['-a', '-x', '-O', '-f', filename, '-Fc', '-T', 'schema_migrations', '-T', 'ar_internal_metadata']
60
62
  args.concat(pg_connection_args)
61
63
  Kernel.system("pg_dump", *args)
62
64
  when 'mysql'
@@ -64,6 +66,7 @@ module DumpHook
64
66
  args << "--compress"
65
67
  args.concat ["--result-file", filename]
66
68
  args.concat ["--ignore-table", "#{settings.database}.schema_migrations"]
69
+ args.concat ["--ignore-table", "#{settings.database}.ar_internal_metadata"]
67
70
  Kernel.system("mysqldump", *args)
68
71
  end
69
72
  end
@@ -71,7 +74,8 @@ module DumpHook
71
74
  def restore_dump(filename)
72
75
  case settings.database_type
73
76
  when 'postgres'
74
- args = pg_connection_args
77
+ args = ['--single-transaction']
78
+ args.concat(pg_connection_args)
75
79
  args << filename
76
80
  Kernel.system("pg_restore", *args)
77
81
  when 'mysql'
@@ -84,7 +88,7 @@ module DumpHook
84
88
  def full_filename(name, created_on, actual)
85
89
  name_with_created_on = name
86
90
  if created_on
87
- name_with_created_on = "#{name_with_created_on}_#{created_on.to_s(:number)}"
91
+ name_with_created_on = "#{name_with_created_on}_#{created_on.strftime('%Y%m%d')}"
88
92
  elsif actual
89
93
  name_with_created_on = "#{name_with_created_on}_actual#{actual}"
90
94
  end
@@ -111,4 +115,11 @@ module DumpHook
111
115
  args.concat(['-p', settings.port]) if settings.port
112
116
  args
113
117
  end
118
+
119
+ def recreate?(filename)
120
+ DumpHook.recreate ||= []
121
+ result = (settings.recreate || ENV["DUMP_HOOK"] == "recreate") && !DumpHook.recreate.include?(filename)
122
+ DumpHook.recreate << filename if result
123
+ result
124
+ end
114
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dump_hook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Ryazantsev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-28 00:00:00.000000000 Z
11
+ date: 2026-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: timecop