empty_eye 0.4.6 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,13 @@
1
- # 0.4.6 / 2012-03-11 / Grady Griffin
1
+ # 0.4.8 / 2012-03-13 / Grady Griffin
2
+
3
+ * readme revisions
4
+ * fixing view manager bug
5
+
6
+ # 0.4.7 / 2012-03-13 / Grady Griffin
7
+
8
+ * readme revision
9
+
10
+ # 0.4.6 / 2012-03-12 / Grady Griffin
2
11
 
3
12
  * tested with sqlite
4
13
  * tested with postgres
data/README.md CHANGED
@@ -27,16 +27,17 @@ this migration tracks view versions and its usage is highly recommended
27
27
  * No mechanism to change mti class table name but that is minor
28
28
  * More complex testing needed to ensure reliability
29
29
  * Uses ARel so should be compatible with ARel supported database that support view; there is support for Oracle and Sql Server adapters but these are not tested
30
- * SchemaDumper support for omitting views with databases other than MySQL is untested
31
30
 
32
31
  Create MTI classes by renaming your base table with the core suffix and wrapping your associations in a mti\_class block
33
32
 
34
33
  Test example from http://techspry.com/ruby_and_rails/multiple-table-inheritance-in-rails-3/ which uses mixins to accomplish MTI:
35
34
 
36
- ActiveRecord::Migration.create_table :restaurants_core, :force => true do |t|
35
+ ActiveRecord::Migration.create_table :restaurants, :force => true do |t|
36
+ t.string :type
37
37
  t.boolean :kids_area
38
38
  t.boolean :wifi
39
- t.integer :food_genre
39
+ t.integer :eating_venue_id
40
+ t.string :food_genre
40
41
  t.datetime :created_at
41
42
  t.datetime :updated_at
42
43
  t.datetime :deleted_at
@@ -79,7 +80,7 @@ For now the convention is to name the base tables with the suffix core as the vi
79
80
 
80
81
  In the background the following association options are used :autosave => true, :validate => true, :dependent => :destroy
81
82
 
82
- MTI associations take the only and except options to limit the inherited columns.
83
+ MTI associations take the :only and :except options to limit the inherited columns.
83
84
 
84
85
  class SmallMechanic < ActiveRecord::Base
85
86
  mti_class :mechanics_core do |t|
@@ -92,14 +93,23 @@ MTI associations take the only and except options to limit the inherited columns
92
93
  has_one :garage, :foreign_key => :mechanic_id, :only => 'specialty'
93
94
  end
94
95
  end
96
+
97
+
98
+ Views are automatically created during class definition.
99
+
100
+ They are managed through Empty Eye View Manager.
95
101
 
96
- Validations are also inherited but only for validations for attributes/columns that are inherited
102
+ The View Manager only rebuilds views when necessary and prevents another app instance from mistakenly rebuilding views during runtime.
97
103
 
98
- Changing or adding these options will have no effect but the MTI would be senseless without them
104
+ Validations are also inherited but only for validations for attributes/columns that are inherited.
105
+
106
+ Only has one associations are supported and always have :autosave => true, :validate => true, :dependent => :destroy options applied.
107
+
108
+ Changing or adding these options will have no effect but the MTI would be senseless without them.
99
109
 
100
110
  If the class does not descend active record the correct table will be used.
101
111
 
102
- If you dont want to use the core suffix convention a table can be specified (see Bar class mti implementation)
112
+ If you dont want to use the core suffix convention a table can be specified (see Bar class mti implementation).
103
113
 
104
114
 
105
115
  1.9.3p0 :005 > Bar
@@ -121,7 +131,67 @@ If you dont want to use the core suffix convention a table can be specified (see
121
131
 
122
132
  1.9.3p0 :013 > Bar.find_by_id(2)
123
133
  => nil
134
+
135
+ Other more complex structures examples:
136
+
137
+ ActiveRecord::Migration.create_table :restaurants, :force => true do |t|
138
+ t.string :type
139
+ t.boolean :kids_area
140
+ t.boolean :wifi
141
+ t.integer :eating_venue_id
142
+ t.string :food_genre
143
+ t.datetime :created_at
144
+ t.datetime :updated_at
145
+ t.datetime :deleted_at
146
+ end
147
+
148
+ ActiveRecord::Migration.create_table :eating_venues_core, :force => true do |t|
149
+ t.string :api_venue_id
150
+ t.string :latitude
151
+ t.string :longitude
152
+ end
153
+
154
+ ActiveRecord::Migration.create_table :businesses, :force => true do |t|
155
+ t.integer :biz_id
156
+ t.string :biz_type
157
+ t.string :name
158
+ t.string :address
159
+ t.string :phone
160
+ end
161
+
162
+ class Business < ActiveRecord::Base
163
+ belongs_to :biz, :polymorphic => true
164
+ end
165
+
166
+ class Restaurant < ActiveRecord::Base
167
+ belongs_to :foursquare_venue
168
+ end
169
+
170
+ class MexicanRestaurant < Restaurant
171
+ mti_class do |t|
172
+ has_one :business, :as => :biz
173
+ end
174
+ end
175
+
176
+ class EatingVenue < ActiveRecord::Base
177
+ mti_class do |t|
178
+ has_one :mexican_restaurant
179
+ end
180
+ end
124
181
 
182
+ Here Restaurant is not an mti class but instead a sti base class. The table name here is just restaurants.
183
+
184
+ MexicanRestaurant inherits from Restaurant therefore no specified primary table is needed; the primary table for MexicanRestaurant is restaurants.
185
+
186
+ MexicanRestaurant inherits the attributes of the Business table.
187
+
188
+ EatingVenue has not specified primary table so Empty Eye uses 'eating\_venues\_core'.
189
+
190
+ Eating Venue is declared as an mti class which inherits the table structure of MexicanRestaurant, an mti class, which in turn is a sti class.
191
+
192
+ Empty Eye only handles multiple table inheritance and not multiple class inheritance.
193
+
194
+ Classes like MexicanRestaurant will inherit methods from Restaurant but not from Business.
125
195
 
126
196
 
127
197
 
@@ -21,6 +21,7 @@ require "empty_eye/shard_association_reflection"
21
21
 
22
22
  require "empty_eye/active_record/base"
23
23
  require "empty_eye/active_record/schema_dumper"
24
+ require "empty_eye/active_record/connection_adapters/abstract_adapter"
24
25
  require "empty_eye/active_record/connection_adapters/abstract_mysql_adapter"
25
26
  require "empty_eye/active_record/connection_adapters/postgresql_adapter"
26
27
  require "empty_eye/active_record/connection_adapters/oci_adapter"
@@ -28,6 +29,7 @@ require "empty_eye/active_record/connection_adapters/oracle_adapter"
28
29
  require "empty_eye/active_record/connection_adapters/oracleenhanced_adapter"
29
30
  require "empty_eye/active_record/connection_adapters/sqlserver_adapter"
30
31
  require "empty_eye/active_record/connection_adapters/sqlite_adapter"
32
+ require "empty_eye/active_record/connection_adapters/sqlite3_adapter"
31
33
 
32
34
  module EmptyEye
33
35
 
@@ -0,0 +1,15 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class AbstractAdapter
4
+
5
+ def ordinary_table_exists?(name)
6
+ tables_without_views.include?(name)
7
+ end
8
+
9
+ def view_exists?(name)
10
+ views.include?(name)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -16,7 +16,7 @@ module ActiveRecord
16
16
 
17
17
  def views(name = nil)
18
18
  query(<<-SQL, 'SCHEMA').map { |row| row[0] }
19
- SELECT tablename
19
+ SELECT viewname
20
20
  FROM pg_views
21
21
  WHERE schemaname = ANY (current_schemas(false))
22
22
  SQL
@@ -0,0 +1,45 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class SQLite3Adapter < SQLiteAdapter
4
+
5
+ def tables(name = 'SCHEMA', table_name = nil) #:nodoc:
6
+ sql = <<-SQL
7
+ SELECT name
8
+ FROM sqlite_master
9
+ WHERE (type = 'table' OR type = 'view') AND NOT name = 'sqlite_sequence'
10
+ SQL
11
+ sql << " AND name = #{quote_table_name(table_name)}" if table_name
12
+
13
+ exec_query(sql, name).map do |row|
14
+ row['name']
15
+ end
16
+ end
17
+
18
+ def tables_without_views(name = 'SCHEMA', table_name = nil) #:nodoc:
19
+ sql = <<-SQL
20
+ SELECT name
21
+ FROM sqlite_master
22
+ WHERE type = 'table' AND NOT name = 'sqlite_sequence'
23
+ SQL
24
+ sql << " AND name = #{quote_table_name(table_name)}" if table_name
25
+
26
+ exec_query(sql, name).map do |row|
27
+ row['name']
28
+ end
29
+ end
30
+
31
+ def views(name = 'SCHEMA', table_name = nil) #:nodoc:
32
+ sql = <<-SQL
33
+ SELECT name
34
+ FROM sqlite_master
35
+ WHERE type = 'view' AND NOT name = 'sqlite_sequence'
36
+ SQL
37
+ sql << " AND name = #{quote_table_name(table_name)}" if table_name
38
+
39
+ exec_query(sql, name).map do |row|
40
+ row['name']
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -2,7 +2,7 @@ module EmptyEye
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 6
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -38,12 +38,8 @@ module EmptyEye
38
38
  self.class.connection.execute(sql)
39
39
  end
40
40
 
41
- def table_exists?
42
- self.class.connection.table_exists?(view_name)
43
- end
44
-
45
41
  def ordinary_table_exists?
46
- self.class.connection.tables_without_views.include?(view_name)
42
+ self.class.connection.ordinary_table_exists?(view_name)
47
43
  end
48
44
 
49
45
  def compute_version
@@ -55,7 +51,7 @@ module EmptyEye
55
51
  end
56
52
 
57
53
  def view_exists?
58
- table_exists? and !ordinary_table_exists?
54
+ self.connection.view_exists?(view_name)
59
55
  end
60
56
 
61
57
  def create_view?
@@ -28,6 +28,13 @@ def exec_sql(sql)
28
28
  ActiveRecord::Base.connection.execute sql
29
29
  end
30
30
 
31
+ begin
32
+ ActiveRecord::Base.connection.views.each do |name|
33
+ puts name
34
+ EmptyEye::ViewManager.drop_view(name)
35
+ end
36
+ end until ActiveRecord::Base.connection.views.empty?
37
+
31
38
  ActiveRecord::Migration.create_table :restaurants, :force => true do |t|
32
39
  t.string :type
33
40
  t.boolean :kids_area
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: empty_eye
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 6
10
- version: 0.4.6
9
+ - 8
10
+ version: 0.4.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - thegboat
@@ -125,11 +125,13 @@ files:
125
125
  - empty_eye.gemspec
126
126
  - lib/empty_eye.rb
127
127
  - lib/empty_eye/active_record/base.rb
128
+ - lib/empty_eye/active_record/connection_adapters/abstract_adapter.rb
128
129
  - lib/empty_eye/active_record/connection_adapters/abstract_mysql_adapter.rb
129
130
  - lib/empty_eye/active_record/connection_adapters/oci_adapter.rb
130
131
  - lib/empty_eye/active_record/connection_adapters/oracle_adapter.rb
131
132
  - lib/empty_eye/active_record/connection_adapters/oracleenhanced_adapter.rb
132
133
  - lib/empty_eye/active_record/connection_adapters/postgresql_adapter.rb
134
+ - lib/empty_eye/active_record/connection_adapters/sqlite3_adapter.rb
133
135
  - lib/empty_eye/active_record/connection_adapters/sqlite_adapter.rb
134
136
  - lib/empty_eye/active_record/connection_adapters/sqlserver_adapter.rb
135
137
  - lib/empty_eye/active_record/schema_dumper.rb