chrono_model 1.2.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +19 -20
- data/README.md +62 -40
- data/lib/active_record/connection_adapters/chronomodel_adapter.rb +17 -11
- data/lib/active_record/tasks/chronomodel_database_tasks.rb +64 -23
- data/lib/chrono_model/adapter/ddl.rb +168 -153
- data/lib/chrono_model/adapter/indexes.rb +99 -94
- data/lib/chrono_model/adapter/migrations.rb +81 -104
- data/lib/chrono_model/adapter/migrations_modules/legacy.rb +41 -0
- data/lib/chrono_model/adapter/migrations_modules/stable.rb +41 -0
- data/lib/chrono_model/adapter/tsrange.rb +20 -5
- data/lib/chrono_model/adapter/upgrade.rb +89 -91
- data/lib/chrono_model/adapter.rb +64 -31
- data/lib/chrono_model/chrono.rb +17 -0
- data/lib/chrono_model/conversions.rb +15 -9
- data/lib/chrono_model/db_console.rb +9 -0
- data/lib/chrono_model/json.rb +9 -6
- data/lib/chrono_model/patches/as_of_time_holder.rb +2 -2
- data/lib/chrono_model/patches/as_of_time_relation.rb +2 -2
- data/lib/chrono_model/patches/association.rb +15 -12
- data/lib/chrono_model/patches/batches.rb +17 -0
- data/lib/chrono_model/patches/db_console.rb +20 -4
- data/lib/chrono_model/patches/join_node.rb +4 -4
- data/lib/chrono_model/patches/preloader.rb +41 -11
- data/lib/chrono_model/patches/relation.rb +53 -8
- data/lib/chrono_model/patches.rb +3 -1
- data/lib/chrono_model/railtie.rb +29 -24
- data/lib/chrono_model/time_gate.rb +3 -3
- data/lib/chrono_model/time_machine/history_model.rb +65 -31
- data/lib/chrono_model/time_machine/time_query.rb +65 -49
- data/lib/chrono_model/time_machine/timeline.rb +52 -28
- data/lib/chrono_model/time_machine.rb +66 -25
- data/lib/chrono_model/utilities.rb +3 -3
- data/lib/chrono_model/version.rb +3 -1
- data/lib/chrono_model.rb +31 -36
- metadata +39 -136
- data/.gitignore +0 -21
- data/.rspec +0 -2
- data/.travis.yml +0 -41
- data/Gemfile +0 -4
- data/README.sql +0 -161
- data/Rakefile +0 -25
- data/chrono_model.gemspec +0 -33
- data/gemfiles/rails_5.0.gemfile +0 -6
- data/gemfiles/rails_5.1.gemfile +0 -6
- data/gemfiles/rails_5.2.gemfile +0 -6
- data/spec/aruba/dbconsole_spec.rb +0 -25
- data/spec/aruba/fixtures/database_with_default_username_and_password.yml +0 -14
- data/spec/aruba/fixtures/database_without_username_and_password.yml +0 -11
- data/spec/aruba/fixtures/empty_structure.sql +0 -27
- data/spec/aruba/fixtures/migrations/56/20160812190335_create_impressions.rb +0 -10
- data/spec/aruba/fixtures/migrations/56/20171115195229_add_temporal_extension_to_impressions.rb +0 -10
- data/spec/aruba/fixtures/railsapp/config/application.rb +0 -17
- data/spec/aruba/fixtures/railsapp/config/boot.rb +0 -5
- data/spec/aruba/fixtures/railsapp/config/environments/development.rb +0 -38
- data/spec/aruba/migrations_spec.rb +0 -48
- data/spec/aruba/rake_task_spec.rb +0 -71
- data/spec/chrono_model/adapter/base_spec.rb +0 -157
- data/spec/chrono_model/adapter/ddl_spec.rb +0 -243
- data/spec/chrono_model/adapter/indexes_spec.rb +0 -72
- data/spec/chrono_model/adapter/migrations_spec.rb +0 -312
- data/spec/chrono_model/conversions_spec.rb +0 -43
- data/spec/chrono_model/history_models_spec.rb +0 -32
- data/spec/chrono_model/json_ops_spec.rb +0 -59
- data/spec/chrono_model/time_machine/as_of_spec.rb +0 -188
- data/spec/chrono_model/time_machine/changes_spec.rb +0 -50
- data/spec/chrono_model/time_machine/counter_cache_race_spec.rb +0 -46
- data/spec/chrono_model/time_machine/default_scope_spec.rb +0 -37
- data/spec/chrono_model/time_machine/history_spec.rb +0 -104
- data/spec/chrono_model/time_machine/keep_cool_spec.rb +0 -27
- data/spec/chrono_model/time_machine/manipulations_spec.rb +0 -84
- data/spec/chrono_model/time_machine/model_identification_spec.rb +0 -46
- data/spec/chrono_model/time_machine/sequence_spec.rb +0 -74
- data/spec/chrono_model/time_machine/sti_spec.rb +0 -100
- data/spec/chrono_model/time_machine/time_query_spec.rb +0 -261
- data/spec/chrono_model/time_machine/timeline_spec.rb +0 -63
- data/spec/chrono_model/time_machine/timestamps_spec.rb +0 -43
- data/spec/chrono_model/time_machine/transactions_spec.rb +0 -69
- data/spec/config.travis.yml +0 -5
- data/spec/config.yml.example +0 -9
- data/spec/spec_helper.rb +0 -33
- data/spec/support/adapter/helpers.rb +0 -53
- data/spec/support/adapter/structure.rb +0 -44
- data/spec/support/aruba.rb +0 -44
- data/spec/support/connection.rb +0 -70
- data/spec/support/matchers/base.rb +0 -56
- data/spec/support/matchers/column.rb +0 -99
- data/spec/support/matchers/function.rb +0 -79
- data/spec/support/matchers/index.rb +0 -69
- data/spec/support/matchers/schema.rb +0 -39
- data/spec/support/matchers/table.rb +0 -275
- data/spec/support/time_machine/helpers.rb +0 -47
- data/spec/support/time_machine/structure.rb +0 -111
- data/sql/json_ops.sql +0 -56
- data/sql/uninstall-json_ops.sql +0 -24
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'support/time_machine/helpers'
|
2
|
-
|
3
|
-
# This module contains the test DDL and models used by most of the
|
4
|
-
# +TimeMachine+ specs.
|
5
|
-
#
|
6
|
-
# The models exercise different ActiveRecord features.
|
7
|
-
#
|
8
|
-
# They look candidate of unwinding by their respective specs, however this
|
9
|
-
# test suite aims also at testing within a "real" use case scenario, in which
|
10
|
-
# multiple models are defined and they interact - with their AR side effects,
|
11
|
-
# still ChronoModel should provide the expected results.
|
12
|
-
#
|
13
|
-
# The +$t+ global variable holds a timeline of events that have happened in
|
14
|
-
# the form of .create! and update_attributes, that aim to mimic the most of
|
15
|
-
# AR with the least of the effort. Full coverage exercises are most welcome.
|
16
|
-
#
|
17
|
-
module ChronoTest::TimeMachine
|
18
|
-
include ChronoTest::TimeMachine::Helpers
|
19
|
-
|
20
|
-
# Set up database structure
|
21
|
-
#
|
22
|
-
adapter.create_table 'foos', :temporal => true do |t|
|
23
|
-
t.string :name
|
24
|
-
t.integer :fooity
|
25
|
-
end
|
26
|
-
|
27
|
-
class ::Foo < ActiveRecord::Base
|
28
|
-
include ChronoModel::TimeMachine
|
29
|
-
|
30
|
-
has_many :bars
|
31
|
-
has_many :sub_bars, :through => :bars
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
adapter.create_table 'bars', :temporal => true do |t|
|
36
|
-
t.string :name
|
37
|
-
t.references :foo
|
38
|
-
end
|
39
|
-
|
40
|
-
class ::Bar < ActiveRecord::Base
|
41
|
-
include ChronoModel::TimeMachine
|
42
|
-
|
43
|
-
belongs_to :foo
|
44
|
-
has_many :sub_bars
|
45
|
-
has_one :baz
|
46
|
-
|
47
|
-
has_timeline :with => :foo
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
adapter.create_table 'sub_bars', :temporal => true do |t|
|
52
|
-
t.string :name
|
53
|
-
t.references :bar
|
54
|
-
end
|
55
|
-
|
56
|
-
class ::SubBar < ActiveRecord::Base
|
57
|
-
include ChronoModel::TimeMachine
|
58
|
-
|
59
|
-
belongs_to :bar
|
60
|
-
|
61
|
-
has_timeline :with => :bar
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
adapter.create_table 'bazs' do |t|
|
66
|
-
t.string :name
|
67
|
-
t.references :bar
|
68
|
-
end
|
69
|
-
|
70
|
-
class ::Baz < ActiveRecord::Base
|
71
|
-
include ChronoModel::TimeGate
|
72
|
-
|
73
|
-
belongs_to :bar
|
74
|
-
|
75
|
-
has_timeline :with => :bar
|
76
|
-
end
|
77
|
-
|
78
|
-
# Master timeline, used in multiple specs. It is defined here
|
79
|
-
# as a global variable to be able to be shared across specs.
|
80
|
-
#
|
81
|
-
$t = Struct.new(:foo, :bar, :baz, :subbar, :foos, :bars).new
|
82
|
-
|
83
|
-
# Set up associated records, with intertwined updates
|
84
|
-
#
|
85
|
-
$t.foo = ts_eval { Foo.create! :name => 'foo', :fooity => 1 }
|
86
|
-
ts_eval($t.foo) { update_attributes! :name => 'foo bar' }
|
87
|
-
|
88
|
-
#
|
89
|
-
$t.bar = ts_eval { Bar.create! :name => 'bar', :foo => $t.foo }
|
90
|
-
ts_eval($t.bar) { update_attributes! :name => 'foo bar' }
|
91
|
-
|
92
|
-
#
|
93
|
-
$t.subbar = ts_eval { SubBar.create! :name => 'sub-bar', :bar => $t.bar }
|
94
|
-
ts_eval($t.subbar) { update_attributes! :name => 'bar sub-bar' }
|
95
|
-
|
96
|
-
ts_eval($t.foo) { update_attributes! :name => 'new foo' }
|
97
|
-
|
98
|
-
ts_eval($t.bar) { update_attributes! :name => 'bar bar' }
|
99
|
-
ts_eval($t.bar) { update_attributes! :name => 'new bar' }
|
100
|
-
|
101
|
-
ts_eval($t.subbar) { update_attributes! :name => 'sub-bar sub-bar' }
|
102
|
-
ts_eval($t.subbar) { update_attributes! :name => 'new sub-bar' }
|
103
|
-
|
104
|
-
#
|
105
|
-
$t.foos = Array.new(2) {|i| ts_eval { Foo.create! :name => "foo #{i}" } }
|
106
|
-
$t.bars = Array.new(2) {|i| ts_eval { Bar.create! :name => "bar #{i}", :foo => $t.foos[i] } }
|
107
|
-
|
108
|
-
#
|
109
|
-
$t.baz = Baz.create :name => 'baz', :bar => $t.bar
|
110
|
-
|
111
|
-
end
|
data/sql/json_ops.sql
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
-- This is a naive, unoptimized way of checking two
|
2
|
-
-- JSON objects for equality. It uses python's json
|
3
|
-
-- module to load and re-dump the json object while
|
4
|
-
-- sorting its keys, and then calculates the object
|
5
|
-
-- hash from it.
|
6
|
-
--
|
7
|
-
CREATE OR REPLACE FUNCTION json_hash( a json ) RETURNS INTEGER AS $$
|
8
|
-
import json
|
9
|
-
|
10
|
-
# http://www.isthe.com/chongo/tech/comp/fnv/#FNV-1a
|
11
|
-
def fnv1a(str):
|
12
|
-
hval = 2166136261
|
13
|
-
for s in str:
|
14
|
-
hval = hval ^ ord(s)
|
15
|
-
hval = (hval * 16777619) % (2**32)
|
16
|
-
return hval
|
17
|
-
|
18
|
-
hsh = fnv1a(json.dumps(json.loads(a), sort_keys=True, separators=(',', ':')))
|
19
|
-
return hsh - 2**31
|
20
|
-
|
21
|
-
$$ LANGUAGE plpythonu STRICT IMMUTABLE;
|
22
|
-
|
23
|
-
CREATE OR REPLACE FUNCTION json_eq( a json, b json ) RETURNS BOOLEAN AS $$
|
24
|
-
SELECT json_hash(a) = json_hash(b);
|
25
|
-
$$ LANGUAGE SQL STRICT IMMUTABLE;
|
26
|
-
|
27
|
-
DO $$
|
28
|
-
BEGIN
|
29
|
-
|
30
|
-
CREATE OPERATOR = (
|
31
|
-
LEFTARG = json,
|
32
|
-
RIGHTARG = json,
|
33
|
-
PROCEDURE = json_eq
|
34
|
-
);
|
35
|
-
|
36
|
-
RAISE LOG 'Created JSON equality operator';
|
37
|
-
|
38
|
-
EXCEPTION WHEN duplicate_function THEN
|
39
|
-
RAISE NOTICE 'JSON equality operator already exists, skipping';
|
40
|
-
END;
|
41
|
-
$$ LANGUAGE plpgsql;
|
42
|
-
|
43
|
-
DO $$
|
44
|
-
BEGIN
|
45
|
-
|
46
|
-
CREATE OPERATOR CLASS json_ops
|
47
|
-
DEFAULT FOR TYPE JSON USING hash AS
|
48
|
-
OPERATOR 1 = (json, json),
|
49
|
-
FUNCTION 1 json_hash(json);
|
50
|
-
|
51
|
-
RAISE LOG 'Created JSON hash operator class';
|
52
|
-
|
53
|
-
EXCEPTION WHEN duplicate_object THEN
|
54
|
-
RAISE NOTICE 'JSON hash operator class already exists, skipping';
|
55
|
-
END;
|
56
|
-
$$ LANGUAGE plpgsql;
|
data/sql/uninstall-json_ops.sql
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
DO $$
|
2
|
-
BEGIN
|
3
|
-
|
4
|
-
DROP OPERATOR CLASS json_ops using hash;
|
5
|
-
RAISE LOG 'Dropped JSON hash operator class';
|
6
|
-
|
7
|
-
EXCEPTION WHEN undefined_object THEN
|
8
|
-
RAISE NOTICE 'JSON hash operator class does not exist, skipping';
|
9
|
-
END;
|
10
|
-
$$ LANGUAGE plpgsql;
|
11
|
-
|
12
|
-
DO $$
|
13
|
-
BEGIN
|
14
|
-
|
15
|
-
DROP OPERATOR = ( json, json );
|
16
|
-
RAISE LOG 'Dropped JSON equality operator';
|
17
|
-
|
18
|
-
EXCEPTION WHEN undefined_function THEN
|
19
|
-
RAISE NOTICE 'JSON equality operator does not exist, skipping';
|
20
|
-
END;
|
21
|
-
$$ LANGUAGE plpgsql;
|
22
|
-
|
23
|
-
DROP FUNCTION IF EXISTS json_eq( json, json );
|
24
|
-
DROP FUNCTION IF EXISTS json_hash ( json );
|