activerecord-turntable 2.1.0.beta2 → 2.1.0.rc1
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 +4 -4
- data/CHANGELOG.md +1 -0
- data/lib/active_record/turntable/migration.rb +55 -0
- data/lib/active_record/turntable/railties/databases.rake +112 -127
- data/lib/active_record/turntable/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6223a14dc7586f9425a7450535d1d90075e7337
|
4
|
+
data.tar.gz: 6c02e240d36b6abe0c8f56a0174e2054ced1d4c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
4
|
+
turntable_namespace = nil
|
5
5
|
|
6
6
|
db_namespace = namespace :db do
|
7
|
-
namespace :
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
shard_configs
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
97
|
+
turntable_namespace['structure:dump'].reenable
|
128
98
|
end
|
129
|
-
db_namespace['structure:dump'].reenable
|
130
|
-
end
|
131
99
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
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.
|
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-
|
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:
|