postgressor 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac951676c1041a11f52a59de5c58154648a6d77a0a4d5828b8ac4a8045c352d9
4
- data.tar.gz: b87bcf598f561ab1385de799a705417bc7d153f560f47fee655f7067de6775d6
3
+ metadata.gz: e3e6aec99892829719db0dcc79bd3f83937688d8cd6e3ed6a6846deea3171179
4
+ data.tar.gz: 9b036d82fdd5bc61d699ea5ee8ba89f6af5561ecd4d892d34deb919be0800beb
5
5
  SHA512:
6
- metadata.gz: e971443893ae079d788c7b598dc635c0e887218ace8eac059932bfe30969168c98e1ca363c677524ba89af9b0418276d78efe32725faeca4f642f8a26731847c
7
- data.tar.gz: b4778abdf4caa5e930982bb324ebed27a29350d47cd09d28b14b5d2916025e146699e4c98a002be05f1e0166908356a5699db44db22f03803355f7fd6e4eb260
6
+ metadata.gz: bd90c0e80fbc2d37418232f8c2dbc25ba26171512f79f9c9efb80352fcfaf87cea6cfffd5c878e15e885e71690b02382835fdb97931c7d75c393a75964540e15
7
+ data.tar.gz: 7afa9d9b0d2d2fc50fe0d275029f6d56397c876f8939b3127b60e6f8e604e1fbcd21338ac82e7eec4ed0bebf8c4fe429a73d5732e1c39333e92fef7a130f6025
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Postgressor
2
2
 
3
+ > **NEW:** added support for `config/database.yml` in version 0.2.0
4
+
3
5
  Get tired of typing the same commands over and over like creating Postgres user, database, creating and restoring database backups? Postgressor allow you to manage your (Postgres) application database and user within simple commands:
4
6
 
5
7
  ```
@@ -16,7 +18,11 @@ Commands:
16
18
  postgressor help [COMMAND] # Describe available commands or one specific command
17
19
  ```
18
20
 
19
- All what you need is DATABASE_URL in format like: `DATABASE_URL="postgres://app_user:app_user_pass@host/app_db_name"`. Also Postgressor automatically check `.env` file (if present) **to read DATABASE_URL from there.**
21
+ Postgressor can fetch required credentials from two sources:
22
+
23
+ 1. DATABASE_URL environment variable (default). Format: `DATABASE_URL="postgres://app_user:app_user_pass@host/app_db_name"`. Also postgressor automatically checks `.env` file (if present) **to read DATABASE_URL from there**.
24
+ 2. If DATABASE_URL env variable not present, postgressor will try to fetch credentials from `config/database.yml` (Rails style) file (if present). By default posgressor read `production` settings. If you want to use different environment, simply provide RAILS_ENV env before postgressor command. Example: `RAILS_ENV=development postressor createuser`.
25
+
20
26
 
21
27
  ## Installation
22
28
 
data/exe/postgressor CHANGED
File without changes
@@ -1,6 +1,7 @@
1
1
  require 'uri'
2
2
  require 'thor'
3
3
  require 'dotenv/load'
4
+ require 'yaml'
4
5
 
5
6
  module Postgressor
6
7
  class CLI < Thor
@@ -130,8 +131,27 @@ module Postgressor
130
131
 
131
132
  def preload!
132
133
  url = ENV["DATABASE_URL"]
133
- raise "Env variable DATABASE_URL is not provided" if url.nil? || url.strip.empty?
134
134
 
135
+ if url.nil? || url.strip.empty?
136
+ # If DATABASE_URL env not present, try to read from config/database.yml (Rails)
137
+ if File.exist?("config/database.yml")
138
+ settings = YAML.load_file("config/database.yml")
139
+ # By default, use production config, if RAILS_ENV not provided
140
+ config = ENV["RAILS_ENV"] ? settings[ENV["RAILS_ENV"]] : settings["production"]
141
+
142
+ preload_from_database_yml(config)
143
+ else
144
+ raise "Env variable DATABASE_URL or config/database.yml file not provided"
145
+ end
146
+ else
147
+ preload_from_database_url(url)
148
+ end
149
+
150
+ @pg_cli_args = ["-h", @conf[:host], "-U", @conf[:user]]
151
+ @pg_cli_args += ["-p", @conf[:port].to_s] if @conf[:port]
152
+ end
153
+
154
+ def preload_from_database_url(url)
135
155
  uri = URI.parse(url)
136
156
  raise "DB adapter is not postgres" if uri.scheme != "postgres"
137
157
 
@@ -143,9 +163,19 @@ module Postgressor
143
163
  user: uri.user,
144
164
  password: uri.password
145
165
  }
166
+ end
146
167
 
147
- @pg_cli_args = ["-h", @conf[:host], "-U", @conf[:user]]
148
- @pg_cli_args += ["-p", @conf[:port].to_s] if @conf[:port]
168
+ def preload_from_database_yml(config)
169
+ raise "DB adapter is not postgres" if config["adapter"] != "postgresql"
170
+
171
+ @conf = {
172
+ url: nil,
173
+ db: config["database"],
174
+ host: config["host"],
175
+ port: config["port"],
176
+ user: config["username"],
177
+ password: config["password"]
178
+ }
149
179
  end
150
180
  end
151
181
  end
@@ -1,3 +1,3 @@
1
1
  module Postgressor
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Afanasev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-01 00:00:00.000000000 Z
11
+ date: 2019-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor