osmosis 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/osmosis/command.rb +62 -27
- data/lib/osmosis/tasks/db/connect.rake +7 -0
- data/lib/osmosis/tasks/db/import.rake +13 -0
- data/lib/osmosis/version.rb +1 -1
- metadata +5 -18
- data/lib/osmosis/tasks/db/restore.rake +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '033500944d7bcb9c17fb602c3381e842b060f17233096a6286884cc2bdb72c54'
|
4
|
+
data.tar.gz: f05ea8a885a2560d4ec01fec4d21082fc29f665d714b30cfeeab9c7b634b299f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 271e0df3804c9cc4ec4d66cd77c32f4538c09da2e9e9390bae58422715eb9c61b5ad201e51f148ddf4586fca8403a3e429a264aac6c980c0c3cb95e41bdf65cd
|
7
|
+
data.tar.gz: f47ce3ddd08b8a025bf7da08267edb6e2a23edfe7ec37cd392feb3908a2fdf22e9e771d86cbc62ab2209fe2c591bd8fddeefccbbdbdf38321571f56d78099758
|
data/README.md
CHANGED
@@ -16,9 +16,21 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
16
16
|
|
17
17
|
Osmosis provides you with different rake tasks that simplify the management of your database.
|
18
18
|
|
19
|
-
### Database
|
19
|
+
### Database import
|
20
20
|
|
21
|
+
The import command takes the `.dump` file provided and restores it to the PostgreSQL database. Any pre-existing data is dropped.
|
21
22
|
|
23
|
+
```bash
|
24
|
+
bundle exec rails db:import <filename>
|
25
|
+
```
|
26
|
+
|
27
|
+
### Database export
|
28
|
+
|
29
|
+
The export command exports the PostgreSQL database into a `.dump` file. If the file already exists, it is overwritten.
|
30
|
+
|
31
|
+
```bash
|
32
|
+
bundle exec rails db:export <filename>
|
33
|
+
```
|
22
34
|
|
23
35
|
## Development
|
24
36
|
|
@@ -28,7 +40,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
28
40
|
|
29
41
|
## Contributing
|
30
42
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/code-fabrik/osmosis.
|
32
44
|
|
33
45
|
## License
|
34
46
|
|
data/lib/osmosis/command.rb
CHANGED
@@ -1,35 +1,51 @@
|
|
1
|
+
require 'expect'
|
1
2
|
require 'ostruct'
|
3
|
+
require 'pty'
|
2
4
|
|
3
5
|
module Osmosis
|
4
6
|
class Command
|
5
|
-
def self.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
return [
|
10
|
-
OpenStruct.new(type: :print, command: "No backups found for *.dump")
|
11
|
-
]
|
12
|
-
when 1
|
13
|
-
file = files.first
|
14
|
-
host = ActiveRecord::Base.connection_db_config.host
|
15
|
-
database = ActiveRecord::Base.connection_db_config.database
|
16
|
-
username = ActiveRecord::Base.connection_db_config.configuration_hash[:username]
|
17
|
-
password = ActiveRecord::Base.connection_db_config.configuration_hash[:password]
|
18
|
-
cmd = "PGPASSWORD=#{password} pg_restore -U #{username} -h #{host} -d #{database} -cO --if-exists -w < #{file}"
|
19
|
-
Rake::Task["db:drop"].invoke
|
20
|
-
Rake::Task["db:create"].invoke
|
21
|
-
return [
|
22
|
-
OpenStruct.new(type: :rake, command: 'db:drop'),
|
23
|
-
OpenStruct.new(type: :rake, command: 'db:create'),
|
24
|
-
OpenStruct.new(type: :cmd, command: cmd),
|
25
|
-
OpenStruct.new(type: :print, command: "Restored database '#{database}'"),
|
26
|
-
]
|
27
|
-
else
|
28
|
-
return [
|
29
|
-
OpenStruct.new(type: :print, command: "Too many backups found for *.dump:"),
|
30
|
-
OpenStruct.new(type: :print, command: ' ' + files.join("\n ")),
|
31
|
-
]
|
7
|
+
def self.import(argv)
|
8
|
+
file = argv[0]
|
9
|
+
if file.nil?
|
10
|
+
return [OpenStruct.new(type: :print, command: "Please provide a filename parameter: rails db:import <filename>")]
|
32
11
|
end
|
12
|
+
if !File.exist?(file)
|
13
|
+
return [OpenStruct.new(type: :print, command: "File #{file} does not exist")]
|
14
|
+
end
|
15
|
+
host = ActiveRecord::Base.connection_db_config.host
|
16
|
+
database = ActiveRecord::Base.connection_db_config.database
|
17
|
+
username = ActiveRecord::Base.connection_db_config.configuration_hash[:username]
|
18
|
+
password = ActiveRecord::Base.connection_db_config.configuration_hash[:password]
|
19
|
+
cmd = "PGPASSWORD=#{password} pg_restore -U #{username} -h #{host} -d #{database} -cO --if-exists -w < #{file}"
|
20
|
+
return [
|
21
|
+
OpenStruct.new(type: :rake, command: 'db:drop'),
|
22
|
+
OpenStruct.new(type: :rake, command: 'db:create'),
|
23
|
+
OpenStruct.new(type: :cmd, command: cmd),
|
24
|
+
OpenStruct.new(type: :print, command: "Imported database '#{database}'"),
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.export(argv)
|
29
|
+
file = argv[0]
|
30
|
+
if file.nil?
|
31
|
+
return [OpenStruct.new(type: :print, command: "Please provide a filename parameter: rails db:export <filename>")]
|
32
|
+
end
|
33
|
+
host = ActiveRecord::Base.connection_db_config.host
|
34
|
+
database = ActiveRecord::Base.connection_db_config.database
|
35
|
+
username = ActiveRecord::Base.connection_db_config.configuration_hash[:username]
|
36
|
+
password = ActiveRecord::Base.connection_db_config.configuration_hash[:password]
|
37
|
+
cmd = "PGPASSWORD=#{password} pg_dump -Fc --no-acl --no-owner -h #{host} -U #{username} -w #{database} > #{file}"
|
38
|
+
return [
|
39
|
+
OpenStruct.new(type: :cmd, command: cmd),
|
40
|
+
OpenStruct.new(type: :print, command: "Exported database '#{database}'"),
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.connect(argv)
|
45
|
+
cmd = "PGPASSWORD=#{password} psql -U #{username} -h #{host} -d #{database}"
|
46
|
+
return [
|
47
|
+
OpenStruct.new(type: :pty, command: cmd)
|
48
|
+
]
|
33
49
|
end
|
34
50
|
|
35
51
|
def self.run(commands)
|
@@ -40,6 +56,25 @@ module Osmosis
|
|
40
56
|
system cmd.command
|
41
57
|
elsif cmd.type == :print
|
42
58
|
puts cmd.command
|
59
|
+
elsif cmd.type == :pty
|
60
|
+
PTY.spawn(cmd.command) do |stdout, stdin, pid|
|
61
|
+
trap("INT") { Process.kill("INT", pid) }
|
62
|
+
|
63
|
+
begin
|
64
|
+
loop do
|
65
|
+
# Read output from psql
|
66
|
+
stdout.each { |line| puts line}
|
67
|
+
|
68
|
+
# Check if there's any input from the user
|
69
|
+
if IO.select([STDIN], nil, nil, 0.1)
|
70
|
+
user_input = STDIN.gets.chomp
|
71
|
+
stdin.puts user_input
|
72
|
+
end
|
73
|
+
end
|
74
|
+
rescue Errno::EIO
|
75
|
+
puts "psql session ended"
|
76
|
+
end
|
77
|
+
end
|
43
78
|
else
|
44
79
|
raise StandardError, "Unknown command type #{cmd.type}"
|
45
80
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
namespace :db do
|
2
|
+
desc "Imports a database from a backup"
|
3
|
+
task import: :environment do
|
4
|
+
commands = Osmosis::Command.import(ARGV)
|
5
|
+
Osmosis::Command.run(commands)
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Exports a database to a backup"
|
9
|
+
task import: :environment do
|
10
|
+
commands = Osmosis::Command.export(ARGV)
|
11
|
+
Osmosis::Command.run(commands)
|
12
|
+
end
|
13
|
+
end
|
data/lib/osmosis/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osmosis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas_Skywalker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: thor
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.3'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.3'
|
11
|
+
date: 2024-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: This powerful database utility library simplifies and automates common
|
28
14
|
database tasks, including exports, imports, and data migrations. With its intuitive
|
29
15
|
interface and robust feature set, it enables developers to manage databases more
|
@@ -42,7 +28,8 @@ files:
|
|
42
28
|
- lib/osmosis.rb
|
43
29
|
- lib/osmosis/command.rb
|
44
30
|
- lib/osmosis/railtie.rb
|
45
|
-
- lib/osmosis/tasks/db/
|
31
|
+
- lib/osmosis/tasks/db/connect.rake
|
32
|
+
- lib/osmosis/tasks/db/import.rake
|
46
33
|
- lib/osmosis/version.rb
|
47
34
|
- sig/osmosis.rbs
|
48
35
|
homepage: https://github.com/code-fabrik/osmosis
|