activerecord-turntable 2.1.0.beta2 → 2.1.0.rc1

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
  SHA1:
3
- metadata.gz: c2673c7fcde5190f1b2da9ac7d398ebf0e3faf1a
4
- data.tar.gz: 40fa47723f339d79d3846aaa90aabccdc0232337
3
+ metadata.gz: a6223a14dc7586f9425a7450535d1d90075e7337
4
+ data.tar.gz: 6c02e240d36b6abe0c8f56a0174e2054ced1d4c1
5
5
  SHA512:
6
- metadata.gz: b79b1ecdbea938ab801be102982441244841af16ff2c83fd4bc1a003f10ec000adc95480a40ac2e743ddd10a9d8ad9d7a84ae12aecb70abe1d4be68ee3783f6c
7
- data.tar.gz: 1b35bfd21a4a4bfa04506375785f3e1496eb03f1ab209776d03295deab494ea9983e6bc523341d83df8577da82272190e11c8de0d8511aa3b998142ae98800bc
6
+ metadata.gz: 858730a5f8d9359177599e38652f91813016d5c5901d125ef544419b3f1e4f18f1c1b59630b09e8401acb1867a531f7aa14d4f034461511e665e3ad69107afc2
7
+ data.tar.gz: 4fbea3f83b7415584c322c81234dfdf6e13316f4643b7ee7dd197701aa638046dbefb9a9f54cc6548a751f14defc26b3930230b205904515f2320e61c68344fb
data/CHANGELOG.md CHANGED
@@ -5,6 +5,7 @@ Support activerecord 4.2.0
5
5
  ### Bugfixes
6
6
 
7
7
  * Fix cluster helper methods(i.e xxxx_cluster_transaction helper) on lazy load environments(development, test)
8
+ * Move migration tasks as Migrator extension to fix rake actions(added by other gems) ordering problem
8
9
 
9
10
  ## activerecord-turntable 2.0.6 ##
10
11
 
@@ -8,6 +8,7 @@ module ActiveRecord::Turntable::Migration
8
8
  alias_method_chain :exec_migration, :turntable
9
9
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, SchemaStatementsExt)
10
10
  ::ActiveRecord::Migration::CommandRecorder.send(:include, CommandRecorder)
11
+ ::ActiveRecord::Migrator.send(:include, Migrator)
11
12
  end
12
13
 
13
14
  module ShardDefinition
@@ -93,4 +94,58 @@ module ActiveRecord::Turntable::Migration
93
94
  end
94
95
  end
95
96
 
97
+ module Migrator
98
+ extend ActiveSupport::Concern
99
+
100
+ included do
101
+ klass = self
102
+ (class << klass; self; end).instance_eval {
103
+ [:up, :down, :run, :open].each do |method_name|
104
+ original_method_alias = "_original_#{method_name}"
105
+ unless klass.respond_to?(original_method_alias)
106
+ alias_method original_method_alias, method_name
107
+ end
108
+ alias_method_chain method_name, :turntable
109
+ end
110
+ }
111
+ end
112
+
113
+ module ClassMethods
114
+ def up_with_turntable(migrations_paths, target_version = nil)
115
+ up_without_turntable(migrations_paths, target_version)
116
+
117
+ ActiveRecord::Tasks::DatabaseTasks.each_current_turntable_cluster_connected do |name, configuration|
118
+ puts "[turntable] *** Migrating database: #{configuration['database']}(Shard: #{name})"
119
+ _original_up(migrations_paths, target_version)
120
+ end
121
+ end
122
+
123
+ def down_with_turntable(migrations_paths, target_version = nil, &block)
124
+ down_without_turntable(migrations_paths, target_version, &block)
125
+
126
+ ActiveRecord::Tasks::DatabaseTasks.each_current_turntable_cluster_connected do |name, configuration|
127
+ puts "[turntable] *** Migrating database: #{configuration['database']}(Shard: #{name})"
128
+ _original_down(migrations_paths, target_version, &block)
129
+ end
130
+ end
131
+
132
+ def run_with_turntable(*args)
133
+ run_without_turntable(*args)
134
+
135
+ ActiveRecord::Tasks::DatabaseTasks.each_current_turntable_cluster_connected do |name, configuration|
136
+ puts "[turntable] *** Migrating database: #{configuration['database']}(Shard: #{name})"
137
+ _original_run(*args)
138
+ end
139
+ end
140
+
141
+ def open_with_turntable(migrations_paths)
142
+ open_without_turntable(migrations_paths)
143
+
144
+ ActiveRecord::Tasks::DatabaseTasks.each_current_turntable_cluster_connected do |name, configuration|
145
+ puts "[turntable] *** Migrating database: #{configuration['database']}(Shard: #{name})"
146
+ _original_open(*args)
147
+ end
148
+ end
149
+ end
150
+ end
96
151
  end
@@ -1,164 +1,149 @@
1
1
  require 'active_record/turntable'
2
2
  ActiveRecord::SchemaDumper.send(:include, ActiveRecord::Turntable::ActiveRecordExt::SchemaDumper)
3
3
 
4
- # TODO: implement schema:cache:xxxx
4
+ turntable_namespace = nil
5
5
 
6
6
  db_namespace = namespace :db do
7
- namespace :create do
8
- task :all => :load_config do
9
- ActiveRecord::Tasks::DatabaseTasks.create_all_turntable_cluster
10
- end
11
- end
12
-
13
- desc 'Create current turntable databases config/database.yml for the current Rails.env'
14
- task :create => [:load_config] do
15
- unless ENV['DATABASE_URL']
16
- ActiveRecord::Tasks::DatabaseTasks.create_current_turntable_cluster
17
- end
18
- end
19
-
20
- namespace :drop do
21
- task :all => :load_config do
22
- ActiveRecord::Tasks::DatabaseTasks.drop_all_turntable_cluster
23
- end
24
- end
25
-
26
- desc 'Drops current turntable databases for the current Rails.env'
27
- task :drop => [:load_config] do
28
- unless ENV['DATABASE_URL']
29
- ActiveRecord::Tasks::DatabaseTasks.drop_current_turntable_cluster
7
+ turntable_namespace = namespace :turntable do
8
+ namespace :create do
9
+ task :all do
10
+ ActiveRecord::Tasks::DatabaseTasks.create_all_turntable_cluster
11
+ end
30
12
  end
31
- end
32
-
33
- desc "Migrate turntable databases (options: VERSION=x, VERBOSE=false, SCOPE=blog)."
34
- task :migrate => [:environment, :load_config] do
35
- ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
36
13
 
37
- ActiveRecord::Tasks::DatabaseTasks.each_current_turntable_cluster_connected do |name, configuration|
38
- puts "[turntable] *** Migrating database: #{configuration['database']}(Shard: #{name})"
39
- ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
40
- db_namespace['_dump'].invoke
14
+ desc 'Create current turntable databases config/database.yml for the current Rails.env'
15
+ task :create do
16
+ unless ENV['DATABASE_URL']
17
+ ActiveRecord::Tasks::DatabaseTasks.create_current_turntable_cluster
18
+ end
41
19
  end
42
- end
43
20
 
44
- desc 'Rolls the turntable cluster schema back to the previous version (specify steps w/ STEP=n).'
45
- task :rollback => [:environment, :load_config] do
46
- step = ENV['STEP'] ? ENV['STEP'].to_i : 1
47
-
48
- ActiveRecord::Tasks::DatabaseTasks.each_current_turntable_cluster_connected do |name, configuration|
49
- puts "[turntable] *** Migrating database: #{configuration['database']}(Shard: #{name})"
50
- ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
21
+ namespace :drop do
22
+ task :all do
23
+ ActiveRecord::Tasks::DatabaseTasks.drop_all_turntable_cluster
24
+ end
51
25
  end
52
- db_namespace['_dump'].invoke
53
- end
54
-
55
- # desc 'Pushes the turntable cluster schema to the next version (specify steps w/ STEP=n).'
56
- task :forward => [:environment, :load_config] do
57
- step = ENV['STEP'] ? ENV['STEP'].to_i : 1
58
26
 
59
- ActiveRecord::Tasks::DatabaseTasks.each_current_turntable_cluster_connected do |name, configuration|
60
- puts "[turntable] *** Migrating database: #{configuration['database']}(Shard: #{name})"
61
- ActiveRecord::Migrator.forward(ActiveRecord::Migrator.migrations_paths, step)
27
+ desc 'Drops current turntable databases for the current Rails.env'
28
+ task :drop do
29
+ unless ENV['DATABASE_URL']
30
+ ActiveRecord::Tasks::DatabaseTasks.drop_current_turntable_cluster
31
+ end
62
32
  end
63
- db_namespace['_dump'].invoke
64
- end
65
-
66
33
 
67
- namespace :schema do
68
- task :dump do
69
- require 'active_record/schema_dumper'
70
- config = ActiveRecord::Base.configurations[Rails.env]
71
- shard_configs = config["shards"]
72
- shard_configs.merge!(config["seq"]) if config["seq"]
73
- if shard_configs
74
- shard_configs.each do |name, config|
75
- next unless config["database"]
76
- filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema-#{name}.rb"
77
- File.open(filename, "w:utf-8") do |file|
78
- ActiveRecord::Base.establish_connection(config)
79
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
34
+ namespace :schema do
35
+ # TODO: implement schema:cache:xxxx
36
+ task :dump do
37
+ require 'active_record/schema_dumper'
38
+ config = ActiveRecord::Base.configurations[Rails.env]
39
+ shard_configs = config["shards"]
40
+ shard_configs.merge!(config["seq"]) if config["seq"]
41
+ if shard_configs
42
+ shard_configs.each do |name, config|
43
+ next unless config["database"]
44
+ filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema-#{name}.rb"
45
+ File.open(filename, "w:utf-8") do |file|
46
+ ActiveRecord::Base.establish_connection(config)
47
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
48
+ end
80
49
  end
81
50
  end
51
+ ActiveRecord::Base.establish_connection(config)
52
+ turntable_namespace['schema:dump'].reenable
82
53
  end
83
- ActiveRecord::Base.establish_connection(config)
84
- db_namespace['schema:dump'].reenable
85
- end
86
54
 
87
- desc 'Load a schema.rb file into the database'
88
- task :load => :environment do
89
- config = ActiveRecord::Base.configurations[Rails.env]
90
- shard_configs = config["shards"]
91
- shard_configs.merge!(config["seq"]) if config["seq"]
92
- if shard_configs
93
- shard_configs.each do |name, config|
94
- next unless config["database"]
95
- ActiveRecord::Base.establish_connection(config)
96
- file = ENV['SCHEMA'] || "#{Rails.root}/db/schema-#{name}.rb"
97
- if File.exists?(file)
98
- load(file)
99
- else
100
- abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to limit the frameworks that will be loaded'}
55
+ desc 'Load a schema.rb file into the database'
56
+ task :load do
57
+ config = ActiveRecord::Base.configurations[Rails.env]
58
+ shard_configs = config["shards"]
59
+ shard_configs.merge!(config["seq"]) if config["seq"]
60
+ if shard_configs
61
+ shard_configs.each do |name, config|
62
+ next unless config["database"]
63
+ ActiveRecord::Base.establish_connection(config)
64
+ file = ENV['SCHEMA'] || "#{Rails.root}/db/schema-#{name}.rb"
65
+ if File.exists?(file)
66
+ load(file)
67
+ else
68
+ abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to limit the frameworks that will be loaded'}
69
+ end
101
70
  end
102
71
  end
72
+ ActiveRecord::Base.establish_connection(config)
103
73
  end
104
- ActiveRecord::Base.establish_connection(config)
105
74
  end
106
- end
107
75
 
108
- namespace :structure do
109
- desc 'Dump the database structure to an SQL file'
110
- task :dump => :environment do
111
- current_config = ActiveRecord::Tasks::DatabaseTasks.current_config
112
- shard_configs = current_config["shards"]
113
- shard_configs.merge!(config["seq"]) if config["seq"]
114
- if shard_configs
115
- shard_configs.each do |name, config|
116
- next unless config["database"]
117
- ActiveRecord::Base.establish_connection(config)
118
- filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "structure_#{name}.sql")
119
- ActiveRecord::Tasks::DatabaseTasks.structure_dump(config, filename)
76
+ namespace :structure do
77
+ desc 'Dump the database structure to an SQL file'
78
+ task :dump do
79
+ current_config = ActiveRecord::Tasks::DatabaseTasks.current_config
80
+ shard_configs = current_config["shards"]
81
+ shard_configs.merge!(config["seq"]) if config["seq"]
82
+ if shard_configs
83
+ shard_configs.each do |name, config|
84
+ next unless config["database"]
85
+ ActiveRecord::Base.establish_connection(config)
86
+ filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "structure_#{name}.sql")
87
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump(config, filename)
120
88
 
121
- if ActiveRecord::Base.connection.supports_migrations?
122
- File.open(filename, "a") do |f|
123
- f.puts ActiveRecord::Base.connection.dump_schema_information
89
+ if ActiveRecord::Base.connection.supports_migrations?
90
+ File.open(filename, "a") do |f|
91
+ f.puts ActiveRecord::Base.connection.dump_schema_information
92
+ end
124
93
  end
125
94
  end
95
+ ActiveRecord::Base.establish_connection(current_config)
126
96
  end
127
- ActiveRecord::Base.establish_connection(current_config)
97
+ turntable_namespace['structure:dump'].reenable
128
98
  end
129
- db_namespace['structure:dump'].reenable
130
- end
131
99
 
132
- # desc "Recreate the databases from the structure.sql file"
133
- task :load => [:environment, :load_config] do
134
- current_config = ActiveRecord::Tasks::DatabaseTasks.current_config
135
- shard_configs = current_config["shards"]
136
- shard_configs.merge!(config["seq"]) if config["seq"]
137
- if shard_configs
138
- shard_configs.each do |name, config|
139
- next unless config["database"]
140
- ActiveRecord::Base.establish_connection(config)
141
- filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "structure_#{name}.sql")
142
- ActiveRecord::Tasks::DatabaseTasks.structure_load(config, filename)
100
+ # desc "Recreate the databases from the structure.sql file"
101
+ task :load do
102
+ current_config = ActiveRecord::Tasks::DatabaseTasks.current_config
103
+ shard_configs = current_config["shards"]
104
+ shard_configs.merge!(config["seq"]) if config["seq"]
105
+ if shard_configs
106
+ shard_configs.each do |name, config|
107
+ next unless config["database"]
108
+ ActiveRecord::Base.establish_connection(config)
109
+ filename = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "structure_#{name}.sql")
110
+ ActiveRecord::Tasks::DatabaseTasks.structure_load(config, filename)
111
+ end
112
+ ActiveRecord::Base.establish_connection(current_config)
143
113
  end
144
- ActiveRecord::Base.establish_connection(current_config)
145
114
  end
146
115
  end
147
- end
148
116
 
149
- namespace :test do
150
- # desc "Empty the test database"
151
- task :purge => :environment do
152
- config = ActiveRecord::Base.configurations[Rails.env]
153
- shard_configs = config["shards"]
154
- shard_configs.merge!(config["seq"]) if config["seq"]
155
- if shard_configs
156
- shard_configs.each do |name, config|
157
- next unless config["database"]
158
- ActiveRecord::Tasks::DatabaseTasks.purge config
117
+ namespace :test do
118
+ # desc "Empty the test database"
119
+ task :purge do
120
+ config = ActiveRecord::Base.configurations[Rails.env]
121
+ shard_configs = config["shards"]
122
+ shard_configs.merge!(config["seq"]) if config["seq"]
123
+ if shard_configs
124
+ shard_configs.each do |name, config|
125
+ next unless config["database"]
126
+ ActiveRecord::Tasks::DatabaseTasks.purge config
127
+ end
159
128
  end
129
+ ActiveRecord::Base.establish_connection(config)
160
130
  end
161
- ActiveRecord::Base.establish_connection(config)
162
131
  end
163
132
  end
164
133
  end
134
+
135
+ %w(
136
+ create:all
137
+ create
138
+ drop:all
139
+ drop
140
+ schema:dump
141
+ schema:load
142
+ structure:dump
143
+ structure:load
144
+ test:purge
145
+ ).each do |task_name|
146
+ db_namespace[task_name].enhance do
147
+ turntable_namespace[task_name].invoke
148
+ end
149
+ end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Turntable
3
- VERSION = "2.1.0.beta2"
3
+ VERSION = "2.1.0.rc1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-turntable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.beta2
4
+ version: 2.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - gussan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-16 00:00:00.000000000 Z
12
+ date: 2015-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -513,3 +513,4 @@ test_files:
513
513
  - spec/spec_helper.rb
514
514
  - spec/support/matchers/be_saved_to.rb
515
515
  - spec/support/turntable_helper.rb
516
+ has_rdoc: