chrono_model 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/chrono_model/adapter.rb +1 -21
- data/lib/chrono_model/version.rb +1 -1
- data/spec/aruba/fixtures/migrations/56/20160812190335_create_impressions.rb +10 -0
- data/spec/aruba/fixtures/migrations/56/20171115195229_add_temporal_extension_to_impressions.rb +10 -0
- data/spec/aruba/fixtures/railsapp/config/environments/development.rb +0 -16
- data/spec/aruba/migrations_spec.rb +46 -2
- data/spec/aruba/rake_task_spec.rb +3 -4
- data/spec/support/aruba.rb +16 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bf80e2ead7e4bd268485039492504007f1bef1d
|
4
|
+
data.tar.gz: ec80e086d0723533e8f7bb06e78ec58e1a9edd39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eea3f10b7f18fd38718716ef4c90fc3a65ac4e789a6ae6a888080d655a1b2fae6761830242cf03bb911e9e7f090706c66ddf71bab20b76fb2f76ff3a68caf25e
|
7
|
+
data.tar.gz: fa5936bc34ca7820eefceb3064af13c12d5e323f0f8bede5e01062936b5ae7003bbe104b162a61469e95825a2b74b1580e05a21e5591dd537185842bb75d50d8
|
data/.gitignore
CHANGED
data/lib/chrono_model/adapter.rb
CHANGED
@@ -46,8 +46,6 @@ module ChronoModel
|
|
46
46
|
_on_history_schema { chrono_create_history_for(table_name) }
|
47
47
|
|
48
48
|
chrono_create_view_for(table_name, options)
|
49
|
-
|
50
|
-
TableCache.add! table_name
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
@@ -115,9 +113,6 @@ module ChronoModel
|
|
115
113
|
# Create view and functions
|
116
114
|
#
|
117
115
|
chrono_create_view_for(new_name)
|
118
|
-
|
119
|
-
TableCache.del! name
|
120
|
-
TableCache.add! new_name
|
121
116
|
end
|
122
117
|
end
|
123
118
|
|
@@ -148,8 +143,6 @@ module ChronoModel
|
|
148
143
|
chrono_create_view_for(table_name, options)
|
149
144
|
copy_indexes_to_history_for(table_name)
|
150
145
|
|
151
|
-
TableCache.add! table_name
|
152
|
-
|
153
146
|
# Optionally copy the plain table data, setting up history
|
154
147
|
# retroactively.
|
155
148
|
#
|
@@ -191,8 +184,6 @@ module ChronoModel
|
|
191
184
|
|
192
185
|
execute "ALTER TABLE #{table_name} SET SCHEMA #{default_schema}"
|
193
186
|
end
|
194
|
-
|
195
|
-
TableCache.del! table_name
|
196
187
|
end
|
197
188
|
|
198
189
|
super table_name, options, &block
|
@@ -207,8 +198,6 @@ module ChronoModel
|
|
207
198
|
return super unless is_chrono?(table_name)
|
208
199
|
|
209
200
|
_on_temporal_schema { execute "DROP TABLE #{table_name} CASCADE" }
|
210
|
-
|
211
|
-
TableCache.del! table_name
|
212
201
|
end
|
213
202
|
|
214
203
|
# If adding an index to a temporal table, add it to the one in the
|
@@ -452,20 +441,11 @@ module ChronoModel
|
|
452
441
|
@_on_schema_nesting -= 1
|
453
442
|
end
|
454
443
|
|
455
|
-
TableCache = (Class.new(Hash) do
|
456
|
-
def all ; keys; ; end
|
457
|
-
def add! table ; self[table.to_s] = true ; end
|
458
|
-
def del! table ; self[table.to_s] = nil ; end
|
459
|
-
def fetch table ; self[table.to_s] ||= yield ; end
|
460
|
-
end).new
|
461
|
-
|
462
444
|
# Returns true if the given name references a temporal table.
|
463
445
|
#
|
464
446
|
def is_chrono?(table)
|
465
|
-
|
466
|
-
_on_temporal_schema { chrono_data_source_exists?(table) } &&
|
447
|
+
_on_temporal_schema { chrono_data_source_exists?(table) } &&
|
467
448
|
_on_history_schema { chrono_data_source_exists?(table) }
|
468
|
-
end
|
469
449
|
|
470
450
|
rescue ActiveRecord::StatementInvalid => e
|
471
451
|
# means that we could not change the search path to check for
|
data/lib/chrono_model/version.rb
CHANGED
data/spec/aruba/fixtures/migrations/56/20171115195229_add_temporal_extension_to_impressions.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
class AddTemporalExtensionToImpressions < ActiveRecord::Migration[5.0]
|
2
|
+
def self.up
|
3
|
+
enable_extension 'btree_gist' unless extension_enabled?('btree_gist')
|
4
|
+
change_table :impressions, temporal: true, copy_data: true
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
change_table :impressions, temporal: false
|
9
|
+
end
|
10
|
+
end
|
@@ -12,25 +12,9 @@ Rails.application.configure do
|
|
12
12
|
# Show full error reports.
|
13
13
|
config.consider_all_requests_local = true
|
14
14
|
|
15
|
-
# Enable/disable caching. By default caching is disabled.
|
16
|
-
if Rails.root.join('tmp/caching-dev.txt').exist?
|
17
|
-
config.action_controller.perform_caching = true
|
18
|
-
|
19
|
-
config.cache_store = :memory_store
|
20
|
-
config.public_file_server.headers = {
|
21
|
-
'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
|
22
|
-
}
|
23
|
-
else
|
24
|
-
config.action_controller.perform_caching = false
|
25
|
-
|
26
|
-
config.cache_store = :null_store
|
27
|
-
end
|
28
|
-
|
29
15
|
# Don't care if the mailer can't send.
|
30
16
|
config.action_mailer.raise_delivery_errors = false
|
31
17
|
|
32
|
-
config.action_mailer.perform_caching = false
|
33
|
-
|
34
18
|
# Print deprecation notices to the Rails logger.
|
35
19
|
config.active_support.deprecation = :log
|
36
20
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'database migrations' do
|
3
|
+
describe 'database migrations', type: :aruba do
|
4
4
|
context 'after a migration was generated' do
|
5
5
|
before { write_file('config/database.yml',
|
6
6
|
File.read(File.expand_path('fixtures/database_without_username_and_password.yml', __dir__))) }
|
7
7
|
|
8
8
|
before { run_simple('bundle exec rails g migration CreateModels name:string') }
|
9
9
|
|
10
|
-
describe 'bundle exec rake db:migrate'
|
10
|
+
describe 'bundle exec rake db:migrate' do
|
11
11
|
let(:action) { run('bundle exec rake db:migrate') }
|
12
12
|
let(:last_command) { action && last_command_started }
|
13
13
|
|
@@ -15,4 +15,48 @@ describe 'database migrations' do
|
|
15
15
|
specify { expect(last_command).to have_output(/CreateModels: migrated/) }
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
|
20
|
+
describe 'rerun bundle exec rake db:drop db:create db:migrate', issue: 56 do
|
21
|
+
let(:command) { 'bundle exec rake db:drop db:create db:migrate' }
|
22
|
+
before do
|
23
|
+
copy(
|
24
|
+
'../../spec/aruba/fixtures/database_without_username_and_password.yml',
|
25
|
+
'config/database.yml'
|
26
|
+
)
|
27
|
+
copy(
|
28
|
+
'../../spec/aruba/fixtures/migrations/56/',
|
29
|
+
'db/migrate'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
# Alter migrations and remove the version specifier for Rails < 5.0
|
35
|
+
#
|
36
|
+
if gem_version('rails') < Gem::Version.new('5.0')
|
37
|
+
Dir['spec/aruba/fixtures/migrations/56/*rb'].each do |migration|
|
38
|
+
migration = File.basename(migration)
|
39
|
+
|
40
|
+
file_mangle! "db/migrate/#{migration}" do |contents|
|
41
|
+
contents.sub(/::Migration\[\d\.\d\]/, '::Migration')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:action) { run(command) }
|
48
|
+
let(:regex) { /-- change_table\(:impressions, {:temporal=>true, :copy_data=>true}\)/ }
|
49
|
+
|
50
|
+
describe 'once' do
|
51
|
+
let(:last_command) { action && last_command_started }
|
52
|
+
specify { expect(last_command).to be_successfully_executed }
|
53
|
+
specify { expect(last_command).to have_output(regex) }
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'twice' do
|
57
|
+
let(:last_command) { run_simple(command) && action && last_command_started }
|
58
|
+
specify { expect(last_command).to be_successfully_executed }
|
59
|
+
specify { expect(last_command).to have_output(regex) }
|
60
|
+
end
|
61
|
+
end
|
18
62
|
end
|
@@ -30,10 +30,9 @@ describe 'rake tasks', type: :aruba do
|
|
30
30
|
#
|
31
31
|
before do
|
32
32
|
if which 'brew'
|
33
|
-
|
34
|
-
sub('username: postgres', "username: #{Etc.getlogin}")
|
35
|
-
|
36
|
-
write_file 'config/database.yml', database_config
|
33
|
+
file_mangle!('config/database.yml') do |contents|
|
34
|
+
contents.sub('username: postgres', "username: #{Etc.getlogin}")
|
35
|
+
end
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
data/spec/support/aruba.rb
CHANGED
@@ -29,5 +29,21 @@ module ChronoTest
|
|
29
29
|
connection.drop_database database
|
30
30
|
connection.create_database database
|
31
31
|
end
|
32
|
+
|
33
|
+
def file_mangle!(file, &block)
|
34
|
+
# Read
|
35
|
+
file_contents = read(file).join("\n")
|
36
|
+
|
37
|
+
# Mangle
|
38
|
+
file_contents = block.call(file_contents)
|
39
|
+
|
40
|
+
# Write
|
41
|
+
write_file file, file_contents
|
42
|
+
end
|
43
|
+
|
44
|
+
def gem_version(name)
|
45
|
+
spec = Bundler.locked_gems.specs.find {|s| s.name == name }
|
46
|
+
return spec.version if spec
|
47
|
+
end
|
32
48
|
end
|
33
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chrono_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcello Barnaba
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-11-
|
12
|
+
date: 2017-11-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -234,6 +234,8 @@ files:
|
|
234
234
|
- spec/aruba/fixtures/database_with_default_username_and_password.yml
|
235
235
|
- spec/aruba/fixtures/database_without_username_and_password.yml
|
236
236
|
- spec/aruba/fixtures/empty_structure.sql
|
237
|
+
- spec/aruba/fixtures/migrations/56/20160812190335_create_impressions.rb
|
238
|
+
- spec/aruba/fixtures/migrations/56/20171115195229_add_temporal_extension_to_impressions.rb
|
237
239
|
- spec/aruba/fixtures/railsapp/config/application.rb
|
238
240
|
- spec/aruba/fixtures/railsapp/config/boot.rb
|
239
241
|
- spec/aruba/fixtures/railsapp/config/environments/development.rb
|
@@ -284,6 +286,8 @@ test_files:
|
|
284
286
|
- spec/aruba/fixtures/database_with_default_username_and_password.yml
|
285
287
|
- spec/aruba/fixtures/database_without_username_and_password.yml
|
286
288
|
- spec/aruba/fixtures/empty_structure.sql
|
289
|
+
- spec/aruba/fixtures/migrations/56/20160812190335_create_impressions.rb
|
290
|
+
- spec/aruba/fixtures/migrations/56/20171115195229_add_temporal_extension_to_impressions.rb
|
287
291
|
- spec/aruba/fixtures/railsapp/config/application.rb
|
288
292
|
- spec/aruba/fixtures/railsapp/config/boot.rb
|
289
293
|
- spec/aruba/fixtures/railsapp/config/environments/development.rb
|