nomadize 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: ee738d9952a99b01a995138cb42d3f02a33a552e
4
- data.tar.gz: a2d88cf37009b8826e651f4e7823e94305c45661
3
+ metadata.gz: 281d8eece08ec4e4ff09e73656dd2c7c57f5c723
4
+ data.tar.gz: e585f19613a01e82e198b57678c721d54d2fa09b
5
5
  SHA512:
6
- metadata.gz: 10b5374b4a415af7adb87ad3268ef6fa103a86c17b989311e957085df2b843d722ee92314b3b89cbf515118f9c2d4eb879fe0085acf234812eb1fe5c0f639298
7
- data.tar.gz: 1c9f547803f18082f8ee1d8a94f153b4c9f07886551524bc50d3c467951a9a4250cd010beb256853f783e3d119a7ce98477bc9984864da67119a1c03b74c0e54
6
+ metadata.gz: 0103c0e40303bb05c0b35cfc7b61e736c46fcf7b3e88ba260f77cb28c678a701483ea099bbb0bae1f7f41d9773d83ef63158e9c2d44b8cc5161a3c61b161cb6a
7
+ data.tar.gz: 5b2fa8e1548e3697c0e1d332c00afa4084038f640a573630b6bca1566d46ea4ab37ab801aff444e5f91c7741165f43c8c4bd271630e6d7e31ad206a2ad4b08d5
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Nomadize
2
2
 
3
- Some simple tools for managing migrations with postgres (without requiring an entire ORM).
3
+ Nomadize is a collection of rake tasks for managing migrations using a PostgreSQL database. It does not import an entire ORM and aims to be a small / simple utility.
4
+
4
5
 
5
6
  ## Installation
6
7
 
@@ -21,10 +22,9 @@ Or install it yourself as:
21
22
 
22
23
  ## Usage
23
24
 
24
- Nomadize expects a database configuration file in `config/database.yml`. This file should look something like:
25
+ Nomadize expects a database configuration file in `config/database.yml`. You can generate this file with the rake task `db:generate_template_config` or write it yourself. This file should look something like:
25
26
 
26
27
  ```
27
- migrations_path: db/migrations
28
28
  development:
29
29
  :dbname: lol_dev
30
30
  test:
@@ -33,9 +33,9 @@ production:
33
33
  :dbname: lol_production
34
34
  ```
35
35
 
36
- `migrations_path` defines where Nomadize should find and create your migration files.
36
+ test/development/production keys set environment dependent options (through `RACK_ENV`) for the postgres connection object. These key/value pairs are handed directly to the `PG.connect` method, documentation for what options can be passed can be found [here](http://deveiate.org/code/pg/PG/Connection.html#method-c-new).
37
37
 
38
- The test/development/production keys set environment dependent options (through `RACK_ENV`) for the postgres connection object. These key/value pairs are handed directly to the `PG.connect` method, documentation for what options can be passed can be found [here](http://deveiate.org/code/pg/PG/Connection.html#method-c-new).
38
+ `migrations_path: db/migrations` defines where Nomadize should find and create your migration files, this setting is optional and is set to `db/migrations` by default.
39
39
 
40
40
  After a config file is in place add `require 'nomadize/tasks'` to your rake file, and enjoy helpful new rake tasks such as:
41
41
 
@@ -45,7 +45,17 @@ After a config file is in place add `require 'nomadize/tasks'` to your rake fil
45
45
  * `rake db:migrate` - runs migrations found in db/migrations that have not been run yet
46
46
  * `rake db:status` - see which migrations have or have not been run
47
47
  * `rake db:rollback[count]` - rollback migrations (default count: 1)
48
+ * `rake db:generate_template_config` - generate a config file in `config/database.yml`
49
+
50
+ Migrations are written in SQL in the generated YAML files:
51
+
52
+ ```
53
+ ---
54
+ :up: 'CREATE TABLE testing (field TEXT);'
55
+ :down: 'DROP TABLE testing;'
56
+ ```
48
57
 
58
+ You also have access to the underlying PG connection wrapper (using your defined config) by using the `Nomadize::Config.db` method. This wrapper responds to `exec` in the same way that the underlying PG connection object does.
49
59
 
50
60
  ## Development
51
61
 
@@ -58,6 +68,8 @@ todo:
58
68
  - [ ] transactions / error handling
59
69
  - [ ] maybe some kind of logging idk
60
70
  - [x] possibly wrap pg
71
+ - [x] template config file generator
72
+ - [x] maybe set a default migrations path (so the key isn't required in the config file)
61
73
 
62
74
 
63
75
  ## Contributing
data/lib/nomadize.rb CHANGED
@@ -57,4 +57,15 @@ module Nomadize
57
57
  Nomadize::FileGenerator.new(path: Config.migrations_path, name: name).save
58
58
  end
59
59
 
60
+ def self.generate_template_config
61
+ fail 'Config file already exists' if File.exists?('config/database.yml')
62
+ template_config = YAML.dump(
63
+ { 'development' => { dbname: '' },
64
+ 'test' => { dbname: '' },
65
+ 'production' => { dbname: '' }
66
+ } )
67
+ FileUtils.mkdir 'config' unless File.exists?('config')
68
+ File.open('config/database.yml', 'w') { |f| f.write(template_config) }
69
+ end
70
+
60
71
  end
@@ -18,7 +18,7 @@ module Nomadize
18
18
  end
19
19
 
20
20
  def self.migrations_path
21
- config_file.fetch("migrations_path")
21
+ config_file.fetch('migrations_path', 'db/migrations')
22
22
  end
23
23
 
24
24
  def self.config_file(path = 'config/database.yml')
@@ -12,7 +12,7 @@ namespace :db do
12
12
  Nomadize.drop_database
13
13
  end
14
14
 
15
- desc 'Generate a migration template file in {appdir}/db/migrations/'
15
+ desc "Generate a migration template file. default directory: {appdir}/db/migrations"
16
16
  task :new_migration, [:migration_name] do |_, args|
17
17
  Nomadize.generate_template_migration_file(args.migration_name)
18
18
  end
@@ -33,4 +33,10 @@ namespace :db do
33
33
  Nomadize.rollback(count)
34
34
  end
35
35
 
36
+ desc 'generate template config file'
37
+ task :generate_template_config do
38
+ Nomadize.generate_template_config
39
+ puts 'Config created in config/database.yml'
40
+ end
41
+
36
42
  end
@@ -1,3 +1,3 @@
1
1
  module Nomadize
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/nomadize.gemspec CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["paul@into.computer"]
11
11
 
12
12
  spec.summary = %q{A simple database migration utility}
13
+ spec.description = %q{Nomadize is a collection of rake tasks for managing migrations using a PostgreSQL database. It does not import an entire ORM and aims to be a small / simple utility.}
13
14
  spec.homepage = "https://github.com/piisalie/nomadize"
14
15
  spec.license = "MIT"
15
16
 
@@ -17,6 +18,7 @@ Gem::Specification.new do |spec|
17
18
  spec.bindir = "exe"
18
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
20
  spec.require_paths = ["lib"]
21
+ spec.required_ruby_version = '~> 2.0'
20
22
 
21
23
  spec.add_development_dependency "bundler", "~> 1.10"
22
24
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nomadize
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
  - Paul Dawson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-10 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,7 +66,9 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.18.1
69
- description:
69
+ description: Nomadize is a collection of rake tasks for managing migrations using
70
+ a PostgreSQL database. It does not import an entire ORM and aims to be a small /
71
+ simple utility.
70
72
  email:
71
73
  - paul@into.computer
72
74
  executables: []
@@ -101,9 +103,9 @@ require_paths:
101
103
  - lib
102
104
  required_ruby_version: !ruby/object:Gem::Requirement
103
105
  requirements:
104
- - - ">="
106
+ - - "~>"
105
107
  - !ruby/object:Gem::Version
106
- version: '0'
108
+ version: '2.0'
107
109
  required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  requirements:
109
111
  - - ">="