activerecord-oracle_enhanced-adapter 1.5.6 → 1.6.0.beta1

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/History.md +87 -0
  4. data/README.md +271 -174
  5. data/VERSION +1 -1
  6. data/activerecord-oracle_enhanced-adapter.gemspec +26 -22
  7. data/lib/active_record/connection_adapters/{oracle_enhanced_column.rb → oracle_enhanced/column.rb} +14 -63
  8. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +65 -0
  9. data/lib/active_record/connection_adapters/{oracle_enhanced_connection.rb → oracle_enhanced/connection.rb} +2 -2
  10. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +347 -0
  11. data/lib/active_record/connection_adapters/{oracle_enhanced_cpk.rb → oracle_enhanced/cpk.rb} +0 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +257 -0
  13. data/lib/active_record/connection_adapters/{oracle_enhanced_database_tasks.rb → oracle_enhanced/database_tasks.rb} +0 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +40 -0
  15. data/lib/active_record/connection_adapters/{oracle_enhanced_jdbc_connection.rb → oracle_enhanced/jdbc_connection.rb} +0 -0
  16. data/lib/active_record/connection_adapters/{oracle_enhanced_oci_connection.rb → oracle_enhanced/oci_connection.rb} +0 -0
  17. data/lib/active_record/connection_adapters/{oracle_enhanced_procedures.rb → oracle_enhanced/procedures.rb} +0 -0
  18. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_creation.rb → oracle_enhanced/schema_creation.rb} +17 -16
  19. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +92 -0
  20. data/lib/active_record/connection_adapters/{oracle_enhanced_schema_dumper.rb → oracle_enhanced/schema_dumper.rb} +4 -32
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +543 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +65 -0
  23. data/lib/active_record/connection_adapters/{oracle_enhanced_structure_dump.rb → oracle_enhanced/structure_dump.rb} +26 -4
  24. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +159 -66
  26. data/lib/active_record/oracle_enhanced/type/integer.rb +13 -0
  27. data/lib/active_record/oracle_enhanced/type/raw.rb +13 -0
  28. data/lib/active_record/oracle_enhanced/type/timestamp.rb +11 -0
  29. data/lib/activerecord-oracle_enhanced-adapter.rb +1 -1
  30. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +6 -31
  31. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +1 -1
  32. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +2 -2
  33. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +2 -2
  34. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +63 -63
  35. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +1 -1
  36. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +7 -13
  37. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +21 -175
  38. data/spec/spec_config.yaml.template +10 -0
  39. data/spec/spec_helper.rb +21 -10
  40. metadata +29 -25
  41. data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +0 -77
  42. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -350
  43. data/lib/active_record/connection_adapters/oracle_enhanced_database_statements.rb +0 -262
  44. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -45
  45. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -197
  46. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -450
  47. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
  48. data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
@@ -1,258 +0,0 @@
1
- require 'digest/sha1'
2
-
3
- module ActiveRecord
4
- module ConnectionAdapters
5
- module OracleEnhancedSchemaStatementsExt
6
- def supports_foreign_keys? #:nodoc:
7
- true
8
- end
9
-
10
- # Create primary key trigger (so that you can skip primary key value in INSERT statement).
11
- # By default trigger name will be "table_name_pkt", you can override the name with
12
- # :trigger_name option (but it is not recommended to override it as then this trigger will
13
- # not be detected by ActiveRecord model and it will still do prefetching of sequence value).
14
- #
15
- # add_primary_key_trigger :users
16
- #
17
- # You can also create primary key trigger using +create_table+ with :primary_key_trigger
18
- # option:
19
- #
20
- # create_table :users, :primary_key_trigger => true do |t|
21
- # # ...
22
- # end
23
- #
24
- def add_primary_key_trigger(table_name, options={})
25
- # call the same private method that is used for create_table :primary_key_trigger => true
26
- create_primary_key_trigger(table_name, options)
27
- end
28
-
29
- # Adds a new foreign key to the +from_table+, referencing the primary key of +to_table+
30
- # (syntax and partial implementation taken from http://github.com/matthuhiggins/foreigner)
31
- #
32
- # The foreign key will be named after the from and to tables unless you pass
33
- # <tt>:name</tt> as an option.
34
- #
35
- # === Examples
36
- # ==== Creating a foreign key
37
- # add_foreign_key(:comments, :posts)
38
- # generates
39
- # ALTER TABLE comments ADD CONSTRAINT
40
- # comments_post_id_fk FOREIGN KEY (post_id) REFERENCES posts (id)
41
- #
42
- # ==== Creating a named foreign key
43
- # add_foreign_key(:comments, :posts, :name => 'comments_belongs_to_posts')
44
- # generates
45
- # ALTER TABLE comments ADD CONSTRAINT
46
- # comments_belongs_to_posts FOREIGN KEY (post_id) REFERENCES posts (id)
47
- #
48
- # ==== Creating a cascading foreign_key on a custom column
49
- # add_foreign_key(:people, :people, :column => 'best_friend_id', :dependent => :nullify)
50
- # generates
51
- # ALTER TABLE people ADD CONSTRAINT
52
- # people_best_friend_id_fk FOREIGN KEY (best_friend_id) REFERENCES people (id)
53
- # ON DELETE SET NULL
54
- #
55
- # ==== Creating a composite foreign key
56
- # add_foreign_key(:comments, :posts, :columns => ['post_id', 'author_id'], :name => 'comments_post_fk')
57
- # generates
58
- # ALTER TABLE comments ADD CONSTRAINT
59
- # comments_post_fk FOREIGN KEY (post_id, author_id) REFERENCES posts (post_id, author_id)
60
- #
61
- # === Supported options
62
- # [:column]
63
- # Specify the column name on the from_table that references the to_table. By default this is guessed
64
- # to be the singular name of the to_table with "_id" suffixed. So a to_table of :posts will use "post_id"
65
- # as the default <tt>:column</tt>.
66
- # [:columns]
67
- # An array of column names when defining composite foreign keys. An alias of <tt>:column</tt> provided for improved readability.
68
- # [:primary_key]
69
- # Specify the column name on the to_table that is referenced by this foreign key. By default this is
70
- # assumed to be "id". Ignored when defining composite foreign keys.
71
- # [:name]
72
- # Specify the name of the foreign key constraint. This defaults to use from_table and foreign key column.
73
- # [:dependent]
74
- # If set to <tt>:delete</tt>, the associated records in from_table are deleted when records in to_table table are deleted.
75
- # If set to <tt>:nullify</tt>, the foreign key column is set to +NULL+.
76
- def add_foreign_key(from_table, to_table, options = {})
77
- columns = options[:column] || options[:columns] || "#{to_table.to_s.singularize}_id"
78
- constraint_name = foreign_key_constraint_name(from_table, columns, options)
79
- sql = "ALTER TABLE #{quote_table_name(from_table)} ADD CONSTRAINT #{quote_column_name(constraint_name)} "
80
- sql << foreign_key_definition(to_table, options)
81
- execute sql
82
- end
83
-
84
- def foreign_key_definition(to_table, options = {}) #:nodoc:
85
- columns = Array(options[:column] || options[:columns])
86
-
87
- if columns.size > 1
88
- # composite foreign key
89
- columns_sql = columns.map {|c| quote_column_name(c)}.join(',')
90
- references = options[:references] || columns
91
- references_sql = references.map {|c| quote_column_name(c)}.join(',')
92
- else
93
- columns_sql = quote_column_name(columns.first || "#{to_table.to_s.singularize}_id")
94
- references = options[:references] ? options[:references].first : nil
95
- references_sql = quote_column_name(options[:primary_key] || references || "id")
96
- end
97
-
98
- table_name = ActiveRecord::Migrator.proper_table_name(to_table)
99
-
100
- sql = "FOREIGN KEY (#{columns_sql}) REFERENCES #{quote_table_name(table_name)}(#{references_sql})"
101
-
102
- case options[:dependent]
103
- when :nullify
104
- sql << " ON DELETE SET NULL"
105
- when :delete
106
- sql << " ON DELETE CASCADE"
107
- end
108
- sql
109
- end
110
-
111
- # Remove the given foreign key from the table.
112
- #
113
- # ===== Examples
114
- # ====== Remove the suppliers_company_id_fk in the suppliers table.
115
- # remove_foreign_key :suppliers, :companies
116
- # ====== Remove the foreign key named accounts_branch_id_fk in the accounts table.
117
- # remove_foreign_key :accounts, :column => :branch_id
118
- # ====== Remove the foreign key named party_foreign_key in the accounts table.
119
- # remove_foreign_key :accounts, :name => :party_foreign_key
120
- def remove_foreign_key(from_table, options)
121
- if Hash === options
122
- constraint_name = foreign_key_constraint_name(from_table, options[:column], options)
123
- else
124
- constraint_name = foreign_key_constraint_name(from_table, "#{options.to_s.singularize}_id")
125
- end
126
- execute "ALTER TABLE #{quote_table_name(from_table)} DROP CONSTRAINT #{quote_column_name(constraint_name)}"
127
- end
128
-
129
- private
130
-
131
- def foreign_key_constraint_name(table_name, columns, options = {})
132
- columns = Array(columns)
133
- constraint_name = original_name = options[:name] || "#{table_name}_#{columns.join('_')}_fk"
134
-
135
- return constraint_name if constraint_name.length <= OracleEnhancedAdapter::IDENTIFIER_MAX_LENGTH
136
-
137
- # leave just first three letters from each word
138
- constraint_name = constraint_name.split('_').map{|w| w[0,3]}.join('_')
139
- # generate unique name using hash function
140
- if constraint_name.length > OracleEnhancedAdapter::IDENTIFIER_MAX_LENGTH
141
- constraint_name = 'c'+Digest::SHA1.hexdigest(original_name)[0,OracleEnhancedAdapter::IDENTIFIER_MAX_LENGTH-1]
142
- end
143
- @logger.warn "#{adapter_name} shortened foreign key constraint name #{original_name} to #{constraint_name}" if @logger
144
- constraint_name
145
- end
146
-
147
-
148
- public
149
-
150
- # get table foreign keys for schema dump
151
- def foreign_keys(table_name) #:nodoc:
152
- (owner, desc_table_name, db_link) = @connection.describe(table_name)
153
-
154
- fk_info = select_all(<<-SQL, 'Foreign Keys')
155
- SELECT r.table_name to_table
156
- ,rc.column_name references_column
157
- ,cc.column_name
158
- ,c.constraint_name name
159
- ,c.delete_rule
160
- FROM user_constraints#{db_link} c, user_cons_columns#{db_link} cc,
161
- user_constraints#{db_link} r, user_cons_columns#{db_link} rc
162
- WHERE c.owner = '#{owner}'
163
- AND c.table_name = '#{desc_table_name}'
164
- AND c.constraint_type = 'R'
165
- AND cc.owner = c.owner
166
- AND cc.constraint_name = c.constraint_name
167
- AND r.constraint_name = c.r_constraint_name
168
- AND r.owner = c.owner
169
- AND rc.owner = r.owner
170
- AND rc.constraint_name = r.constraint_name
171
- AND rc.position = cc.position
172
- ORDER BY name, to_table, column_name, references_column
173
- SQL
174
-
175
- fks = {}
176
-
177
- fk_info.map do |row|
178
- name = oracle_downcase(row['name'])
179
- fks[name] ||= { :columns => [], :to_table => oracle_downcase(row['to_table']), :references => [] }
180
- fks[name][:columns] << oracle_downcase(row['column_name'])
181
- fks[name][:references] << oracle_downcase(row['references_column'])
182
- case row['delete_rule']
183
- when 'CASCADE'
184
- fks[name][:dependent] = :delete
185
- when 'SET NULL'
186
- fks[name][:dependent] = :nullify
187
- end
188
- end
189
-
190
- fks.map do |k, v|
191
- options = {:name => k, :columns => v[:columns], :references => v[:references], :dependent => v[:dependent]}
192
- OracleEnhancedForeignKeyDefinition.new(table_name, v[:to_table], options)
193
- end
194
- end
195
-
196
- # REFERENTIAL INTEGRITY ====================================
197
-
198
- def disable_referential_integrity(&block) #:nodoc:
199
- sql_constraints = <<-SQL
200
- SELECT constraint_name, owner, table_name
201
- FROM user_constraints
202
- WHERE constraint_type = 'R'
203
- AND status = 'ENABLED'
204
- SQL
205
- old_constraints = select_all(sql_constraints)
206
- begin
207
- old_constraints.each do |constraint|
208
- execute "ALTER TABLE #{constraint["table_name"]} DISABLE CONSTRAINT #{constraint["constraint_name"]}"
209
- end
210
- yield
211
- ensure
212
- old_constraints.each do |constraint|
213
- execute "ALTER TABLE #{constraint["table_name"]} ENABLE CONSTRAINT #{constraint["constraint_name"]}"
214
- end
215
- end
216
- end
217
-
218
- # Add synonym to existing table or view or sequence. Can be used to create local synonym to
219
- # remote table in other schema or in other database
220
- # Examples:
221
- #
222
- # add_synonym :posts, "blog.posts"
223
- # add_synonym :posts_seq, "blog.posts_seq"
224
- # add_synonym :employees, "hr.employees@dblink", :force => true
225
- #
226
- def add_synonym(name, table_name, options = {})
227
- sql = "CREATE"
228
- if options[:force] == true
229
- sql << " OR REPLACE"
230
- end
231
- sql << " SYNONYM #{quote_table_name(name)} FOR #{quote_table_name(table_name)}"
232
- execute sql
233
- end
234
-
235
- # Remove existing synonym to table or view or sequence
236
- # Example:
237
- #
238
- # remove_synonym :posts, "blog.posts"
239
- #
240
- def remove_synonym(name)
241
- execute "DROP SYNONYM #{quote_table_name(name)}"
242
- end
243
-
244
- # get synonyms for schema dump
245
- def synonyms #:nodoc:
246
- select_all("SELECT synonym_name, table_owner, table_name, db_link FROM user_synonyms").collect do |row|
247
- OracleEnhancedSynonymDefinition.new(oracle_downcase(row['synonym_name']),
248
- oracle_downcase(row['table_owner']), oracle_downcase(row['table_name']), oracle_downcase(row['db_link']))
249
- end
250
- end
251
-
252
- end
253
- end
254
- end
255
-
256
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
257
- include ActiveRecord::ConnectionAdapters::OracleEnhancedSchemaStatementsExt
258
- end
@@ -1 +0,0 @@
1
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::VERSION = File.read(File.expand_path('../../../../VERSION', __FILE__)).chomp