dbmigrator 0.5.3

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.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source :rubygems
2
+
3
+ gem 'rake'
4
+ gem 'activerecord', '~>3.2.9'
5
+ gem 'railties', '~>3.2.9'
6
+
7
+ group :dev do
8
+ gem 'jeweler'
9
+ end
10
+
data/Gemfile.lock ADDED
@@ -0,0 +1,71 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionpack (3.2.9)
5
+ activemodel (= 3.2.9)
6
+ activesupport (= 3.2.9)
7
+ builder (~> 3.0.0)
8
+ erubis (~> 2.7.0)
9
+ journey (~> 1.0.4)
10
+ rack (~> 1.4.0)
11
+ rack-cache (~> 1.2)
12
+ rack-test (~> 0.6.1)
13
+ sprockets (~> 2.2.1)
14
+ activemodel (3.2.9)
15
+ activesupport (= 3.2.9)
16
+ builder (~> 3.0.0)
17
+ activerecord (3.2.9)
18
+ activemodel (= 3.2.9)
19
+ activesupport (= 3.2.9)
20
+ arel (~> 3.0.2)
21
+ tzinfo (~> 0.3.29)
22
+ activesupport (3.2.9)
23
+ i18n (~> 0.6)
24
+ multi_json (~> 1.0)
25
+ arel (3.0.2)
26
+ builder (3.0.4)
27
+ erubis (2.7.0)
28
+ git (1.2.5)
29
+ hike (1.2.1)
30
+ i18n (0.6.1)
31
+ jeweler (1.6.4)
32
+ bundler (~> 1.0)
33
+ git (>= 1.2.5)
34
+ rake
35
+ journey (1.0.4)
36
+ json (1.7.5)
37
+ multi_json (1.3.7)
38
+ rack (1.4.1)
39
+ rack-cache (1.2)
40
+ rack (>= 0.4)
41
+ rack-ssl (1.3.2)
42
+ rack
43
+ rack-test (0.6.2)
44
+ rack (>= 1.0)
45
+ railties (3.2.9)
46
+ actionpack (= 3.2.9)
47
+ activesupport (= 3.2.9)
48
+ rack-ssl (~> 1.3.2)
49
+ rake (>= 0.8.7)
50
+ rdoc (~> 3.4)
51
+ thor (>= 0.14.6, < 2.0)
52
+ rake (10.0.2)
53
+ rdoc (3.12)
54
+ json (~> 1.4)
55
+ sprockets (2.2.1)
56
+ hike (~> 1.2)
57
+ multi_json (~> 1.0)
58
+ rack (~> 1.0)
59
+ tilt (~> 1.1, != 1.3.0)
60
+ thor (0.16.0)
61
+ tilt (1.3.3)
62
+ tzinfo (0.3.35)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ activerecord (~> 3.2.9)
69
+ jeweler
70
+ railties (~> 3.2.9)
71
+ rake
data/README.markdown ADDED
@@ -0,0 +1,25 @@
1
+ Rails migration in non-Rails projects.
2
+
3
+ USAGE
4
+ =====
5
+
6
+ Install Ruby 1.9 and your database adapter (e.g. `gem install pg`) then:
7
+
8
+ ```gem install "dbmigrator"```
9
+
10
+ This gems allows only migrate the existing database. We turned off db:create and db:drop due to security issues.
11
+
12
+ To create migration you should use the folling command:
13
+
14
+ ```rake db:migrations:new GROUP=items NAME=add_new_column```
15
+
16
+ This command creates migration with name `add_new_column` within `items` group.
17
+
18
+ To migrate items group use the following command:
19
+
20
+ ```rake db:migrate DATABASE_URL=postgres://user:password@host/database GROUP=items```
21
+
22
+ This command applies migrations within `items` group to database `postgres://user:password@host/database`
23
+
24
+ dbmigrator uses sql schema format `ActiveRecord::Base.schema_format = :sql`. In other words we produce pure sql dumps after db:migrate and use this dump in db:setup task
25
+
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ rescue LoadError => e
7
+ $stderr.puts "Jeweler, or one of its dependencies, is not available:"
8
+ $stderr.puts "#{e.class}: #{e.message}"
9
+ $stderr.puts "Install it with: sudo gem install jeweler"
10
+ else
11
+ Jeweler::Tasks.new do |gem|
12
+ gem.name = 'dbmigrator'
13
+ gem.summary = "Standalone migrator for non Rails projects"
14
+ gem.email = "vasenin@aboutecho.com"
15
+ gem.homepage = "http://github.com/avasenin/dbmigrator"
16
+ gem.authors = ["Andrey Vasenin"]
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.3
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "dbmigrator"
8
+ s.version = "0.5.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andrey Vasenin"]
12
+ s.date = "2012-12-21"
13
+ s.email = "vasenin@aboutecho.com"
14
+ s.extra_rdoc_files = [
15
+ "README.markdown"
16
+ ]
17
+ s.files = [
18
+ "Gemfile",
19
+ "Gemfile.lock",
20
+ "README.markdown",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "dbmigrator.gemspec",
24
+ "example/.gitignore",
25
+ "example/Rakefile",
26
+ "lib/dbmigrator.rb",
27
+ "lib/dbmigrator/migration_generator.rb",
28
+ "lib/dbmigrator/minimal_rails_application.rb",
29
+ "lib/dbmigrator/postgres.rb",
30
+ "lib/dbmigrator/task_manager.rb",
31
+ "lib/dbmigrator/tasks/databases.rake",
32
+ "lib/dbmigrator/templates/migration.rb"
33
+ ]
34
+ s.homepage = "http://github.com/avasenin/dbmigrator"
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.24"
37
+ s.summary = "Standalone migrator for non Rails projects"
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
44
+ s.add_runtime_dependency(%q<activerecord>, ["~> 3.2.9"])
45
+ s.add_runtime_dependency(%q<railties>, ["~> 3.2.9"])
46
+ else
47
+ s.add_dependency(%q<rake>, [">= 0"])
48
+ s.add_dependency(%q<activerecord>, ["~> 3.2.9"])
49
+ s.add_dependency(%q<railties>, ["~> 3.2.9"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rake>, [">= 0"])
53
+ s.add_dependency(%q<activerecord>, ["~> 3.2.9"])
54
+ s.add_dependency(%q<railties>, ["~> 3.2.9"])
55
+ end
56
+ end
57
+
@@ -0,0 +1,5 @@
1
+ *.sqlite3
2
+ Gemfile
3
+ .bundle/
4
+ bin/
5
+ Gemfile.lock
data/example/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ lib = File.expand_path("../../lib", __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ require "dbmigrator"
data/lib/dbmigrator.rb ADDED
@@ -0,0 +1,14 @@
1
+ lib_path = File.dirname(__FILE__)
2
+ $:.unshift lib_path unless $:.include?(lib_path)
3
+
4
+ require "rubygems"
5
+ require "rails"
6
+ require "active_record"
7
+
8
+ if !ENV["RAILS_ENV"]
9
+ ENV["RAILS_ENV"] = ENV["RACK_ENV"] || Rails.env || "development"
10
+ end
11
+
12
+ require "dbmigrator/minimal_rails_application"
13
+
14
+ DbMigrator::MinimalRailsApplication.load_tasks
@@ -0,0 +1,23 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record/migration/migration_generator'
3
+
4
+ class SqlMigrationGenerator < ActiveRecord::Generators::MigrationGenerator
5
+ class_option :location, :type => :string, :default => "db/migrate"
6
+
7
+ def create_migration_file
8
+ set_local_assigns!
9
+ validate_file_name!
10
+ migration_name = "#{file_name}.rb"
11
+ migration_template "migration.rb", File.join(options[:location], migration_name)
12
+ end
13
+
14
+ def source_paths
15
+ [File.join(File.dirname(__FILE__), "templates")]
16
+ end
17
+ protected
18
+ def validate_file_name!
19
+ unless file_name =~ /^[_a-z0-9]+$/
20
+ raise IllegalMigrationNameError.new(file_name)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module DbMigrator
2
+ class MinimalRailsApplication < Rails::Application
3
+ config.generators.options[:rails] = {:orm => :active_record}
4
+
5
+ config.generators.options[:active_record] = {
6
+ :migration => true,
7
+ :timestamps => true
8
+ }
9
+
10
+ rake_tasks do
11
+ Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ require "active_record/connection_adapters/postgresql_adapter"
2
+
3
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do
4
+ def supports_ddl_transactions?
5
+ false # switch off auto transaction to avoid problems with index concerently
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ Rake::TaskManager.class_eval do
2
+ def alias_task(fq_name)
3
+ new_name = "#{fq_name}:original"
4
+ @tasks[new_name] = @tasks.delete(fq_name)
5
+ end
6
+ end
7
+
8
+ def alias_task(fq_name)
9
+ Rake.application.alias_task(fq_name)
10
+ end
11
+
12
+ def override_task(*args, &block)
13
+ name, params, deps = Rake.application.resolve_args(args.dup)
14
+ fq_name = Rake.application.instance_variable_get(:@scope).dup.push(name).join(':')
15
+ alias_task(fq_name)
16
+ Rake::Task.define_task(*args, &block)
17
+ end
18
+
@@ -0,0 +1,66 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..")
2
+
3
+ require "task_manager"
4
+ require "migration_generator"
5
+ require "postgres"
6
+
7
+ load "active_record/railties/databases.rake"
8
+
9
+ db_namespace = namespace :db do
10
+ namespace :migration do
11
+ desc 'Create new migration'
12
+ task :new => ["db:set_migration_paths"] do |t, args|
13
+ if ([:name, :group].all?{|key| options[key].present?})
14
+ ActiveRecord::Migrator.migrations_paths.each do |path|
15
+ Rails::Generators.invoke "sql_migration", [options[:name], "--location=#{path}"],
16
+ :destination_root => Rails.root
17
+ end
18
+ else
19
+ puts "Error: you must provide name and group to generate migration."
20
+ puts "For example: rake #{t.name} NAME=add_field_to_form GROUP=items"
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ task :establish_connection do
27
+ if (ENV["DATABASE_URL"].blank?)
28
+ puts "You should specify DATABASE_URL variable to establist connection to database"
29
+ puts "Example: rake db:migrate DATABASE_URL=postgres://avasenin@localhost/test_db GROUP=items"
30
+ abort
31
+ end
32
+ ActiveRecord::Base.configurations = {Rails.env => database_url_config}
33
+ ActiveRecord::Base.establish_connection database_url_config
34
+ end
35
+
36
+ task :set_migration_paths do
37
+ if (options[:group].blank?)
38
+ puts "You should specify GROUP variable to set correct migration folder"
39
+ puts "Example: rake db:migration:new NAME=test_migration GROUP=items"
40
+ abort
41
+ end
42
+
43
+ ActiveRecord::Base.schema_format = :sql
44
+
45
+ root_folder = File.join(Rails.root, "db", options[:group])
46
+ FileUtils.mkdir_p root_folder
47
+
48
+ ActiveRecord::Migrator.migrations_paths = [File.join(root_folder, "migrate")]
49
+ Rails.application.paths['db/seeds'] = File.join(root_folder, "seed.rb")
50
+ ENV['DB_STRUCTURE'] = File.join(root_folder, "structure.sql")
51
+ end
52
+
53
+ override_task :load_config => [:establish_connection, :set_migration_paths] do
54
+ end
55
+
56
+ override_task :create
57
+ override_task :drop
58
+
59
+ override_task :setup => [:environment, :load_config] do
60
+ Rake::Task['db:setup:original'].invoke
61
+ end
62
+ end
63
+
64
+ def options
65
+ Hash[ENV.map{|key,value| [key.to_s.downcase.parameterize.underscore.to_sym,value]}]
66
+ end
@@ -0,0 +1,7 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def up
3
+ end
4
+
5
+ def down
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbmigrator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey Vasenin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 3.2.9
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.9
46
+ - !ruby/object:Gem::Dependency
47
+ name: railties
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 3.2.9
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.9
62
+ description:
63
+ email: vasenin@aboutecho.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - README.markdown
68
+ files:
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - README.markdown
72
+ - Rakefile
73
+ - VERSION
74
+ - dbmigrator.gemspec
75
+ - example/.gitignore
76
+ - example/Rakefile
77
+ - lib/dbmigrator.rb
78
+ - lib/dbmigrator/migration_generator.rb
79
+ - lib/dbmigrator/minimal_rails_application.rb
80
+ - lib/dbmigrator/postgres.rb
81
+ - lib/dbmigrator/task_manager.rb
82
+ - lib/dbmigrator/tasks/databases.rake
83
+ - lib/dbmigrator/templates/migration.rb
84
+ homepage: http://github.com/avasenin/dbmigrator
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -2120803987318549885
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.24
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Standalone migrator for non Rails projects
111
+ test_files: []