dump_hook 0.0.2 → 0.0.3
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 +4 -4
- data/Gemfile +1 -1
- data/README.md +10 -3
- data/lib/dump_hook/version.rb +1 -1
- data/lib/dump_hook.rb +13 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cda4bb66293e266cdd96f7daf940f922ca709d917dc5ca56fc1968f5df807436
|
4
|
+
data.tar.gz: 6f84da0ff1bbd961e8f93b936b4d71a47616b8aaca3bbf2dceb98829591698b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33ad6577dae5c891182c5baa976aaaeaf6ca8583616ac36cb896330559494ac0a90053c95e310f46ad690bfe834a3ae788df84dba43c2c8446dd199d7131e4fa
|
7
|
+
data.tar.gz: c2fc9dc581736b336cd570b5a0064c5df4d9178abc243e0aff07e0b30a3657cc09e13b18448cca532b0a207061639caa2b52ad979bd0173a7ced5cc3e7e22857
|
data/Gemfile
CHANGED
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 '
|
10
|
+
gem 'dump_hook'
|
11
11
|
```
|
12
12
|
|
13
13
|
For Rspec/Capybara add to `rails_helper.rb`:
|
@@ -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
|
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
|
data/lib/dump_hook/version.rb
CHANGED
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.
|
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
|
@@ -111,4 +114,11 @@ module DumpHook
|
|
111
114
|
args.concat(['-p', settings.port]) if settings.port
|
112
115
|
args
|
113
116
|
end
|
117
|
+
|
118
|
+
def recreate?(filename)
|
119
|
+
DumpHook.recreate ||= []
|
120
|
+
result = (settings.recreate || ENV["DUMP_HOOK"] == "recreate") && !DumpHook.recreate.include?(filename)
|
121
|
+
DumpHook.recreate << filename if result
|
122
|
+
result
|
123
|
+
end
|
114
124
|
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.
|
4
|
+
version: 0.0.3
|
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
|
11
|
+
date: 2022-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: timecop
|