active_record-mti 0.0.5 → 0.0.6
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/Gemfile +3 -0
- data/Gemfile.lock +80 -0
- data/active_record-mti.gemspec +6 -2
- data/lib/active_record/mti.rb +18 -2
- data/lib/active_record/mti/connection_adapters/postgresql/schema_statements.rb +5 -3
- data/lib/active_record/mti/inheritance.rb +4 -0
- data/lib/active_record/mti/querying.rb +7 -0
- data/lib/active_record/mti/railtie.rb +6 -12
- data/lib/active_record/mti/schema_dumper.rb +5 -2
- data/lib/active_record/mti/version.rb +1 -1
- metadata +49 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f561f8c3e6dff9e4c46e297bb68cf4e00d5d5891
|
4
|
+
data.tar.gz: 44bf123a8420156b88e21e5e9f1d9c39e4379a8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be36facecf13fe566b71bab1825e9d7ef0311b85b48bb34456476d649cad0a0adcb3877f2f25afac7ec2755149ef0a258aac9d9f69410f55aa537c60efbfc227
|
7
|
+
data.tar.gz: aff8249f8050fe264785718e2ce773132e64b0153d50524bae003f6dad83c5f98ce74d5f1ed155b0fd197fc6beead571a6f2b020631253f648214dee74bd21c0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
active_record-mti (0.0.6)
|
5
|
+
activerecord (~> 4.1, > 4.1)
|
6
|
+
activesupport (~> 4.1, > 4.1)
|
7
|
+
pg (~> 0)
|
8
|
+
railties (~> 4.1, > 4.1)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
actionpack (4.2.8)
|
14
|
+
actionview (= 4.2.8)
|
15
|
+
activesupport (= 4.2.8)
|
16
|
+
rack (~> 1.6)
|
17
|
+
rack-test (~> 0.6.2)
|
18
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
19
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
20
|
+
actionview (4.2.8)
|
21
|
+
activesupport (= 4.2.8)
|
22
|
+
builder (~> 3.1)
|
23
|
+
erubis (~> 2.7.0)
|
24
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
25
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
26
|
+
activemodel (4.2.8)
|
27
|
+
activesupport (= 4.2.8)
|
28
|
+
builder (~> 3.1)
|
29
|
+
activerecord (4.2.8)
|
30
|
+
activemodel (= 4.2.8)
|
31
|
+
activesupport (= 4.2.8)
|
32
|
+
arel (~> 6.0)
|
33
|
+
activesupport (4.2.8)
|
34
|
+
i18n (~> 0.7)
|
35
|
+
minitest (~> 5.1)
|
36
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
37
|
+
tzinfo (~> 1.1)
|
38
|
+
arel (6.0.4)
|
39
|
+
builder (3.2.3)
|
40
|
+
erubis (2.7.0)
|
41
|
+
i18n (0.8.1)
|
42
|
+
loofah (2.0.3)
|
43
|
+
nokogiri (>= 1.5.9)
|
44
|
+
mini_portile2 (2.1.0)
|
45
|
+
minitest (5.10.1)
|
46
|
+
nokogiri (1.7.1)
|
47
|
+
mini_portile2 (~> 2.1.0)
|
48
|
+
pg (0.20.0)
|
49
|
+
rack (1.6.5)
|
50
|
+
rack-test (0.6.3)
|
51
|
+
rack (>= 1.0)
|
52
|
+
rails-deprecated_sanitizer (1.0.3)
|
53
|
+
activesupport (>= 4.2.0.alpha)
|
54
|
+
rails-dom-testing (1.0.8)
|
55
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
56
|
+
nokogiri (~> 1.6)
|
57
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
58
|
+
rails-html-sanitizer (1.0.3)
|
59
|
+
loofah (~> 2.0)
|
60
|
+
railties (4.2.8)
|
61
|
+
actionpack (= 4.2.8)
|
62
|
+
activesupport (= 4.2.8)
|
63
|
+
rake (>= 0.8.7)
|
64
|
+
thor (>= 0.18.1, < 2.0)
|
65
|
+
rake (0.9.6)
|
66
|
+
thor (0.19.4)
|
67
|
+
thread_safe (0.3.6)
|
68
|
+
tzinfo (1.2.3)
|
69
|
+
thread_safe (~> 0.1)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
ruby
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
active_record-mti!
|
76
|
+
bundler (~> 1.6)
|
77
|
+
rake (~> 0)
|
78
|
+
|
79
|
+
BUNDLED WITH
|
80
|
+
1.13.6
|
data/active_record-mti.gemspec
CHANGED
@@ -20,7 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
22
|
spec.add_development_dependency 'rake', '~> 0'
|
23
|
-
|
24
|
-
spec.
|
23
|
+
|
24
|
+
spec.add_dependency 'pg', '~> 0'
|
25
|
+
|
26
|
+
spec.add_dependency 'activerecord', '~> 4.1', '> 4.1'
|
27
|
+
spec.add_dependency 'railties', '~> 4.1', '> 4.1'
|
28
|
+
spec.add_dependency 'activesupport', '~> 4.1', '> 4.1'
|
25
29
|
|
26
30
|
end
|
data/lib/active_record/mti.rb
CHANGED
@@ -1,8 +1,24 @@
|
|
1
|
-
require
|
2
|
-
require 'active_record/mti/railtie'
|
1
|
+
require 'active_record/mti/version'
|
2
|
+
require 'active_record/mti/railtie'
|
3
|
+
require 'active_record'
|
4
|
+
require 'active_record/connection_handling'
|
5
|
+
require 'active_record/mti/schema_dumper'
|
6
|
+
require 'active_record/mti/inheritance'
|
7
|
+
require 'active_record/mti/query_methods'
|
8
|
+
require 'active_record/mti/calculations'
|
9
|
+
require 'active_record/mti/connection_adapters/postgresql/schema_statements'
|
3
10
|
|
4
11
|
module ActiveRecord
|
5
12
|
module MTI
|
6
13
|
# Your code goes here...
|
14
|
+
def self.load
|
15
|
+
puts "ActiveRecord::MTI loaded"
|
16
|
+
::ActiveRecord::Base.send :include, Inheritance
|
17
|
+
::ActiveRecord::Relation.send :include, QueryMethods
|
18
|
+
::ActiveRecord::Relation.send :include, ActiveRecord::MTI::Calculations
|
19
|
+
|
20
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :include, ConnectionAdapters::PostgreSQL::SchemaStatements
|
21
|
+
::ActiveRecord::SchemaDumper.send :include, ActiveRecord::MTI::SchemaDumper
|
22
|
+
end
|
7
23
|
end
|
8
24
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module MTI
|
3
5
|
module ConnectionAdapters
|
@@ -22,11 +24,11 @@ module ActiveRecord
|
|
22
24
|
if schema = options.delete(:schema)
|
23
25
|
# If we specify a schema then we only create it if it doesn't exist
|
24
26
|
# and we only force create it if only the specific schema is in the search path
|
25
|
-
table_name = "#{schema}
|
27
|
+
table_name = %Q("#{schema}"."#{table_name}")
|
26
28
|
end
|
27
29
|
|
28
30
|
if parent_table = options.delete(:inherits)
|
29
|
-
options[:options] = [
|
31
|
+
options[:options] = [%Q(INHERITS ("#{parent_table}")), options[:options]].compact.join
|
30
32
|
end
|
31
33
|
|
32
34
|
td = create_table_definition table_name, options[:temporary], options[:options], options[:as]
|
@@ -58,7 +60,7 @@ module ActiveRecord
|
|
58
60
|
|
59
61
|
if parent_table
|
60
62
|
parent_table_primary_key = primary_key(parent_table)
|
61
|
-
execute
|
63
|
+
execute %Q(ALTER TABLE "#{table_name}" ADD PRIMARY KEY ("#{parent_table_primary_key}"))
|
62
64
|
indexes(parent_table).each do |index|
|
63
65
|
add_index table_name, index.columns, :unique => index.unique
|
64
66
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
# == Multi table inheritance
|
3
5
|
#
|
@@ -57,6 +59,8 @@ module ActiveRecord
|
|
57
59
|
# Search descendants for one who's table_name is equal to the returned tableoid.
|
58
60
|
# This indicates the class of the record
|
59
61
|
def find_mti_class(record)
|
62
|
+
record['tableoid'].classify.constantize
|
63
|
+
rescue NameError => e
|
60
64
|
descendants.find(Proc.new{ self }) { |d| d.table_name == record['tableoid'] }
|
61
65
|
end
|
62
66
|
|
@@ -1,19 +1,13 @@
|
|
1
|
-
require '
|
2
|
-
require 'active_record/mti/inheritance'
|
3
|
-
require 'active_record/mti/query_methods'
|
4
|
-
require 'active_record/mti/calculations'
|
5
|
-
require 'active_record/mti/connection_adapters/postgresql/schema_statements'
|
1
|
+
require 'rails/railtie'
|
6
2
|
|
7
3
|
module ActiveRecord
|
8
4
|
module MTI
|
9
5
|
class Railtie < Rails::Railtie
|
10
|
-
initializer 'active_record-mti.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :include, ConnectionAdapters::PostgreSQL::SchemaStatements
|
16
|
-
::ActiveRecord::SchemaDumper.send :include, ActiveRecord::MTI::SchemaDumper
|
6
|
+
initializer 'active_record-mti.load' do |_app|
|
7
|
+
puts "ActiveRecord::MTI railtie initializer"
|
8
|
+
ActiveSupport.on_load(:active_record) do
|
9
|
+
ActiveRecord::MTI.load
|
10
|
+
end
|
17
11
|
end
|
18
12
|
end
|
19
13
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
1
3
|
# Modified SchemaDumper that knows how to dump
|
2
4
|
# inherited tables. Key is that we have to dump parent
|
3
5
|
# tables before we dump child tables (of course).
|
@@ -28,6 +30,7 @@ module ActiveRecord
|
|
28
30
|
# schema in the search path (not including the $user schema)
|
29
31
|
def table(table, stream)
|
30
32
|
return if already_dumped?(table)
|
33
|
+
|
31
34
|
if parent_table = @connection.parent_table(table)
|
32
35
|
table(parent_table, stream)
|
33
36
|
parent_column_names = @connection.columns(parent_table).map(&:name)
|
@@ -42,12 +45,12 @@ module ActiveRecord
|
|
42
45
|
|
43
46
|
tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}"
|
44
47
|
if parent_table
|
45
|
-
tbl.print %Q(, inherits:
|
48
|
+
tbl.print %Q(, inherits: '#{parent_table}')
|
46
49
|
else
|
47
50
|
pkcol = columns.detect { |c| c.name == pk }
|
48
51
|
if pkcol
|
49
52
|
if pk != 'id'
|
50
|
-
tbl.print %Q(, primary_key:
|
53
|
+
tbl.print %Q(, primary_key: '#{pk}')
|
51
54
|
elsif pkcol.sql_type == 'bigint'
|
52
55
|
tbl.print ", id: :bigserial"
|
53
56
|
elsif pkcol.sql_type == 'uuid'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-mti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Stevens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,7 +39,21 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pg
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
@@ -59,19 +73,45 @@ dependencies:
|
|
59
73
|
- !ruby/object:Gem::Version
|
60
74
|
version: '4.1'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
76
|
+
name: railties
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
64
78
|
requirements:
|
65
79
|
- - "~>"
|
66
80
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
81
|
+
version: '4.1'
|
82
|
+
- - ">"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '4.1'
|
68
85
|
type: :runtime
|
69
86
|
prerelease: false
|
70
87
|
version_requirements: !ruby/object:Gem::Requirement
|
71
88
|
requirements:
|
72
89
|
- - "~>"
|
73
90
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
91
|
+
version: '4.1'
|
92
|
+
- - ">"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '4.1'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: activesupport
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '4.1'
|
102
|
+
- - ">"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '4.1'
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '4.1'
|
112
|
+
- - ">"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '4.1'
|
75
115
|
description: Allows use of native inherited tables in PostgreSQL
|
76
116
|
email:
|
77
117
|
- dale@twilightcoders.net
|
@@ -80,6 +120,8 @@ extensions: []
|
|
80
120
|
extra_rdoc_files: []
|
81
121
|
files:
|
82
122
|
- ".gitignore"
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
83
125
|
- LICENSE.txt
|
84
126
|
- README.md
|
85
127
|
- Rakefile
|
@@ -89,6 +131,7 @@ files:
|
|
89
131
|
- lib/active_record/mti/connection_adapters/postgresql/schema_statements.rb
|
90
132
|
- lib/active_record/mti/inheritance.rb
|
91
133
|
- lib/active_record/mti/query_methods.rb
|
134
|
+
- lib/active_record/mti/querying.rb
|
92
135
|
- lib/active_record/mti/railtie.rb
|
93
136
|
- lib/active_record/mti/schema_dumper.rb
|
94
137
|
- lib/active_record/mti/version.rb
|