database-cloner-rails 1.0.1 → 1.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5b9746f0df92bf39ad438cdcd9b6b214a65dc5041bb259aa29358f2144176b69
|
|
4
|
+
data.tar.gz: 02a3b5b3e7e3d16a8be41c727690a15b591215cbd091972afebd8d664450f024
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec3b1c953a9b0b9be224ec786eddecfadbe2b40330b5327f3bc3e374f50983169c2423469b1110525718ebe30c6deadbddbcf86229109adf7dda34f5ed280e04
|
|
7
|
+
data.tar.gz: bda35012cba75780535f111cd962ce654c8025ce57fa651b3ca98e48b3a22932da6c29f2456161668efc151cc870aac4914f545be0dad19db7353fea958bdf76
|
|
@@ -1,19 +1,26 @@
|
|
|
1
|
+
require "fileutils"
|
|
2
|
+
require "json"
|
|
3
|
+
|
|
1
4
|
module DatabaseClonerRails
|
|
2
5
|
class Downloader
|
|
3
|
-
def self.run(dump_dir: default_dump_dir)
|
|
4
|
-
new(dump_dir: dump_dir).run
|
|
6
|
+
def self.run(dump_dir: default_dump_dir, only: nil)
|
|
7
|
+
new(dump_dir: dump_dir, only: only).run
|
|
5
8
|
end
|
|
6
9
|
|
|
7
10
|
def self.default_dump_dir
|
|
8
11
|
File.join(Rails.root, "lib", "tasks", "database_cloner", "db_dump")
|
|
9
12
|
end
|
|
10
13
|
|
|
11
|
-
def initialize(dump_dir: self.class.default_dump_dir)
|
|
14
|
+
def initialize(dump_dir: self.class.default_dump_dir, only: nil)
|
|
12
15
|
@dump_dir = dump_dir
|
|
16
|
+
@only = Array(only).map(&:to_s).reject(&:empty?)
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
def run
|
|
16
|
-
|
|
20
|
+
FileUtils.mkdir_p(@dump_dir)
|
|
21
|
+
tables = ActiveRecord::Base.connection.tables
|
|
22
|
+
tables = tables.select { |t| @only.include?(t) } if @only.any?
|
|
23
|
+
tables.each do |table|
|
|
17
24
|
model = table.classify.safe_constantize
|
|
18
25
|
next unless model.present?
|
|
19
26
|
dump_table(table, model)
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
module DatabaseClonerRails
|
|
2
2
|
class Uploader
|
|
3
|
-
def self.run
|
|
4
|
-
new.run
|
|
3
|
+
def self.run(only: nil)
|
|
4
|
+
new(only: only).run
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize(only: nil)
|
|
8
|
+
@only = Array(only).map(&:to_s).reject(&:empty?)
|
|
5
9
|
end
|
|
6
10
|
|
|
7
11
|
def run
|
|
8
|
-
ActiveRecord::Base.connection.tables
|
|
12
|
+
tables = ActiveRecord::Base.connection.tables
|
|
13
|
+
tables = tables.select { |t| @only.include?(t) } if @only.any?
|
|
14
|
+
tables.each do |table|
|
|
9
15
|
next unless table.classify.safe_constantize.present?
|
|
10
16
|
begin
|
|
11
17
|
require "tasks/database_cloner/db_dump/#{table}"
|
data/lib/tasks/database.rake
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
namespace :database do
|
|
2
|
-
desc "Dump all model records to Ruby files in lib/tasks/database_cloner/db_dump
|
|
2
|
+
desc "Dump all model records to Ruby files in lib/tasks/database_cloner/db_dump/. Use MODELS=users,posts to filter."
|
|
3
3
|
task download: :environment do
|
|
4
|
-
|
|
4
|
+
only = ENV["MODELS"]&.split(",")&.map(&:strip)
|
|
5
|
+
DatabaseClonerRails::Downloader.run(only: only)
|
|
5
6
|
end
|
|
6
7
|
|
|
7
|
-
desc "Restore model records from dumped Ruby files"
|
|
8
|
+
desc "Restore model records from dumped Ruby files. Use MODELS=users,posts to filter."
|
|
8
9
|
task upload: :environment do
|
|
9
|
-
|
|
10
|
+
only = ENV["MODELS"]&.split(",")&.map(&:strip)
|
|
11
|
+
DatabaseClonerRails::Uploader.run(only: only)
|
|
10
12
|
end
|
|
11
13
|
end
|