amico-db 0.1.7
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 +7 -0
- data/.github/workflows/gem-push.yml +41 -0
- data/.github/workflows/ruby.yml +33 -0
- data/.gitignore +1 -0
- data/Dockerfile +12 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +10 -0
- data/amico-db.gemspec +44 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +11 -0
- data/lib/amico-db.rb +17 -0
- data/lib/amico-db/configuration.rb +31 -0
- data/lib/amico-db/download.rb +40 -0
- data/lib/amico-db/download_tools/create_dir_if_not_exist.rb +15 -0
- data/lib/amico-db/dump.rb +60 -0
- data/lib/amico-db/dump_cmd.rb +24 -0
- data/lib/amico-db/railtie.rb +7 -0
- data/lib/amico-db/version.rb +3 -0
- data/lib/tasks/db.rake +55 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 640595f08087f9029ca05b73fd78aefee25c2b153644fb429ba071af7287b2f2
|
4
|
+
data.tar.gz: 6c0c84fe3b5a2023af70f47fd27dbf5ad9ba2f686907662435405da01fa65c28
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a5b73b3cf154d5159f0be12c02a84eeba464e0d9c81cd17028097c9602800afa28b57cb24dabcc8fb390213907d44e2d84d3f92994ce11e0165fff9f5d82eb47
|
7
|
+
data.tar.gz: 0bb6259efd9cf7c3871fb31f73cfdc3ff9398e5e44663035f37109270fc31bbddffd8d60782063a4c1bcf17f2a68999d9918baa042b38dfad4ce84b4c982ceb9
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- name: Set up Ruby 2.6
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 2.6.x
|
20
|
+
|
21
|
+
- name: Publish to RubyGems
|
22
|
+
run: |
|
23
|
+
mkdir -p $HOME/.gem
|
24
|
+
touch $HOME/.gem/credentials
|
25
|
+
chmod 0600 $HOME/.gem/credentials
|
26
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
27
|
+
gem build *.gemspec
|
28
|
+
gem push *.gem
|
29
|
+
env:
|
30
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
31
|
+
- name: Publish to GPR
|
32
|
+
run: |
|
33
|
+
mkdir -p $HOME/.gem
|
34
|
+
touch $HOME/.gem/credentials
|
35
|
+
chmod 0600 $HOME/.gem/credentials
|
36
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
37
|
+
gem build *.gemspec
|
38
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
39
|
+
env:
|
40
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
41
|
+
OWNER: ${{ github.repository_owner }}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- name: Set up Ruby
|
24
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
25
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
26
|
+
# uses: ruby/setup-ruby@v1
|
27
|
+
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
28
|
+
with:
|
29
|
+
ruby-version: 2.6
|
30
|
+
- name: Install dependencies
|
31
|
+
run: bundle install
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.vscode/
|
data/Dockerfile
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
amico-db (0.1.5)
|
5
|
+
colorize
|
6
|
+
net-ssh (>= 6.1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
colorize (0.8.1)
|
12
|
+
minitest (5.14.1)
|
13
|
+
net-ssh (6.1.0)
|
14
|
+
rake (13.0.1)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
amico-db!
|
21
|
+
bundler (~> 1.17)
|
22
|
+
minitest (~> 5.0)
|
23
|
+
rake (>= 12.3.3)
|
24
|
+
|
25
|
+
BUNDLED WITH
|
26
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+

|
2
|
+
|
3
|
+
# Amico Db
|
4
|
+
|
5
|
+
Import **mysql db from docker container**.
|
6
|
+
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
### Docker container
|
10
|
+
To use this tool you need a docker container on the server with your db.
|
11
|
+
|
12
|
+
### Pipeline
|
13
|
+
For visualize progress on the cli you need to install pv: https://man7.org/linux/man-pages/man1/pv.1.html.
|
14
|
+
|
15
|
+
```bash
|
16
|
+
# Install PV in your Dockerfile
|
17
|
+
RUN apt-get update && apt-get install -y pv
|
18
|
+
RUN apt-get update && apt-get install -y mariadb-client
|
19
|
+
|
20
|
+
```
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'amico-db', git: 'https://github.com/rubynetti/amico-db.git'
|
28
|
+
```
|
29
|
+
|
30
|
+
## Configuration
|
31
|
+
|
32
|
+
For example inside a rails initializer (config/initializers/amico-db.rb).
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
dev = Rails.configuration.database_configuration["production"]
|
36
|
+
production = Rails.configuration.database_configuration["production"]
|
37
|
+
|
38
|
+
AmicoDb.configure do |config|
|
39
|
+
config.ssh_user = 'root'
|
40
|
+
config.host = 'your_host'
|
41
|
+
config.remote_app_path = '/var/www/yourproject'
|
42
|
+
config.folder_dump = '/dumps/db.sql'
|
43
|
+
config.local_path = './dumps/db.sql'
|
44
|
+
|
45
|
+
config.db_name = production['database']
|
46
|
+
config.db_user = production['username']
|
47
|
+
config.db_dev_dbname = dev['database']
|
48
|
+
config.db_dev_username = dev['username']
|
49
|
+
end
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
## Docker Dev Configuration (docker-compose.development.yml)
|
54
|
+
|
55
|
+
Your dev configuration need to copy ssh folder inside.
|
56
|
+
Example:
|
57
|
+
|
58
|
+
```yaml
|
59
|
+
services:
|
60
|
+
web:
|
61
|
+
build: .
|
62
|
+
command: ['rails', 'server', '-b', '0']
|
63
|
+
volumes:
|
64
|
+
- .:/app
|
65
|
+
- ~/.ssh:/home/rails/.ssh
|
66
|
+
```
|
67
|
+
|
68
|
+
## Docker Production Configuration (docker-compose.production.yml)
|
69
|
+
|
70
|
+
Database service need MYSQL_ROOT_PASSWORD and share dumps folder.
|
71
|
+
|
72
|
+
```yaml
|
73
|
+
services:
|
74
|
+
db:
|
75
|
+
environment:
|
76
|
+
- MYSQL_ROOT_PASSWORD=$DB_PASSWORD
|
77
|
+
volumes:
|
78
|
+
- ./dumps:/dumps
|
79
|
+
```
|
80
|
+
|
81
|
+
## Usage
|
82
|
+
|
83
|
+
```bash
|
84
|
+
rake db:dump
|
85
|
+
rake db:import_from_staging
|
86
|
+
rake db:import_from_sql (importa sql da dumps/db-staging.sql)
|
87
|
+
```
|
88
|
+
|
89
|
+
## For development of this gem with Docker
|
90
|
+
|
91
|
+
- `docker-compose up` run `rake test` command
|
data/Rakefile
ADDED
data/amico-db.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "amico-db/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "amico-db"
|
8
|
+
spec.version = AmicoDb::VERSION
|
9
|
+
spec.authors = ["Rubynetti - www.rubynetti.it"]
|
10
|
+
spec.email = ["info@rubynetti.it"]
|
11
|
+
|
12
|
+
spec.summary = %q{Import mysql db.}
|
13
|
+
#spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
#spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
|
22
|
+
#spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
#spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
24
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_dependency "net-ssh", ">= 6.1.0"
|
40
|
+
spec.add_dependency "colorize"
|
41
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
42
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
43
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
44
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "amico-db"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
data/lib/amico-db.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'amico-db/configuration'
|
2
|
+
require 'amico-db/version'
|
3
|
+
require 'amico-db/download_tools/create_dir_if_not_exist'
|
4
|
+
require 'amico-db/download'
|
5
|
+
require 'amico-db/dump'
|
6
|
+
require 'amico-db/dump_cmd'
|
7
|
+
require 'amico-db/railtie' if defined?(Rails::Railtie)
|
8
|
+
|
9
|
+
module AmicoDb
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= AmicoDb::Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module AmicoDb
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :ssh_user
|
4
|
+
attr_accessor :host
|
5
|
+
attr_accessor :remote_app_path
|
6
|
+
attr_accessor :folder_dump
|
7
|
+
attr_accessor :local_path
|
8
|
+
attr_accessor :db_name
|
9
|
+
attr_accessor :db_user
|
10
|
+
attr_accessor :db_dev_dbname
|
11
|
+
attr_accessor :db_dev_username
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
self.ssh_user = 'user'
|
15
|
+
self.host = 'www.example.com'
|
16
|
+
self.remote_app_path = '/var/www/yourproject'
|
17
|
+
self.folder_dump = '/dumps/db.sql'
|
18
|
+
self.local_path = './dumps/db.sql'
|
19
|
+
self.db_name = 'dbname'
|
20
|
+
self.db_user = 'dbusername'
|
21
|
+
self.db_dev_dbname = 'dbname'
|
22
|
+
self.db_dev_username = 'dbdevname'
|
23
|
+
end
|
24
|
+
|
25
|
+
# ex: /var/www/yourproject/db.sql
|
26
|
+
def remote_path
|
27
|
+
"#{remote_app_path}#{folder_dump}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
module AmicoDb
|
4
|
+
class Download
|
5
|
+
attr_accessor :user
|
6
|
+
attr_accessor :host
|
7
|
+
attr_accessor :remote_path
|
8
|
+
attr_accessor :local_path
|
9
|
+
attr_accessor :cmd
|
10
|
+
|
11
|
+
def initialize(user: AmicoDb.configuration.ssh_user,
|
12
|
+
host: AmicoDb.configuration.host,
|
13
|
+
remote_path: AmicoDb.configuration.remote_path,
|
14
|
+
local_path: AmicoDb.configuration.local_path)
|
15
|
+
self.user = user
|
16
|
+
self.host = host
|
17
|
+
self.remote_path = remote_path
|
18
|
+
self.local_path = local_path
|
19
|
+
self.cmd = generate_cmd
|
20
|
+
end
|
21
|
+
|
22
|
+
def call
|
23
|
+
AmicoDb::DownloadTools::CreateDirIfNotExist.new(local_path).call
|
24
|
+
log_cmd
|
25
|
+
system(cmd)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def log_cmd
|
31
|
+
puts 'Start download with scp:'.colorize(:red)
|
32
|
+
puts cmd.colorize(:red)
|
33
|
+
end
|
34
|
+
|
35
|
+
def generate_cmd
|
36
|
+
"scp #{user}@#{host}:#{remote_path} #{local_path}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'net/ssh'
|
3
|
+
module AmicoDb
|
4
|
+
class Dump
|
5
|
+
attr_accessor :host
|
6
|
+
attr_accessor :ssh_user
|
7
|
+
attr_accessor :remote_path
|
8
|
+
|
9
|
+
def initialize(host: AmicoDb.configuration.host,
|
10
|
+
ssh_user: AmicoDb.configuration.ssh_user)
|
11
|
+
self.host = host
|
12
|
+
self.ssh_user = ssh_user
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
log_before
|
17
|
+
Net::SSH.start(host, ssh_user) do |ssh|
|
18
|
+
log_start
|
19
|
+
ssh.open_channel do |channel|
|
20
|
+
execute_stuff(channel)
|
21
|
+
end
|
22
|
+
ssh.loop
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def execute_stuff(channel)
|
29
|
+
channel.request_pty
|
30
|
+
commands = DumpCmd.new.call
|
31
|
+
channel.exec(commands) do |ch|
|
32
|
+
puts commands.colorize(:cyan)
|
33
|
+
ch.on_data do |_c, data|
|
34
|
+
puts "Il server dice: #{data.inspect}".colorize(:blue)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
channel.on_close { log_end }
|
38
|
+
end
|
39
|
+
|
40
|
+
def log_before
|
41
|
+
puts '------------------------------------'.colorize(:red)
|
42
|
+
puts "#{ssh_user}@#{host}".colorize(:red)
|
43
|
+
puts '------------------------------------'.colorize(:red)
|
44
|
+
end
|
45
|
+
|
46
|
+
def log_start
|
47
|
+
puts '------------------------------------'.colorize(:red)
|
48
|
+
puts '--- RUBYNETTI DUMP POWER -----------'.colorize(:red)
|
49
|
+
puts '------------------------------------'.colorize(:red)
|
50
|
+
puts 'Connected to server'.colorize(:blue)
|
51
|
+
puts '------------------------------------'.colorize(:red)
|
52
|
+
end
|
53
|
+
|
54
|
+
def log_end
|
55
|
+
puts '--------------------------------------'.colorize(:red)
|
56
|
+
puts 'Hi Rubynetti, close connection.'.colorize(:green)
|
57
|
+
puts '--------------------------------------'.colorize(:red)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AmicoDb
|
2
|
+
class DumpCmd
|
3
|
+
attr_accessor :db_user
|
4
|
+
attr_accessor :db_name
|
5
|
+
attr_accessor :folder_dump
|
6
|
+
attr_accessor :remote_app_path
|
7
|
+
|
8
|
+
def initialize(db_user: AmicoDb.configuration.db_user,
|
9
|
+
db_name: AmicoDb.configuration.db_name,
|
10
|
+
folder_dump: AmicoDb.configuration.folder_dump,
|
11
|
+
remote_app_path: AmicoDb.configuration.remote_app_path)
|
12
|
+
self.db_user = db_user
|
13
|
+
self.db_name = db_name
|
14
|
+
self.folder_dump = folder_dump
|
15
|
+
self.remote_app_path = remote_app_path
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
cmd = "'mysqldump -u #{db_user} --ignore-table=#{db_name}.ar_internal_metadata --no-create-db -p$MYSQL_ROOT_PASSWORD #{db_name} > #{folder_dump}'"
|
20
|
+
cmds = ["cd #{remote_app_path}", "docker-compose exec -T db bash -c #{cmd}"]
|
21
|
+
cmds.join('; ')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/tasks/db.rake
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# ------------------------------------
|
2
|
+
# --- RUBYNETTI DUMP POWER -----------
|
3
|
+
# ------------------------------------
|
4
|
+
|
5
|
+
# Queste azioni rake permettono di importare il db da linea di comando.
|
6
|
+
# Esempi di uso:
|
7
|
+
# - rake db:import_from_staging
|
8
|
+
# - rake db:import_from_sql (importa sql da dumps/db-staging.sql)
|
9
|
+
|
10
|
+
namespace :db do
|
11
|
+
|
12
|
+
desc 'Dump db from staging and copy inside locale'
|
13
|
+
# esempio: rake db:import_from_staging
|
14
|
+
task import_from_staging: :environment do
|
15
|
+
Rake::Task['db:dump_and_download'].invoke
|
16
|
+
Rake::Task['db:substitute'].invoke(AmicoDb.configuration.folder_dump)
|
17
|
+
end
|
18
|
+
|
19
|
+
# esempio: rake db:import_from_sql
|
20
|
+
desc 'Dump db di staging'
|
21
|
+
task import_from_sql: :environment do
|
22
|
+
Rake::Task['db:substitute'].invoke(AmicoDb.configuration.folder_dump)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Dump database and import requested dump'
|
26
|
+
task :substitute, [:dump_path] => :environment do |_task, args|
|
27
|
+
Rake::Task['db:drop'].invoke
|
28
|
+
Rake::Task['db:create'].invoke
|
29
|
+
Rake::Task['db:environment:set'].invoke
|
30
|
+
Rake::Task['db:import'].invoke("#{args.dump_path.sub('/','')}")
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Download from staging sql dump of db'
|
34
|
+
task download: :environment do
|
35
|
+
AmicoDb::Download.new.call
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Import requested dump'
|
39
|
+
task :import, [:dump_path] => :environment do |_task, args|
|
40
|
+
db_name = AmicoDb.configuration.db_dev_dbname
|
41
|
+
user = AmicoDb.configuration.db_dev_username
|
42
|
+
system("pv #{args.dump_path} | mysql -h db -u #{user} -p #{db_name}")
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'Dump and download from staging db'
|
46
|
+
task dump_and_download: :environment do
|
47
|
+
Rake::Task['db:dump'].invoke
|
48
|
+
Rake::Task['db:download'].invoke
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'Dump db staging'
|
52
|
+
task dump: :environment do
|
53
|
+
AmicoDb::Dump.new.call
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amico-db
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rubynetti - www.rubynetti.it
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-ssh
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 12.3.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 12.3.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- info@rubynetti.it
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".github/workflows/gem-push.yml"
|
91
|
+
- ".github/workflows/ruby.yml"
|
92
|
+
- ".gitignore"
|
93
|
+
- Dockerfile
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- amico-db.gemspec
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- docker-compose.yml
|
103
|
+
- lib/amico-db.rb
|
104
|
+
- lib/amico-db/configuration.rb
|
105
|
+
- lib/amico-db/download.rb
|
106
|
+
- lib/amico-db/download_tools/create_dir_if_not_exist.rb
|
107
|
+
- lib/amico-db/dump.rb
|
108
|
+
- lib/amico-db/dump_cmd.rb
|
109
|
+
- lib/amico-db/railtie.rb
|
110
|
+
- lib/amico-db/version.rb
|
111
|
+
- lib/tasks/db.rake
|
112
|
+
homepage:
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubygems_version: 3.1.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Import mysql db.
|
135
|
+
test_files: []
|