active_record_migrations 4.0.0.0.pre.optimistic
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +93 -0
- data/Rakefile +1 -0
- data/active_record_migrations.gemspec +33 -0
- data/lib/active_record_migrations/configurations.rb +27 -0
- data/lib/active_record_migrations/generators/migration.rb +18 -0
- data/lib/active_record_migrations/tasks/new_migration.rake +34 -0
- data/lib/active_record_migrations/version.rb +3 -0
- data/lib/active_record_migrations.rb +43 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f5c8a81eb9fe55bd7b1ef8e4af6126cd8d7771f4
|
4
|
+
data.tar.gz: af1237a86da35f8cb2b7fcafe41040a2a10713d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e613099dcb5eebd5b023188da866fb01260422d938d62646c29cab8a9354d963a1e934074c1f7910ae4df0bb1c40aee21a3fb0d9527c082a744617ba694f45d
|
7
|
+
data.tar.gz: 9c291428efabd3596a3d507b5b8571b29eb22d9ff797c67996b299275fb70d2f98c4fb5f5443c322cf196b4b6a62e13a28d1f8f11d13519c90d45b6b27873ae4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Rodrigo Rosenfeld Rosas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# ActiveRecord Stand-alone Migrations
|
2
|
+
|
3
|
+
Allows you to use ActiveRecord migrations in non-Rails projects.
|
4
|
+
|
5
|
+
This branch is for the _optimistic_ version, assuming the internals of AR migrations we rely on
|
6
|
+
won't change until the next major version. However, we can't really promiss the related AR
|
7
|
+
migrations code won't change in minor or patch versions of AR. That's why we can't release this
|
8
|
+
branch as a final version.
|
9
|
+
|
10
|
+
But at least you should be able to try it with basically any AR version in case you have to deal
|
11
|
+
with conflicts.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile (run `bundle init` if you don't have one):
|
16
|
+
|
17
|
+
gem 'active_record_migrations', '4.0.0.0.pre.optimistic'
|
18
|
+
gem 'sqlite3' # or 'pg', 'mysql2', ...
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle --binstubs
|
23
|
+
|
24
|
+
Create a Rakefile:
|
25
|
+
|
26
|
+
require 'active_record_migrations'
|
27
|
+
ActiveRecordMigrations.load_tasks
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
By default, your database configurations will be read from `db/config.yml` and your migration files
|
32
|
+
will be created under `db/migrate`. If you want to keep with the defaults, create your `db/config.yml`:
|
33
|
+
|
34
|
+
```yaml
|
35
|
+
development:
|
36
|
+
adapter: postgresql
|
37
|
+
database: my_db
|
38
|
+
encoding: utf8
|
39
|
+
host: localhost
|
40
|
+
port: 5432
|
41
|
+
username: noel
|
42
|
+
password: s3cret
|
43
|
+
test:
|
44
|
+
adapter: sqlite3
|
45
|
+
database: db/test.sqlite3
|
46
|
+
pool: 5
|
47
|
+
timeout: 5000
|
48
|
+
```
|
49
|
+
|
50
|
+
If you prefer to specify your settings in plain Ruby, add this to your Rakefile,
|
51
|
+
before calling `ActiveRecordMigrations.load_taks`:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
ActiveRecordMigrations.configure do |c|
|
55
|
+
c.database_configuration = {
|
56
|
+
'development' => {'adapter' => 'sqlite3', 'database' => 'db/custom.sqlite3'},
|
57
|
+
}
|
58
|
+
# Other settings:
|
59
|
+
c.schema_format = :sql # default is :ruby
|
60
|
+
# c.yaml_config = 'db/config.yml'
|
61
|
+
# c.environment = ENV['db']
|
62
|
+
# c.db_dir = 'db'
|
63
|
+
# c.migrations_paths = ['db/migrate'] # the first entry will be used by the generator
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
Take a look at the [Migrations Guide](http://guides.rubyonrails.org/migrations.html) for more details.
|
68
|
+
|
69
|
+
The main difference is that instead of `rails generate migration` (or `rails g migration`), the generator is
|
70
|
+
implemented as a Rake task. So you should use it like `rake "db:new_migration[CreateUser, name birth:date]"`
|
71
|
+
(double quotes are required if you use this form). Alternatively you could run it as
|
72
|
+
`rake db:new_migration name=CreateUser options="name birth:date"`.
|
73
|
+
|
74
|
+
Just run `rake db:new_migration` for help on usage.
|
75
|
+
|
76
|
+
You can specify the environment by setting the `db` environment variable:
|
77
|
+
|
78
|
+
rake db:migrate db=production
|
79
|
+
|
80
|
+
## Versioning
|
81
|
+
|
82
|
+
For final releases, the version follows ActiveRecord versions plus a patch version from our own.
|
83
|
+
For instance, if AR version is 4.0.1, this gem will be versioned 4.0.1.x with x starting in 0.
|
84
|
+
|
85
|
+
This branch however won't use pessimistic locking so that you have some flexibility if you need.
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
1. Fork it
|
90
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
91
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
92
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
93
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_record_migrations/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "active_record_migrations"
|
8
|
+
spec.version = ActiveRecordMigrations::VERSION
|
9
|
+
spec.authors = ["Rodrigo Rosenfeld Rosas"]
|
10
|
+
spec.email = ["rr.rosas@gmail.com"]
|
11
|
+
spec.description = %q{ActiveRecord Stand-alone migrations}
|
12
|
+
spec.summary = %q{Use AR migrations from outside of a Rails project}
|
13
|
+
spec.homepage = "http://github.com/rosenfeld/active_record_migrations"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_dependency "rake"
|
23
|
+
# We rely on a kind of monkey patch for allowing us to override the migrations path.
|
24
|
+
# The final releases fix on an specific version of AR and check if the override of
|
25
|
+
# ActiveRecord::Generators::MigrationGenerator#create_migration_file is correct
|
26
|
+
# before upgrading AR dependency. See ARM::Generators::MigrationGenerator impl.
|
27
|
+
# The "optimistic" versions allow more flexibility to support other AR versions but
|
28
|
+
# on the other side we can't really guarantee that it will actually work since it depends
|
29
|
+
# on internal implementation of AR migrations that could change any time.
|
30
|
+
spec.add_dependency "railties", "~> 4.0"
|
31
|
+
spec.add_dependency "activerecord", "~> 4.0"
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'yaml'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module ActiveRecordMigrations
|
6
|
+
class Configurations
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_accessor :yaml_config, :database_configuration, :environment, :db_dir, :migrations_paths, :schema_format, :seed_loader
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@yaml_config = 'db/config.yml'
|
13
|
+
@environment = ENV['db'] || Rails.env
|
14
|
+
@db_dir = 'db'
|
15
|
+
@migrations_paths = ['db/migrate']
|
16
|
+
@schema_format = :ruby # or :sql
|
17
|
+
@seed_loader = Rails.application
|
18
|
+
end
|
19
|
+
|
20
|
+
alias configure instance_eval
|
21
|
+
|
22
|
+
def database_configuration
|
23
|
+
@database_configuration ||= YAML.load(ERB.new(File.read @yaml_config).result)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators/active_record/migration/migration_generator'
|
2
|
+
require 'active_record/tasks/database_tasks'
|
3
|
+
|
4
|
+
module ActiveRecordMigrations
|
5
|
+
module Generators
|
6
|
+
class MigrationGenerator < ::ActiveRecord::Generators::MigrationGenerator
|
7
|
+
source_root ::ActiveRecord::Generators::MigrationGenerator.source_root
|
8
|
+
|
9
|
+
def create_migration_file
|
10
|
+
set_local_assigns!
|
11
|
+
validate_file_name!
|
12
|
+
dir = ::ActiveRecord::Tasks::DatabaseTasks.migrations_paths.first
|
13
|
+
migration_template @migration_template, "#{dir}/#{file_name}.rb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'active_record'
|
3
|
+
require 'active_record/tasks/database_tasks'
|
4
|
+
require 'active_record_migrations/configurations'
|
5
|
+
require 'active_record_migrations/generators/migration'
|
6
|
+
|
7
|
+
task environment: 'db:load_config' do
|
8
|
+
ActiveRecord::Base.establish_connection ActiveRecord::Tasks::DatabaseTasks.current_config
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :db do
|
12
|
+
desc "Creates a new migration file with the specified name"
|
13
|
+
task :new_migration, :name, :options do |t, args|
|
14
|
+
name = args[:name] || ENV['name']
|
15
|
+
options = args[:options] || ENV['options']
|
16
|
+
|
17
|
+
unless name
|
18
|
+
generator = Rails::Generators.find_by_namespace "migration"
|
19
|
+
desc = generator.desc.gsub(/`rails (?:g|generate) migration (\w+)`/, '`rake "db:new_migration[\\1]"`' ).
|
20
|
+
gsub(/`rails (?:g|generate) migration (\w+) (.*)`/, '`rake "db:new_migration[\\1, \\2]"`' )
|
21
|
+
puts [
|
22
|
+
%Q{Usage: rake "#{t.name}[AddFieldToForm[, field[:type][:index]] field[:type][:index]]"},
|
23
|
+
desc,
|
24
|
+
].join "\n\n"
|
25
|
+
abort
|
26
|
+
end
|
27
|
+
params = [name]
|
28
|
+
params.concat options.split(' ') if options
|
29
|
+
#Rails::Generators.invoke "active_record:migration", params,
|
30
|
+
Rails::Generators.invoke "active_record_migrations:migration", params,
|
31
|
+
behavior: :invoke, destination_root: Rails.root
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "active_record_migrations/version"
|
2
|
+
require 'active_record'
|
3
|
+
require 'active_record/tasks/database_tasks'
|
4
|
+
require 'rails'
|
5
|
+
require 'rails/application'
|
6
|
+
require 'active_record_migrations/configurations'
|
7
|
+
|
8
|
+
module ActiveRecordMigrations
|
9
|
+
include ActiveRecord::Tasks
|
10
|
+
|
11
|
+
def self.configure(&block)
|
12
|
+
create_rails_app_if_not_exists
|
13
|
+
configurations.configure &block
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.load_tasks
|
17
|
+
create_rails_app_if_not_exists
|
18
|
+
|
19
|
+
load "active_record/railties/databases.rake"
|
20
|
+
load 'active_record_migrations/tasks/new_migration.rake'
|
21
|
+
|
22
|
+
ActiveRecord::Base.schema_format = configurations.schema_format
|
23
|
+
DatabaseTasks.env = configurations.environment
|
24
|
+
DatabaseTasks.seed_loader = configurations.seed_loader
|
25
|
+
ActiveRecord::Base.configurations = DatabaseTasks.database_configuration =
|
26
|
+
configurations.database_configuration
|
27
|
+
DatabaseTasks.current_config = configurations.database_configuration[configurations.environment]
|
28
|
+
DatabaseTasks.db_dir = configurations.db_dir
|
29
|
+
DatabaseTasks.migrations_paths = configurations.migrations_paths
|
30
|
+
DatabaseTasks.root = Rails.root
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def self.create_rails_app_if_not_exists
|
36
|
+
Class.new(Rails::Application) unless Rails.application
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.configurations
|
40
|
+
Configurations.instance
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_record_migrations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 4.0.0.0.pre.optimistic
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Rosenfeld Rosas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-22 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
69
|
+
description: ActiveRecord Stand-alone migrations
|
70
|
+
email:
|
71
|
+
- rr.rosas@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- active_record_migrations.gemspec
|
82
|
+
- lib/active_record_migrations.rb
|
83
|
+
- lib/active_record_migrations/configurations.rb
|
84
|
+
- lib/active_record_migrations/generators/migration.rb
|
85
|
+
- lib/active_record_migrations/tasks/new_migration.rake
|
86
|
+
- lib/active_record_migrations/version.rb
|
87
|
+
homepage: http://github.com/rosenfeld/active_record_migrations
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.3.1
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.4.5
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Use AR migrations from outside of a Rails project
|
111
|
+
test_files: []
|
112
|
+
has_rdoc:
|