dumpcar 0.2 → 0.3.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 +4 -4
- data/.devcontainer/Dockerfile +0 -2
- data/.devcontainer/devcontainer.json +12 -3
- data/README.md +11 -5
- data/Rakefile +12 -0
- data/gemfiles/rails_6.0.gemfile +4 -0
- data/gemfiles/rails_6.1.gemfile +4 -0
- data/gemfiles/rails_7.0.gemfile +4 -0
- data/gemfiles/rails_7.1.gemfile +4 -0
- data/gemfiles/rails_7.2.gemfile +4 -0
- data/gemfiles/rails_8.0.gemfile +4 -0
- data/gemfiles/rails_edge.gemfile +4 -0
- data/lib/dumpcar/instance.rb +18 -4
- data/lib/dumpcar/location.rb +11 -11
- data/lib/dumpcar/version.rb +1 -1
- data/lib/rails/commands/dumpcar_command.rb +7 -3
- data/package-lock.json +8 -8
- data/package.json +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4098f5a361deb33a01b2bf1551a41c532de946f1bae2f418ebcf5d4739bf68e
|
4
|
+
data.tar.gz: d82319e62b40f0cd3b619da6e07e083faff7ecf1c0cf03105b9ea8463f1932c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80e2878b12006e0950a199cca67593ebec456f416b8f0529fda1a9753ca530303632ff8169a46f042f82d780a88afb264f100823bb7ffc76f95390601735829b
|
7
|
+
data.tar.gz: 505156796ac225a538c8da5e5233515ef3580fefaf0b688f257da4840022ec8a536e7b140105fc0485bae82b759dda245cef8d3c5219f51084bd4f4f38c320a5
|
data/.devcontainer/Dockerfile
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
FROM mcr.microsoft.com/devcontainers/ruby:1-3.2-bullseye
|
2
2
|
|
3
|
-
# Install Rails
|
4
|
-
RUN su vscode -c "gem install rails webdrivers"
|
5
3
|
RUN su vscode -c "/usr/local/rvm/bin/rvm fix-permissions"
|
6
4
|
|
7
5
|
# Default value to allow debug server to serve content over GitHub Codespace's port forwarding service
|
@@ -18,10 +18,19 @@
|
|
18
18
|
// "forwardPorts": [3000, 5432],
|
19
19
|
|
20
20
|
// Use 'postCreateCommand' to run commands after the container is created.
|
21
|
-
"postCreateCommand": "bin/setup"
|
22
|
-
|
21
|
+
"postCreateCommand": "bundle config set path vendor/bundle && bin/setup",
|
23
22
|
// Configure tool-specific properties.
|
24
|
-
|
23
|
+
"customizations": {
|
24
|
+
"vscode": {
|
25
|
+
"settings": {
|
26
|
+
"rubyLsp.addonSettings": {
|
27
|
+
"Ruby LSP RSpec": {
|
28
|
+
"rspecCommand": "rspec -f d"
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
25
34
|
|
26
35
|
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
27
36
|
// "remoteUser": "root"
|
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Dumpcar
|
2
2
|
|
3
|
-
[](https://rubygems.org/gems/dumpcar)
|
3
|
+
[](https://rubygems.org/gems/dumpcar) [](https://github.com/wwahammy/dumpcar/actions/workflows/main.yml)
|
4
4
|
|
5
|
-
|
5
|
+
Rails commands for dumping and restoring the contents of the PostgreSQL database for your Rails application.
|
6
6
|
|
7
7
|
- Dump (`rails dumpcar:dump`) and restore your last dump (`rails dumpcar:restore`) with a single command
|
8
|
-
- Uses your Rails database credentials for your environment
|
8
|
+
- Uses your Rails database credentials for your environment OR any Rails supported Postgres connection string (via `DATABASE_URL`)
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
|
-
Install the gem executing:
|
12
|
+
Install the gem by executing:
|
13
13
|
|
14
14
|
```bash
|
15
15
|
bundle add dumpcar
|
@@ -21,6 +21,9 @@ rails g dumpcar # creates db/dumps folder, adds it to .gitignore and commits
|
|
21
21
|
```bash
|
22
22
|
rails dumpcar:dump # creates a postgresql dump based on current time like db/dumps/20250601022124.dump
|
23
23
|
rails dumpcar:restore # restores the last dump made chronologically from the db/dumps directory
|
24
|
+
|
25
|
+
# You can use any Postgres connection string that Rails supports
|
26
|
+
DATABASE_URL=postgres://myuser:mypassword@domain.hosting.pg.db:5432/mydatabase rails dumpcar:dump # creates a postgresql dump of the database at DATABASE_URL
|
24
27
|
```
|
25
28
|
|
26
29
|
## Compatibility
|
@@ -29,7 +32,7 @@ Outside of the `rails dumpcar:dump` and `rails dumpcar:restore` commands, don't
|
|
29
32
|
|
30
33
|
## Longer term feature goals
|
31
34
|
|
32
|
-
- Support other Rails
|
35
|
+
- Support other Rails databases (MySQL and SQLite)
|
33
36
|
- Support other Rails environments than the current one
|
34
37
|
- Ability to clean your db/dumps directory of all dumps before a given time
|
35
38
|
- Add support for naming a dump (you can manually do this now but not via the rake task)
|
@@ -41,6 +44,9 @@ Outside of the `rails dumpcar:dump` and `rails dumpcar:restore` commands, don't
|
|
41
44
|
|
42
45
|
## Development
|
43
46
|
|
47
|
+
NOTE: Using the Devcontainer is one of the easiest ways to get setup. Unfortunately, it also requires a no-charge but proprietary
|
48
|
+
extension to VSCode to use.
|
49
|
+
|
44
50
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You should run `bin/appraisal rspec` to run all of the tests on all of the supported Rails versions. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
51
|
|
46
52
|
## Contributing
|
data/Rakefile
CHANGED
@@ -8,3 +8,15 @@ RSpec::Core::RakeTask.new(:spec)
|
|
8
8
|
require "standard/rake"
|
9
9
|
|
10
10
|
task default: %i[spec standard]
|
11
|
+
|
12
|
+
namespace :clean do
|
13
|
+
desc "Clean your tmp directory of copies of files used in rspec runs"
|
14
|
+
task :tmp do
|
15
|
+
tmp_dir_path = Pathname.new(__dir__).join("spec/internal/tmp")
|
16
|
+
tmp_dir_path.children.select { |file| file.basename.to_s != ".keep" }.each(&:rmtree)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Rake::Task[:clean].enhance do
|
21
|
+
Rake::Task["clean:tmp"].invoke
|
22
|
+
end
|
data/gemfiles/rails_6.0.gemfile
CHANGED
data/gemfiles/rails_6.1.gemfile
CHANGED
data/gemfiles/rails_7.0.gemfile
CHANGED
data/gemfiles/rails_7.1.gemfile
CHANGED
data/gemfiles/rails_7.2.gemfile
CHANGED
data/gemfiles/rails_8.0.gemfile
CHANGED
data/gemfiles/rails_edge.gemfile
CHANGED
@@ -17,4 +17,8 @@ gem "appraisal", :git => "https://github.com/pboling/appraisal.git", :ref => "c3
|
|
17
17
|
gem "debug"
|
18
18
|
gem "rails", :github => "rails/rails", :branch => "main"
|
19
19
|
|
20
|
+
group :development do
|
21
|
+
gem "ruby-lsp-rspec", :require => false
|
22
|
+
end
|
23
|
+
|
20
24
|
gemspec :path => "../"
|
data/lib/dumpcar/instance.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
module Dumpcar
|
2
2
|
class Instance
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
require "active_model"
|
4
|
+
include ActiveModel::Model
|
5
|
+
|
6
|
+
attr_accessor :connection, :location, :pg, :base_dir
|
7
|
+
def initialize(attributes = {})
|
8
|
+
cleanup_arguments(attributes)
|
9
|
+
@connection = Dumpcar::Util.get_connection_db_config
|
10
|
+
@location = Location.new(base_dir)
|
11
|
+
@pg = Pg.new(connection)
|
7
12
|
end
|
8
13
|
|
9
14
|
def dump
|
@@ -13,5 +18,14 @@ module Dumpcar
|
|
13
18
|
def restore
|
14
19
|
@pg.restore(@location.last)
|
15
20
|
end
|
21
|
+
|
22
|
+
def cleanup_arguments(arguments)
|
23
|
+
arguments = arguments.to_h.with_indifferent_access
|
24
|
+
unless arguments.has_key?("base_dir")
|
25
|
+
arguments["base_dir"] = Rails.root.join("db/dumps")
|
26
|
+
end
|
27
|
+
|
28
|
+
assign_attributes(arguments)
|
29
|
+
end
|
16
30
|
end
|
17
31
|
end
|
data/lib/dumpcar/location.rb
CHANGED
@@ -4,18 +4,18 @@ module Dumpcar
|
|
4
4
|
TIMESTAMP_GLOB = 14.times.map { "[0-9]" }.join
|
5
5
|
TIMESTAMP_FILE_GLOB = TIMESTAMP_GLOB + "*.dump"
|
6
6
|
|
7
|
-
attr_reader :
|
8
|
-
def initialize(
|
9
|
-
@
|
7
|
+
attr_reader :base_dir
|
8
|
+
def initialize(base_dir)
|
9
|
+
@base_dir = Pathname.new base_dir
|
10
10
|
end
|
11
11
|
|
12
12
|
def dumps
|
13
|
-
|
14
|
-
|
13
|
+
prepare_base_dir!
|
14
|
+
base_dir.glob(TIMESTAMP_FILE_GLOB)
|
15
15
|
end
|
16
16
|
|
17
17
|
def first
|
18
|
-
|
18
|
+
prepare_base_dir!
|
19
19
|
dumps.first
|
20
20
|
end
|
21
21
|
|
@@ -24,13 +24,13 @@ module Dumpcar
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def last
|
27
|
-
|
27
|
+
prepare_base_dir!
|
28
28
|
dumps.last
|
29
29
|
end
|
30
30
|
|
31
31
|
def next
|
32
|
-
|
33
|
-
|
32
|
+
prepare_base_dir!
|
33
|
+
base_dir.join(from_time + ".dump").to_s
|
34
34
|
end
|
35
35
|
|
36
36
|
def from_time(time = Time.now.utc)
|
@@ -39,8 +39,8 @@ module Dumpcar
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
-
def
|
43
|
-
FileUtils.mkdir_p
|
42
|
+
def prepare_base_dir!
|
43
|
+
FileUtils.mkdir_p base_dir
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/lib/dumpcar/version.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
class DumpcarCommand < Rails::Command::Base
|
2
|
-
class_option :
|
2
|
+
class_option :base_dir, type: :string, desc: "the location of your DB dumps, defaults to Rails.root.join('db/dumps')"
|
3
3
|
|
4
4
|
desc "dump", "Dump postgres backup file"
|
5
5
|
def dump
|
6
|
+
require "rails"
|
7
|
+
(Rails.version < "7.1") ? require_application_and_environment! : boot_application!
|
6
8
|
require "dumpcar"
|
7
|
-
Dumpcar::Instance.new.dump
|
9
|
+
Dumpcar::Instance.new(options).dump
|
8
10
|
end
|
9
11
|
|
10
12
|
desc "restore", "Restore postgres backup file"
|
11
13
|
def restore
|
14
|
+
require "rails"
|
15
|
+
(Rails.version < "7.1") ? require_application_and_environment! : boot_application!
|
12
16
|
require "dumpcar"
|
13
|
-
Dumpcar::Instance.new.restore
|
17
|
+
Dumpcar::Instance.new(options).restore
|
14
18
|
end
|
15
19
|
end
|
data/package-lock.json
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
"": {
|
7
7
|
"devDependencies": {
|
8
8
|
"husky": "^9.0",
|
9
|
-
"lint-staged": "^16.
|
10
|
-
"prettier": "^3.
|
9
|
+
"lint-staged": "^16.1",
|
10
|
+
"prettier": "^3.6"
|
11
11
|
}
|
12
12
|
},
|
13
13
|
"node_modules/ansi-escapes": {
|
@@ -252,9 +252,9 @@
|
|
252
252
|
}
|
253
253
|
},
|
254
254
|
"node_modules/lint-staged": {
|
255
|
-
"version": "16.1.
|
256
|
-
"resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-16.1.
|
257
|
-
"integrity": "sha512-
|
255
|
+
"version": "16.1.2",
|
256
|
+
"resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-16.1.2.tgz",
|
257
|
+
"integrity": "sha512-sQKw2Si2g9KUZNY3XNvRuDq4UJqpHwF0/FQzZR2M7I5MvtpWvibikCjUVJzZdGE0ByurEl3KQNvsGetd1ty1/Q==",
|
258
258
|
"dev": true,
|
259
259
|
"license": "MIT",
|
260
260
|
"dependencies": {
|
@@ -440,9 +440,9 @@
|
|
440
440
|
}
|
441
441
|
},
|
442
442
|
"node_modules/prettier": {
|
443
|
-
"version": "3.
|
444
|
-
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.
|
445
|
-
"integrity": "sha512-
|
443
|
+
"version": "3.6.0",
|
444
|
+
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.0.tgz",
|
445
|
+
"integrity": "sha512-ujSB9uXHJKzM/2GBuE0hBOUgC77CN3Bnpqa+g80bkv3T3A93wL/xlzDATHhnhkzifz/UE2SNOvmbTz5hSkDlHw==",
|
446
446
|
"dev": true,
|
447
447
|
"license": "MIT",
|
448
448
|
"bin": {
|
data/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"devDependencies": {
|
3
3
|
"husky": "^9.0",
|
4
|
-
"lint-staged": "^16.
|
5
|
-
"prettier": "^3.
|
4
|
+
"lint-staged": "^16.1",
|
5
|
+
"prettier": "^3.6"
|
6
6
|
},
|
7
7
|
"scripts": {
|
8
8
|
"prepare": "husky"
|
@@ -10,6 +10,6 @@
|
|
10
10
|
"lint-staged": {
|
11
11
|
"*.{js,css,md,yml}": "prettier --write",
|
12
12
|
"*.{rb,rake,gemspec,ru}": "bin/standardrb --fix",
|
13
|
-
"Gemfile": "bin/standardrb --fix"
|
13
|
+
"{Gemfile,Rakefile}": "bin/standardrb --fix"
|
14
14
|
}
|
15
15
|
}
|