bartask 0.1.0 → 0.1.2

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: 46e1cce930119b586806da631fc6d3e818ab8ed4b238f9560aad332471799231
4
- data.tar.gz: 8b4cbe91dd8454c1d5feb44077078bd4be43ee408291ae1e34d6d2021d1167dd
3
+ metadata.gz: 5c5bbc8dd14090413f10d88eb983b6c6e3f77343e46ba9995ac92d2e12347724
4
+ data.tar.gz: ee7829dd51a8423233b9f5a17665d54ce9af5747cbe0a540b2b4a8ca7f3513fe
5
5
  SHA512:
6
- metadata.gz: 8432407cd0719a035f6d074d4e6203da54438080a82033dae43de8d4955fc54e418d94f900671979dd7f8b25306455332a26fa553a7f3c2291078ca6a6a31b9b
7
- data.tar.gz: 4ad33a81804d421d0c6aa0baf29aca6cc24b67918195b93c8813e8aa5678a1aa23be6b2a1a915a6c825467691dc2f3a9342128a6ecb50bade793d8b7c99d0cb8
6
+ metadata.gz: 68aeae9809b6dc91c22281e99c41673fd02d09fd2ff234d5c7bf09dfed5d460b6d2773d96ba7e2caf0d37b3c8383609d4429c66b471d43c385e15fe366a259f4
7
+ data.tar.gz: c7b953ba407b1ed8b4f1a68b8af6d7e7e86e4d51f01bf25935ba12d654bb55f20c674ea75ee05d0ebe71a8fc3028c8a61a22b71ba3d7c123e91e0c33cb9624e4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.2] - 2025-09-25
4
+
5
+ - Show a confirm dialog before dumping and restoring
6
+
7
+ ## [0.1.1] - 2024-12-26
8
+
9
+ - Allow to specify the dump file path via args
10
+
3
11
  ## [0.1.0] - 2024-12-11
4
12
 
5
13
  - Initial release
data/Rakefile CHANGED
@@ -3,6 +3,8 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "minitest/test_task"
5
5
 
6
- Minitest::TestTask.create
6
+ Minitest::TestTask.create do |t|
7
+ t.verbose = true
8
+ end
7
9
 
8
10
  task default: :test
data/lib/bartask/base.rb CHANGED
@@ -7,13 +7,16 @@ require "open3"
7
7
 
8
8
  module Bartask
9
9
  class Base
10
- def initialize(config_file_path: nil)
10
+ def initialize(config_file_path: nil, dump_file_path: nil)
11
11
  @config_file_path = config_file_path || Pathname.new("config/database.yml")
12
+ @specified_dump_file_path = dump_file_path
12
13
  parse_config_file
13
14
  end
14
15
 
15
16
  def dump_file_path
16
17
  @dump_file_path ||= begin
18
+ return @specified_dump_file_path unless @specified_dump_file_path.nil?
19
+
17
20
  suffix = branch_name.empty? ? "" : "_#{branch_name}"
18
21
  Pathname.new("tmp/#{@config["database"]}#{suffix}.dump")
19
22
  end
@@ -40,7 +43,7 @@ module Bartask
40
43
  def branch_name
41
44
  @branch_name ||= begin
42
45
  stdout, _, _ = Open3.capture3("git name-rev --name-only HEAD")
43
- stdout.strip
46
+ stdout.strip.gsub("/", "_")
44
47
  end
45
48
  end
46
49
 
@@ -62,5 +65,13 @@ module Bartask
62
65
  options.push(*%w[--clean --no-owner --no-acl])
63
66
  options
64
67
  end
68
+
69
+ def confirm(message)
70
+ return true if ENV["BARTASK_SKIP_CONFIRM"] == "true" || ENV["RAILS_ENV"] == "test"
71
+
72
+ $stdout.print "#{message} (y/N): "
73
+ response = $stdin.gets.chomp
74
+ response.downcase == 'y' || response.downcase == 'yes'
75
+ end
65
76
  end
66
77
  end
data/lib/bartask/cli.rb CHANGED
@@ -7,9 +7,9 @@ class Bartask::Cli
7
7
  options = cli.parse
8
8
 
9
9
  if options[:mode] == "r"
10
- Bartask::Restorer.new(config_file_path: options[:config]).execute
10
+ Bartask::Restorer.new(config_file_path: options[:config], dump_file_path: options[:dump]).execute
11
11
  else
12
- Bartask::Dumper.new(config_file_path: options[:config]).execute
12
+ Bartask::Dumper.new(config_file_path: options[:config], dump_file_path: options[:dump]).execute
13
13
  end
14
14
  end
15
15
  end
@@ -44,7 +44,7 @@ class Bartask::Cli
44
44
 
45
45
  def global_command
46
46
  @global_command ||= OptionParser.new do |opts|
47
- opts.banner = "Usage: #{CMD} [options] [subcommand [options]]"
47
+ opts.banner = "Usage: #{CMD} [subcommand] [options]"
48
48
  opts.separator ""
49
49
  opts.separator USAGE
50
50
  end
@@ -58,6 +58,10 @@ class Bartask::Cli
58
58
  opts.on("-C", "--config PATH", "Config file path") do |v|
59
59
  @options[:config] = v
60
60
  end
61
+
62
+ opts.on("-D", "--dump PATH", "Dump file path") do |v|
63
+ @options[:dump] = v
64
+ end
61
65
  end,
62
66
  'r' => OptionParser.new do |opts|
63
67
  opts.banner = "Usage: #{CMD} r [options]"
@@ -65,6 +69,10 @@ class Bartask::Cli
65
69
  opts.on("-C", "--config PATH", "Config file path") do |v|
66
70
  @options[:config] = v
67
71
  end
72
+
73
+ opts.on("-D", "--dump PATH", "Dump file path") do |v|
74
+ @options[:dump] = v
75
+ end
68
76
  end
69
77
  }
70
78
  end
@@ -3,6 +3,11 @@
3
3
  module Bartask
4
4
  class Dumper < Base
5
5
  def execute
6
+ unless confirm("Are you sure you want to dump the database to '#{dump_file_path}'?")
7
+ $stdout.puts "Dump operation cancelled."
8
+ return
9
+ end
10
+
6
11
  if mysql?
7
12
  system("mysqldump #{build_options_for_mysql.join(' ')} > #{dump_file_path}")
8
13
  elsif postgresql?
@@ -3,6 +3,11 @@
3
3
  module Bartask
4
4
  class Restorer < Base
5
5
  def execute
6
+ unless confirm("Are you sure you want to restore the database from '#{dump_file_path}'? This will overwrite existing data.")
7
+ $stdout.puts "Restore operation cancelled."
8
+ return
9
+ end
10
+
6
11
  if mysql?
7
12
  system("mysql #{build_options_for_mysql.join(' ')} < #{dump_file_path}", exception: true)
8
13
  elsif postgresql?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bartask
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bartask
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Yaginuma
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -24,7 +23,6 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '0'
27
- description:
28
26
  email:
29
27
  - yuuji.yaginuma@gmail.com
30
28
  executables:
@@ -49,7 +47,6 @@ licenses:
49
47
  - MIT
50
48
  metadata:
51
49
  homepage_uri: https://github.com/y-yagi/bartask
52
- post_install_message:
53
50
  rdoc_options: []
54
51
  require_paths:
55
52
  - lib
@@ -64,8 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
61
  - !ruby/object:Gem::Version
65
62
  version: '0'
66
63
  requirements: []
67
- rubygems_version: 3.5.22
68
- signing_key:
64
+ rubygems_version: 3.6.7
69
65
  specification_version: 4
70
66
  summary: Backup and Recovery tool for RDBMS of Rails development.
71
67
  test_files: []