simplest_migrations 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01a948ac3871d8c7dd59d5a83f14de234dbe92ce
4
+ data.tar.gz: 38758982112d3b9144d8b2c94df2eccae94d56bb
5
+ SHA512:
6
+ metadata.gz: 38f9be24e8befed3f283c23a30a8b2f77b30ec8ddf5ee2c6827648b3ccb11128226eab5d6c963a57992949926e161786e77d6cab7f6ff631e996ac1d188bfc24
7
+ data.tar.gz: 52cad296143ea77c596040144d0535099c21164b75f5061a05c18a7597a4bc308bd93e9ec5352099a22e3bebcbf3ae0979c3f482ac0e65ab9be1d8adb6765fe7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simplest_migrations.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ben Scofield
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,39 @@
1
+ # SimplestMigrations
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/simplest_migrations`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'simplest_migrations'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install simplest_migrations
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/simplest_migrations/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simplest_migrations"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,58 @@
1
+ require "active_record"
2
+ require "active_record/connection_adapters/postgresql_adapter"
3
+ require 'uri'
4
+
5
+ module SimplestMigrations
6
+ class Database
7
+ def self.migrate
8
+ connection!
9
+ ActiveRecord::Migration.verbose = true
10
+ ActiveRecord::Migrator.migrate 'db/migrate', ENV['VERSION'] ? ENV['VERSION'].to_i : nil
11
+ end
12
+
13
+ def self.execute(cmd, db = nil)
14
+ connection!(db)
15
+ ActiveRecord::Base.connection.execute cmd
16
+ end
17
+
18
+ def self.name
19
+ ENV['DATABASE_NAME']
20
+ end
21
+
22
+ def self.connection!(db = nil)
23
+ ActiveRecord::Base.establish_connection configuration(db)
24
+ ActiveRecord::Base
25
+ end
26
+
27
+ def self.configuration(db = nil)
28
+ @config ||= {}
29
+ db_name = db || name
30
+
31
+ @config[db_name] ||= begin
32
+ url = ENV["DATABASE_URL"]
33
+ uri = URI.parse(url)
34
+
35
+ {
36
+ database: db_name,
37
+ adapter: 'postgresql',
38
+ host: uri.host,
39
+ port: uri.port || 5432,
40
+ encoding: 'unicode',
41
+ pool: 5,
42
+ username: uri.user,
43
+ password: uri.password || ''
44
+ }
45
+ end
46
+
47
+ @config[db_name]
48
+ end
49
+
50
+ def self.set_pg_environment
51
+ config = configuration
52
+ ENV['PGHOST'] = config[:host].to_s
53
+ ENV['PGPORT'] = config[:port].to_s
54
+ ENV['PGPASSWORD'] = config[:password].to_s
55
+ ENV['PGUSER'] = config[:username].to_s
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module SimplestMigrations
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "simplest_migrations/database"
2
+ require "simplest_migrations/version"
data/lib/tasks/db.rake ADDED
@@ -0,0 +1,57 @@
1
+ require_relative "../simplest_migrations"
2
+
3
+ namespace :db do
4
+ desc "Drop the database"
5
+ task :drop do
6
+ SimplestMigrations::Database.execute "DROP DATABASE IF EXISTS #{Database.name}", "postgres"
7
+ end
8
+
9
+ desc "Create the database"
10
+ task :create do
11
+ begin
12
+ SimplestMigrations::Database.execute "CREATE DATABASE #{Database.name}", "postgres"
13
+ rescue ActiveRecord::StatementInvalid => ex
14
+ unless ex.to_s =~ /DuplicateDatabase/
15
+ raise ex
16
+ end
17
+ end
18
+ end
19
+
20
+ desc "Migrate the database"
21
+ task :migrate do
22
+ SimplestMigrations::Database.migrate
23
+ end
24
+
25
+ desc "Rebuild the database"
26
+ task reset: [:drop, :create, :load]
27
+
28
+ desc "Create a new migration: rake db:new name=NAME"
29
+ task :new_migration do |t, args|
30
+ name = ENV['NAME'] || 'new_migration'
31
+ FileUtils.touch("db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_#{name}.rb")
32
+ Rake::Task["db:dump"].invoke
33
+ end
34
+
35
+ desc "Dump the current database schema"
36
+ task :dump do
37
+ file = "db/structure.sql"
38
+
39
+ SimplestMigrations::Database.set_pg_environment
40
+
41
+ command = "pg_dump -s -x -O -f #{file} #{SimplestMigrations::Database.name}"
42
+ Kernel.system(command)
43
+
44
+ command = "pg_dump -t schema_migrations -a #{SimplestMigrations::Database.name} >> #{file}"
45
+ Kernel.system(command)
46
+ end
47
+
48
+ desc "Load the database from the cached schema"
49
+ task :load do
50
+ file = "db/structure.sql"
51
+
52
+ SimplestMigrations::Database.set_pg_environment
53
+
54
+ command = "psql #{SimplestMigrations::Database.name} < #{file}"
55
+ Kernel.system(command)
56
+ end
57
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simplest_migrations/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simplest_migrations"
8
+ spec.version = SimplestMigrations::VERSION
9
+ spec.authors = ["Ben Scofield"]
10
+ spec.email = ["git@turrean.com"]
11
+
12
+ spec.summary = %q{Simple migrations outside of Rails. Postgres only for now.}
13
+ spec.description = %q{Simple migrations outside of Rails. Postgres only for now.}
14
+ spec.homepage = "https://github.com/bscofield/simplest_migrations"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+
25
+ spec.add_dependency "activerecord", "~> 4.2"
26
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplest_migrations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Scofield
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.2'
55
+ description: Simple migrations outside of Rails. Postgres only for now.
56
+ email:
57
+ - git@turrean.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/simplest_migrations.rb
72
+ - lib/simplest_migrations/database.rb
73
+ - lib/simplest_migrations/version.rb
74
+ - lib/tasks/db.rake
75
+ - simplest_migrations.gemspec
76
+ homepage: https://github.com/bscofield/simplest_migrations
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Simple migrations outside of Rails. Postgres only for now.
100
+ test_files: []