dumpcar 0.1.0

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.
data/LGPL-3.0.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ # Free Software Licensing Information for Dumpcar.
2
+
3
+ The primary license of the Dumpcar is:
4
+
5
+ LGPL-3.0-or-later
6
+
7
+ You can copy, convey, propagate, redistribute and/or modify this program
8
+ under the terms of the GNU General Public License (GPL) as published by
9
+ the Free Software Foundation (FSF), either version 3 of the License, or
10
+ (at your option) any later version of the GPL published by the FSF.
11
+
12
+ This program is distributed in the hope that it will be useful, but
13
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
15
+ License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License along
18
+ with this program in a file in the toplevel directory called
19
+ "GPL-3.0.txt". If not, see <http://www.gnu.org/licenses/>.
20
+
21
+ In addition to the permission granted by the GPLv3, you also receive
22
+ permissions as written in GNU Lesser General Public License (LGPL),
23
+ Version 3.0, as published by the Free Software Foundation (FSF), either
24
+ version 3 of the License, or (at your option) any later version of the
25
+ LGPL published by the FSF.
26
+
27
+ This program is distributed in the hope that it will be useful, but
28
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
29
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30
+ for more details.
31
+
32
+ You should have received a copy of the GNU Lesser General Public License
33
+ along with this program in a file in the toplevel directory called
34
+ "LGPL-3.0.txt". If not, see <http://www.gnu.org/licenses/>.
35
+
36
+ ## Licenses for files in Dumpcar Repository.
37
+
38
+ 1. Any file in the Dumpcar repository that does not specify a license, or is
39
+ not discussed explicitly in this toplevel "LICENSE" file is licensed:
40
+
41
+ LGPL-3.0-or-later
42
+
43
+ as specified in detail above.
44
+
data/NOTICES ADDED
@@ -0,0 +1,24 @@
1
+ pg_backup:
2
+
3
+ Copyright (c) 2015 Marcus Geissler
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Rails::Db::Dump
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dumpcar`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wwahammy/dumpcar. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/wwahammy/dumpcar/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Rails::Db::Dump project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/wwahammy/dumpcar/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
data/config.ru ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+
6
+ Bundler.require :default, :development
7
+
8
+ Combustion.initialize! :all
9
+ run Combustion::Application
@@ -0,0 +1,25 @@
1
+ class DumpcarGenerator < Rails::Generators::Base
2
+ def add_db_dumps_dir
3
+ create_file("db/dumps/.keep", "")
4
+ end
5
+
6
+ def add_keep_to_git
7
+ git add: "db/dumps/.keep"
8
+ end
9
+
10
+ def gitignore_db_dumps
11
+ insert_into_file ".gitignore", <<~RUBY
12
+
13
+ # dumpcar dumps
14
+ /db/dumps
15
+ RUBY
16
+ end
17
+
18
+ def add_gitignore_to
19
+ git add: ".gitignore"
20
+ end
21
+
22
+ def commit_git
23
+ git commit: '-m "Added dumpcar .gitignore"'
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module Dumpcar
2
+ class Instance
3
+ attr_reader :location, :pg
4
+ def initialize(base: Rails.root.join("db/dumps"), connection: ActiveRecord::Base.connection_db_config.configuration_hash)
5
+ @location = Location.new(base)
6
+ @pg = Pg.new(connection)
7
+ end
8
+
9
+ def dump
10
+ @pg.dump(@location.next)
11
+ end
12
+
13
+ def restore
14
+ @pg.restore(@location.last)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ module Dumpcar
2
+ class Location
3
+ TIMESTAMP_STRFTIME_FORMAT = "%Y%m%d%H%M%S"
4
+ TIMESTAMP_GLOB = 14.times.map { "[0-9]" }.join
5
+ TIMESTAMP_FILE_GLOB = TIMESTAMP_GLOB + "*.dump"
6
+
7
+ attr_reader :base
8
+ def initialize(base)
9
+ @base = Pathname.new base
10
+ end
11
+
12
+ def dumps
13
+ prepare_base!
14
+ Dir.glob(base.join(TIMESTAMP_FILE_GLOB))
15
+ end
16
+
17
+ def first
18
+ prepare_base!
19
+ dumps.first
20
+ end
21
+
22
+ def last
23
+ prepare_base!
24
+ dumps.last
25
+ end
26
+
27
+ def next
28
+ prepare_base!
29
+ base.join(from_time + ".dump").to_s
30
+ end
31
+
32
+ def from_time(time = Time.now.utc)
33
+ time.strftime(TIMESTAMP_STRFTIME_FORMAT)
34
+ end
35
+
36
+ private
37
+
38
+ def prepare_base!
39
+ FileUtils.mkdir_p base
40
+ end
41
+ end
42
+ end
data/lib/dumpcar/pg.rb ADDED
@@ -0,0 +1,38 @@
1
+ module Dumpcar
2
+ class Pg
3
+ attr_reader :connection
4
+
5
+ def initialize(connection)
6
+ @connection = connection
7
+ end
8
+
9
+ def restore(filename)
10
+ with_database_config do |config|
11
+ config => {password:, host:, port:, username:, database:}
12
+ result = "PGPASSWORD=#{password} pg_restore --verbose --clean --no-acl --no-owner -h #{host} -U #{username} -d #{database} -p #{port} #{filename}"
13
+ puts result
14
+ `#{result} `
15
+ end
16
+ end
17
+
18
+ def dump(filename)
19
+ with_database_config do |config|
20
+ config => {password:, host:, port:, username:, database:}
21
+ result = "PGPASSWORD=#{password} pg_dump --host #{host} --port #{port} --username #{username} --clean --format=c --create --if-exists --no-owner --no-acl #{database} --file=#{filename}"
22
+ puts result
23
+ `#{result} `
24
+ end
25
+ end
26
+
27
+ def with_database_config
28
+ yield self.class.defaults.merge(connection)
29
+ end
30
+
31
+ def self.defaults
32
+ {
33
+ host: "localhost",
34
+ port: "5432"
35
+ }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ module Dumpcar
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load "dumpcar/tasks/dump.rake"
5
+ end
6
+
7
+ generators do
8
+ load "dumpcar/generators/dumpcar_generator.rb"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ namespace :dumpcar do
2
+ namespace :pg do
3
+ desc "Dumped postgres backup file"
4
+ task dump: :environment do
5
+ Dumpcar.dump
6
+ end
7
+
8
+ desc "Load dumped postgres backup file"
9
+ task restore: :environment do
10
+ Dumpcar.restore
11
+ end
12
+
13
+ def say(something)
14
+ puts(something)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dumpcar
4
+ VERSION = "0.1.0"
5
+ end
data/lib/dumpcar.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "dumpcar/version"
2
+ require "dumpcar/location"
3
+ require "dumpcar/pg"
4
+ require "dumpcar/instance"
5
+ require "dumpcar/railtie" if defined?(Rails)
6
+
7
+ module Dumpcar
8
+ def self.dump
9
+ Instance.new.dump
10
+ end
11
+
12
+ def self.restore
13
+ Instance.new.restore
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dumpcar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Schultz
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '6'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '6'
26
+ email:
27
+ - eric@wwahammy.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - ".devcontainer/Dockerfile"
33
+ - ".devcontainer/create-db-user.sql"
34
+ - ".devcontainer/devcontainer.json"
35
+ - ".devcontainer/docker-compose.yml"
36
+ - ".rspec"
37
+ - ".ruby-version"
38
+ - ".standard.yml"
39
+ - CHANGELOG.md
40
+ - CODE_OF_CONDUCT.md
41
+ - GPL-3.0.txt
42
+ - LGPL-3.0.txt
43
+ - LICENSE
44
+ - NOTICES
45
+ - README.md
46
+ - Rakefile
47
+ - config.ru
48
+ - lib/dumpcar.rb
49
+ - lib/dumpcar/generators/dumpcar_generator.rb
50
+ - lib/dumpcar/instance.rb
51
+ - lib/dumpcar/location.rb
52
+ - lib/dumpcar/pg.rb
53
+ - lib/dumpcar/railtie.rb
54
+ - lib/dumpcar/tasks/dump.rake
55
+ - lib/dumpcar/version.rb
56
+ homepage: https://github.com/wwahammy/dumpcar
57
+ licenses:
58
+ - LGPL-3.0-or-later
59
+ metadata:
60
+ homepage_uri: https://github.com/wwahammy/dumpcar
61
+ source_code_uri: https://github.com/wwahammy/dumpcar
62
+ changelog_uri: https://github.com/wwahammy/dumpcar
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 3.2.0
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.6.7
78
+ specification_version: 4
79
+ summary: We're getting there
80
+ test_files: []