rails-baklite 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 91c8389711b76325c4d9d9833cdefdf3ceca480ad44740c3a5e2e2d20d11821d
4
+ data.tar.gz: feca065d6d6b8ccf147203260590640deebb4db33c2313be3953ad22f3a3e192
5
+ SHA512:
6
+ metadata.gz: 1c4817497837a13f6667163db01564dbc282ddd446f07d91535b970d1834d0f6fbd0a2c52fcb674a77e2249f123fec44e66934ee7aa5ffdfaef5e3b41e1f2d75
7
+ data.tar.gz: 9c02e9e536289b60a55ed973ca4f883df11166549a382359f2835fbfdfcc6cd86c0f794fb77a7c96a9e9313a6db5de0e3c0836821145134e7186c874d7dd721d
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Victor García Fernández
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Rails::Baklite
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "rails-baklite"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install rails-baklite
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ module Rails
2
+ module Baklite
3
+ class Railtie < ::Rails::Railtie
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module Baklite
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require 'rails/baklite/version'
2
+ require 'rails/baklite/railtie'
3
+ require 'sqlite3'
4
+
5
+ module Rails
6
+ module Baklite
7
+ def self.backup
8
+ db_config = ActiveRecord::Base.connection_db_config
9
+ database = db_config.configuration_hash
10
+ raise Error, 'Only SQLite3 databases are supported' if database[:adapter] != 'sqlite3'
11
+
12
+ backupfile = "#{Rails.root}/tmp/database.bak"
13
+
14
+ _backup(ActiveRecord::Base.connection.raw_connection, backupfile)
15
+
16
+ backupfile
17
+ end
18
+
19
+ def self._backup(sdb, backupfile, name = 'main')
20
+ ddb = SQLite3::Database.new(backupfile)
21
+
22
+ b = SQLite3::Backup.new(ddb, name, sdb, name)
23
+ p [b.remaining, b.pagecount]
24
+ begin
25
+ p b.step(1)
26
+ p [b.remaining, b.pagecount]
27
+ end while b.remaining > 0
28
+ b.finish
29
+
30
+ ddb = SQLite3::Database.new(backupfile)
31
+ b = SQLite3::Backup.new(ddb, name, sdb, name)
32
+ b.step(-1)
33
+ b.finish
34
+ end
35
+
36
+ def self.restore(backupfile, sdb, name = 'main')
37
+ ddb = SQLite3::Database.new(backupfile, readonly: true)
38
+
39
+ b = SQLite3::Backup.new(sdb, name, ddb, name)
40
+ begin
41
+ b.step(1)
42
+ end while b.remaining > 0
43
+ b.finish
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_baklite do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-baklite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor García Fernández
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.1.3.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.1.3.4
27
+ description: Backup and restore SQLite3 databases in your Rails app.
28
+ email:
29
+ - victorgf2011@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/rails/baklite.rb
38
+ - lib/rails/baklite/railtie.rb
39
+ - lib/rails/baklite/version.rb
40
+ - lib/tasks/rails/baklite_tasks.rake
41
+ homepage: https://github.com/tortitast/rails-baklite
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ allowed_push_host: https://rubygems.org
46
+ homepage_uri: https://github.com/tortitast/rails-baklite
47
+ source_code_uri: https://github.com/tortitast/rails-baklite.git
48
+ changelog_uri: https://github.com/tortitast/rails-baklite.git
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.5.9
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Backup and restore SQLite3 databases in your Rails app.
68
+ test_files: []