dumpcar 0.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36f1dd091285da9e5736495a0ffc53e2b73176cc327a6d138f2ea8663e0b4d6a
4
- data.tar.gz: 38d4fe0b357fc007491a154b6203a31514d22f17a21f38c40cfb0fe64eb7d8c9
3
+ metadata.gz: ee8d684348fb3890c5e4b440c594dc98f4a088d35f508bcad10b785b1c8a786c
4
+ data.tar.gz: f4ac59ac50c529a8be9003d3f616b7e75043b87a2023a146e5fbf6730a3d3a38
5
5
  SHA512:
6
- metadata.gz: 0bbe63e7e62033e29df0e1ae907adfbe03edede801be02af50dd551bdc7d98bf41874ff2c46ca790813f18ec34068846f0905fbec696cd78fb61df31978675ec
7
- data.tar.gz: a9f5a753441535c546e4c2b20af60f8b8b9ea3c4cb42ef9db7aa74bc68780ab84ede78d24d8fd8eea2f11d39a97341a1231d660e164eca8660fa1c07151c6fab
6
+ metadata.gz: 463ad770e9cc2c136c471bda67fe4a526f00c6c0025c79746a4579fd72f1b72668d5dddf3e25055246b821881abfb2859d76cea7c241e7b2f53295d301f3c241
7
+ data.tar.gz: ecc724aad06a3bffe85bd4a4ab9360fa0ee95a9f0cca55f1fddc65e31714743eb5be1396d48e7d7d6e70b506c52392006af156031185055543541fd5e2d03cd1
@@ -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
- // "customizations": {},
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
- [![Ruby Gem version](https://badge.fury.io/rb/dumpcar.svg)](https://rubygems.org/gems/dumpcar)
3
+ [![Ruby Gem version](https://badge.fury.io/rb/dumpcar.svg)](https://rubygems.org/gems/dumpcar) [![Ruby build](https://github.com/wwahammy/dumpcar/actions/workflows/main.yml/badge.svg)](https://github.com/wwahammy/dumpcar/actions/workflows/main.yml)
4
4
 
5
- Rake tasks for dumping and restoring the contents of the PostgreSQL database for your Rails application.
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
8
  - Uses your Rails database credentials for your environment
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
@@ -41,6 +41,9 @@ Outside of the `rails dumpcar:dump` and `rails dumpcar:restore` commands, don't
41
41
 
42
42
  ## Development
43
43
 
44
+ NOTE: Using the Devcontainer is one of the easiest ways to get setup. Unfortunately, it also requires a no-charge but proprietary
45
+ extension VSCode to use.
46
+
44
47
  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
48
 
46
49
  ## 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
@@ -18,4 +18,8 @@ gem "debug"
18
18
  gem "rails", "~> 6.0.0"
19
19
  gem "concurrent-ruby", "1.3.4"
20
20
 
21
+ group :development do
22
+ gem "ruby-lsp-rspec", :require => false
23
+ end
24
+
21
25
  gemspec :path => "../"
@@ -18,4 +18,8 @@ gem "debug"
18
18
  gem "rails", "~> 6.1.0"
19
19
  gem "concurrent-ruby", "1.3.4"
20
20
 
21
+ group :development do
22
+ gem "ruby-lsp-rspec", :require => false
23
+ end
24
+
21
25
  gemspec :path => "../"
@@ -18,4 +18,8 @@ gem "debug"
18
18
  gem "rails", "~> 7.0.0"
19
19
  gem "concurrent-ruby", "1.3.4"
20
20
 
21
+ group :development do
22
+ gem "ruby-lsp-rspec", :require => false
23
+ end
24
+
21
25
  gemspec :path => "../"
@@ -17,4 +17,8 @@ gem "appraisal", :git => "https://github.com/pboling/appraisal.git", :ref => "c3
17
17
  gem "debug"
18
18
  gem "rails", "~> 7.1.0"
19
19
 
20
+ group :development do
21
+ gem "ruby-lsp-rspec", :require => false
22
+ end
23
+
20
24
  gemspec :path => "../"
@@ -17,4 +17,8 @@ gem "appraisal", :git => "https://github.com/pboling/appraisal.git", :ref => "c3
17
17
  gem "debug"
18
18
  gem "rails", "~> 7.2.0"
19
19
 
20
+ group :development do
21
+ gem "ruby-lsp-rspec", :require => false
22
+ end
23
+
20
24
  gemspec :path => "../"
@@ -17,4 +17,8 @@ gem "appraisal", :git => "https://github.com/pboling/appraisal.git", :ref => "c3
17
17
  gem "debug"
18
18
  gem "rails", "~> 8.0.0"
19
19
 
20
+ group :development do
21
+ gem "ruby-lsp-rspec", :require => false
22
+ end
23
+
20
24
  gemspec :path => "../"
@@ -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 => "../"
@@ -1,9 +1,14 @@
1
1
  module Dumpcar
2
2
  class Instance
3
- attr_reader :location, :pg
4
- def initialize(base: Rails.root.join("db/dumps"))
5
- @location = Location.new(base)
6
- @pg = Pg.new(Dumpcar::Util.get_connection_db_config)
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
@@ -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 :base
8
- def initialize(base)
9
- @base = Pathname.new base
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
- prepare_base!
14
- base.glob(TIMESTAMP_FILE_GLOB)
13
+ prepare_base_dir!
14
+ base_dir.glob(TIMESTAMP_FILE_GLOB)
15
15
  end
16
16
 
17
17
  def first
18
- prepare_base!
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
- prepare_base!
27
+ prepare_base_dir!
28
28
  dumps.last
29
29
  end
30
30
 
31
31
  def next
32
- prepare_base!
33
- base.join(from_time + ".dump").to_s
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 prepare_base!
43
- FileUtils.mkdir_p base
42
+ def prepare_base_dir!
43
+ FileUtils.mkdir_p base_dir
44
44
  end
45
45
  end
46
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dumpcar
4
- VERSION = "0.2"
4
+ VERSION = "0.3"
5
5
  end
@@ -1,15 +1,17 @@
1
1
  class DumpcarCommand < Rails::Command::Base
2
- class_option :base, type: :string, desc: "the location of your DB dumps, defaults to Rails.root.join('db/dumps')"
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
+ (Rails.version < "6.1") ? require_application_and_environment! : boot_application!
6
7
  require "dumpcar"
7
- Dumpcar::Instance.new.dump
8
+ Dumpcar::Instance.new(options).dump
8
9
  end
9
10
 
10
11
  desc "restore", "Restore postgres backup file"
11
12
  def restore
13
+ (Rails.version < "6.1") ? require_application_and_environment! : boot_application!
12
14
  require "dumpcar"
13
- Dumpcar::Instance.new.restore
15
+ Dumpcar::Instance.new(options).restore
14
16
  end
15
17
  end
data/package-lock.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "": {
7
7
  "devDependencies": {
8
8
  "husky": "^9.0",
9
- "lint-staged": "^16.0",
10
- "prettier": "^3.0"
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.0",
256
- "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-16.1.0.tgz",
257
- "integrity": "sha512-HkpQh69XHxgCjObjejBT3s2ILwNjFx8M3nw+tJ/ssBauDlIpkx2RpqWSi1fBgkXLSSXnbR3iEq1NkVtpvV+FLQ==",
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.5.3",
444
- "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz",
445
- "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==",
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.0",
5
- "prettier": "^3.0"
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
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumpcar
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Schultz