advertnet 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/LICENSE +674 -0
  2. data/README +257 -0
  3. data/Rakefile +10 -0
  4. data/app/controllers/application.rb +40 -0
  5. data/app/controllers/container_controller.rb +83 -0
  6. data/app/controllers/content_controller.rb +61 -0
  7. data/app/controllers/furnitures_controller.rb +87 -0
  8. data/app/controllers/networks_controller.rb +269 -0
  9. data/app/controllers/objects_in_world_controller.rb +27 -0
  10. data/app/controllers/panels_controller.rb +186 -0
  11. data/app/helpers/application_helper.rb +31 -0
  12. data/app/helpers/container_helper.rb +2 -0
  13. data/app/helpers/content_helper.rb +2 -0
  14. data/app/helpers/furnitures_helper.rb +2 -0
  15. data/app/helpers/network_helper.rb +2 -0
  16. data/app/helpers/networks_helper.rb +2 -0
  17. data/app/helpers/objects_in_world_helper.rb +2 -0
  18. data/app/helpers/panels_helper.rb +2 -0
  19. data/app/models/container.rb +51 -0
  20. data/app/models/furniture.rb +60 -0
  21. data/app/models/mailer.rb +22 -0
  22. data/app/models/network.rb +38 -0
  23. data/app/models/object_in_world.rb +60 -0
  24. data/app/models/object_off_world.rb +77 -0
  25. data/app/models/panel.rb +136 -0
  26. data/app/models/panel_revision.rb +108 -0
  27. data/app/views/container/list.rhtml +27 -0
  28. data/app/views/container/show.rhtml +8 -0
  29. data/app/views/content/_form.rhtml +12 -0
  30. data/app/views/content/edit.rhtml +8 -0
  31. data/app/views/content/list.rhtml +26 -0
  32. data/app/views/content/new.rhtml +8 -0
  33. data/app/views/furnitures/list.rhtml +51 -0
  34. data/app/views/furnitures/show.rhtml +7 -0
  35. data/app/views/layouts/default.rhtml +30 -0
  36. data/app/views/mailer/avtouch.rhtml +1 -0
  37. data/app/views/networks/_form.rhtml +11 -0
  38. data/app/views/networks/_parameters_form.rhtml +8 -0
  39. data/app/views/networks/edit.rhtml +9 -0
  40. data/app/views/networks/list.rhtml +25 -0
  41. data/app/views/networks/new.rhtml +8 -0
  42. data/app/views/networks/show.rhtml +72 -0
  43. data/app/views/networks/show_parameters_form.rjs +5 -0
  44. data/app/views/objects_in_world/list.rhtml +30 -0
  45. data/app/views/objects_in_world/show.rhtml +8 -0
  46. data/app/views/panels/list.rhtml +48 -0
  47. data/app/views/panels/show.rhtml +8 -0
  48. data/bin/advertnet-install +144 -0
  49. data/config/boot.rb +45 -0
  50. data/config/database.yml.default +43 -0
  51. data/config/environment.rb +67 -0
  52. data/config/environments/development.rb +21 -0
  53. data/config/environments/production.rb +21 -0
  54. data/config/environments/test.rb +19 -0
  55. data/config/routes.rb +23 -0
  56. data/db/migrate/001_create_networks.rb +14 -0
  57. data/db/migrate/002_create_furnitures.rb +17 -0
  58. data/db/migrate/003_create_containers.rb +16 -0
  59. data/db/migrate/004_create_objects_in_world.rb +16 -0
  60. data/db/migrate/005_create_objects_off_world.rb +16 -0
  61. data/db/migrate/006_create_panels.rb +17 -0
  62. data/db/migrate/007_join_objects_in_world_panels.rb +17 -0
  63. data/db/migrate/008_join_objects_off_world_panels.rb +17 -0
  64. data/db/migrate/009_add_sessions.rb +19 -0
  65. data/db/migrate/010_add_or_rename_fields.rb +25 -0
  66. data/db/migrate/011_move_texture_to_object_in_world.rb +25 -0
  67. data/db/migrate/012_add_permanent_furniture_id.rb +18 -0
  68. data/db/migrate/013_create_panel_revisions.rb +42 -0
  69. data/db/schema.rb +102 -0
  70. data/doc/README_FOR_APP +108 -0
  71. data/lib/advertnet.rb +13 -0
  72. data/lib/second_life_validators.rb +89 -0
  73. data/lib/tasks/documentation.rake +16 -0
  74. data/lib/tasks/extract_fixtures.rake +23 -0
  75. data/lib/tasks/load_exported_fixtures.rake +14 -0
  76. data/public/404.html +30 -0
  77. data/public/500.html +30 -0
  78. data/public/dispatch.cgi +10 -0
  79. data/public/dispatch.fcgi +24 -0
  80. data/public/dispatch.rb +10 -0
  81. data/public/favicon.ico +0 -0
  82. data/public/images/rails.png +0 -0
  83. data/public/javascripts/application.js +2 -0
  84. data/public/javascripts/controls.js +833 -0
  85. data/public/javascripts/dragdrop.js +942 -0
  86. data/public/javascripts/effects.js +1088 -0
  87. data/public/javascripts/prototype.js +2515 -0
  88. data/public/robots.txt +1 -0
  89. data/public/stylesheets/application.css +25 -0
  90. data/public/stylesheets/scaffold.css +74 -0
  91. data/script/about +3 -0
  92. data/script/breakpointer +3 -0
  93. data/script/console +3 -0
  94. data/script/destroy +3 -0
  95. data/script/generate +3 -0
  96. data/script/performance/benchmarker +3 -0
  97. data/script/performance/profiler +3 -0
  98. data/script/plugin +3 -0
  99. data/script/process/inspector +3 -0
  100. data/script/process/reaper +3 -0
  101. data/script/process/spawner +3 -0
  102. data/script/runner +3 -0
  103. data/script/server +3 -0
  104. data/test/fixtures/containers.yml +44 -0
  105. data/test/fixtures/furnitures.yml +47 -0
  106. data/test/fixtures/mailer/avtouch +1 -0
  107. data/test/fixtures/networks.yml +31 -0
  108. data/test/fixtures/objects_in_world.yml +71 -0
  109. data/test/fixtures/objects_in_world_panels.yml +43 -0
  110. data/test/fixtures/objects_off_world.yml +55 -0
  111. data/test/fixtures/objects_off_world_panels.yml +20 -0
  112. data/test/fixtures/panel_revisions.yml +28 -0
  113. data/test/fixtures/panels.yml +79 -0
  114. data/test/functional/container_controller_test.rb +167 -0
  115. data/test/functional/content_controller_test.rb +91 -0
  116. data/test/functional/furnitures_controller_test.rb +134 -0
  117. data/test/functional/networks_controller_test.rb +248 -0
  118. data/test/functional/objects_in_world_controller_test.rb +42 -0
  119. data/test/functional/panels_controller_test.rb +173 -0
  120. data/test/test_helper.rb +53 -0
  121. data/test/unit/container_test.rb +53 -0
  122. data/test/unit/furniture_test.rb +68 -0
  123. data/test/unit/mailer_test.rb +40 -0
  124. data/test/unit/network_test.rb +42 -0
  125. data/test/unit/object_in_world_test.rb +33 -0
  126. data/test/unit/object_off_world_test.rb +26 -0
  127. data/test/unit/panel_revision_test.rb +148 -0
  128. data/test/unit/panel_test.rb +63 -0
  129. data/vendor/plugins/annotate_models/ChangeLog +46 -0
  130. data/vendor/plugins/annotate_models/README +31 -0
  131. data/vendor/plugins/annotate_models/lib/annotate_models.rb +132 -0
  132. data/vendor/plugins/annotate_models/tasks/annotate_models_tasks.rake +7 -0
  133. data/vendor/plugins/foreign_key_migrations/CHANGELOG +99 -0
  134. data/vendor/plugins/foreign_key_migrations/MIT-LICENSE +20 -0
  135. data/vendor/plugins/foreign_key_migrations/README +87 -0
  136. data/vendor/plugins/foreign_key_migrations/about.yml +5 -0
  137. data/vendor/plugins/foreign_key_migrations/init.rb +3 -0
  138. data/vendor/plugins/foreign_key_migrations/install.rb +1 -0
  139. data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/base.rb +22 -0
  140. data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/abstract_adapter.rb +22 -0
  141. data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/table_definition.rb +28 -0
  142. data/vendor/plugins/redhillonrails_core/CHANGELOG +154 -0
  143. data/vendor/plugins/redhillonrails_core/MIT-LICENSE +20 -0
  144. data/vendor/plugins/redhillonrails_core/README +139 -0
  145. data/vendor/plugins/redhillonrails_core/init.rb +19 -0
  146. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb +54 -0
  147. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/abstract_adapter.rb +31 -0
  148. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/column.rb +21 -0
  149. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb +26 -0
  150. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/index_definition.rb +11 -0
  151. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_adapter.rb +82 -0
  152. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_column.rb +8 -0
  153. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/postgresql_adapter.rb +107 -0
  154. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/schema_statements.rb +23 -0
  155. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/sqlite3_adapter.rb +9 -0
  156. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/table_definition.rb +27 -0
  157. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema.rb +27 -0
  158. data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb +47 -0
  159. metadata +290 -0
@@ -0,0 +1,5 @@
1
+ author: simon@redhillconsulting.com.au
2
+ summary: Automatically generates foreign-key constraints when creating tables.
3
+ homepage: http://www.redhillonrails.org
4
+ license: MIT
5
+ rails_version: EDGE
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Base.send(:include, RedHillConsulting::ForeignKeyMigrations::ActiveRecord::Base)
2
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, RedHillConsulting::ForeignKeyMigrations::ActiveRecord::ConnectionAdapters::AbstractAdapter)
3
+ ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, RedHillConsulting::ForeignKeyMigrations::ActiveRecord::ConnectionAdapters::TableDefinition)
@@ -0,0 +1 @@
1
+ puts "WARNING: You also need to install redhillonrails_core" unless File.exists?(File.join(File.dirname(__FILE__), "..", "redhillonrails_core"))
@@ -0,0 +1,22 @@
1
+ module RedHillConsulting::ForeignKeyMigrations::ActiveRecord
2
+ module Base
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def references(table_name, column_name, options)
9
+ column_name = column_name.to_s
10
+ if options.has_key?(:references)
11
+ references = options[:references]
12
+ references = [references, :id] unless references.nil? || references.is_a?(Array)
13
+ references
14
+ elsif column_name == 'parent_id'
15
+ [table_name, :id]
16
+ elsif column_name =~ /^(.*)_id$/
17
+ [pluralized_table_name($1), :id]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module RedHillConsulting::ForeignKeyMigrations::ActiveRecord::ConnectionAdapters
2
+ module AbstractAdapter
3
+ def self.included(base)
4
+ base.class_eval do
5
+ alias_method_chain :initialize, :foreign_key_migrations unless method_defined?(:initialize_without_foreign_key_migrations)
6
+ end
7
+ end
8
+
9
+ def initialize_with_foreign_key_migrations(*args)
10
+ initialize_without_foreign_key_migrations(*args)
11
+ self.class.class_eval do
12
+ alias_method_chain :add_column, :foreign_key_migrations unless method_defined?(:add_column_without_foreign_key_migrations)
13
+ end
14
+ end
15
+
16
+ def add_column_with_foreign_key_migrations(table_name, column_name, type, options = {})
17
+ add_column_without_foreign_key_migrations(table_name, column_name, type, options)
18
+ references = ActiveRecord::Base.references(table_name, column_name, options)
19
+ add_foreign_key(table_name, column_name, references.first, references.last, options) if references
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ module RedHillConsulting::ForeignKeyMigrations::ActiveRecord::ConnectionAdapters
2
+ module TableDefinition
3
+ def self.included(base)
4
+ base.class_eval do
5
+ alias_method_chain :column, :foreign_key_migrations
6
+ alias_method_chain :primary_key, :foreign_key_migrations
7
+ end
8
+ end
9
+
10
+ def primary_key_with_foreign_key_migrations(name, options = {})
11
+ column(name, :primary_key, options)
12
+ end
13
+
14
+ def column_with_foreign_key_migrations(name, type, options = {})
15
+ column_without_foreign_key_migrations(name, type, options)
16
+ references = ActiveRecord::Base.references(self.name, name, options)
17
+ foreign_key(name, references.first, references.last, options) if references
18
+ self
19
+ end
20
+
21
+ # Some people liked this; personally I've decided against using it but I'll keep it nonetheless
22
+ def belongs_to(table, options = {})
23
+ options = options.merge(:references => table)
24
+ options[:on_delete] = options.delete(:dependent) if options.has_key?(:dependent)
25
+ column("#{table.to_s.singularize}_id".to_sym, :integer, options)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,154 @@
1
+ [REVISION 20071013]
2
+
3
+ [NEW] New migration script methods: set_table_comment and clear_table_comment. Implemented for MySQL and PostgreSQL. Currently not written to schema.rb.
4
+
5
+ [REVISION 20070905]
6
+
7
+ [NEW] Explicitly ignore add_foreign_key() and remove_foreign_key() when running under SQLite. This solves issues when migrating schema from other databases.
8
+
9
+ [REVISION 20070707]
10
+
11
+ [NEW] Make the table name in table definition accessible.
12
+
13
+ [REVISION 20070529]
14
+
15
+ [FIXED] Undefined constant errors when patching connection adapters. Rails now only loads the connection adapter for the specified database (it used to load them all).
16
+
17
+ [REVISION 20070503]
18
+
19
+ [NEW] Support for SQL92 [NOT] DEFERRABLE on foreign keys.
20
+ [CHANGED] Foreign key names are now assigned by the database unless an explicit name is given (using :name).
21
+
22
+ [REVISION 20070221]
23
+
24
+ [NEW] Where possible, determine if a column is case sensitive (or not) based on the presence of case-insensitive indexes.
25
+
26
+ [REVISION 20070220]
27
+
28
+ [CHANGED] :ignore_case => true option when creating indexes change to :case_sensitive => false in keeping with the new Rails 1.2 option of the same name on validates_uniqueness_of. You may need to re-create your schema.rb (by using rake db:schema:dump) to pickup the new syntax.
29
+
30
+ [FIXED] Multi-column, case-insensitive indexes only selecting one of the columns!
31
+
32
+ [REVISION 20070219]
33
+
34
+ [FIXED] Can't drop table referenced in a foreign-key. All reverse foreign keys are now dropped before dropping the table.
35
+
36
+ [CHANGED] Upgrade to Rails 1.2.2.
37
+
38
+ [REVISION 20070217]
39
+
40
+ [NEW] Support reverse_foreign_keys for MySQL using the (typically bastardised) MySQL flavour of information_schema.
41
+
42
+ [CHANGED] Merged ForiegnKey and ForeignKeyDefinition as they were practically the same.
43
+
44
+ [REVISION 20070214]
45
+
46
+ [NEW] :name option when creating foreign keys.
47
+
48
+ [FIXED] Foreign key names are preserved in schema dumps. This means they will be copied from one database to another rather than leaving it up to the target database to make one up.
49
+
50
+ [NEW] Foreign keys are automatically assigned a name (fkey_<tablename>_col1_and_col2_and_col3) if none is specified.
51
+
52
+ [REVISION 20061206]
53
+
54
+ [NEW] Added :ignore_case option to add_index in PostgreSQL to support case-insensitive indexes. The generated indexes are actually expression indexes of the form: lower(column_name).
55
+
56
+ [REVISION 20061206]
57
+
58
+ [NEW] reverse_foreign_keys methods.
59
+
60
+ [REVISION 20061202]
61
+
62
+ [CHANGED] Use Rails 1.2 alias_method_chain.
63
+
64
+ [CHANGED] Separate modules into individual files.
65
+
66
+ [REVISION 20061129]
67
+
68
+ [FIXED] Foreign-key ON DELETE and ON UPDATE flipped in schema dump.
69
+
70
+ [REVISION 20061121]
71
+
72
+ [FIXED] MySQL doesn't support SQL92 'DROP CONSTRAINT SYNTAX'; use 'DROP FOREIGN KEY' instead.
73
+
74
+ [REVISION 20061116]
75
+
76
+ [FIXED] 'DROP FOREIGN KEY' should be 'DROP CONSTRAINT'.
77
+
78
+ [REVISION 20061114]
79
+
80
+ [CHANGED] Removed Column.required as it didn't handle updates correctly. Instead we now have Column.required_on which returns an appropriate event (nil, :save, :update).
81
+
82
+ [REVISION 20061110]
83
+
84
+ [FIXED] MySQL driver uses single AND double quotes around identifiers.
85
+
86
+ [REVISION 20061028]
87
+
88
+ [FIXED] Syntax error when generating schema under MySQL when a foreign key specifies both ON UPDATE and ON DELETE.
89
+
90
+ [REVISION 20061024]
91
+
92
+ [FIXED] Foreign key associations for key-word table-names are quoted in postgresql.
93
+
94
+ [REVISION 20061011]
95
+
96
+ [NEW] ActiveRecord::Base.base_class? returns true if the class is a base class; false otherwise.
97
+
98
+ [REVISION 20061009]
99
+
100
+ [NEW] ActiveRecord::Base.abstract_class? returns true if class name starts with 'Abstract'; false otherwise.
101
+
102
+ [REVISION 20061001]
103
+
104
+ [NEW] remove_foreign_key for completeness.
105
+
106
+ [FIXED] MySQL barfs when attempting to drop a column that participates in a foreign key constraint.
107
+
108
+ [REVISION 20060921]
109
+
110
+ [FIXED] add_foreign_key doesn't support on_delete or on_update--It doesn't do anything with the options hash.
111
+
112
+ [REVISION 20060919]
113
+
114
+ [CHANGED] Column.unique is now derived based on the presence of Column.unique_scope (which is an empty array for single column unique indexes).
115
+
116
+ [REVISION 20060915]
117
+
118
+ [NEW] Unique columns contain scoping meta-data for multi-column unique indexes. The column to be marked as unique is either the last column not ending in '_id' or simply the last column. This follows the typical composite unique index column ordering where the scoping is specified first but will attempt to find the last non-foreign-key column just-in-case. Eg, both add_index :states, [:country_id, :name] and add_index :states, [:name, :country_id] would result in the name column marked as unique with a scope of [:country_id].
119
+
120
+ [REVISION 20060913]
121
+
122
+ [NEW] Column.required: returns true if a column is marked as not allowing null and has no default.
123
+
124
+ [REVISION 20060911]
125
+
126
+ [NEW] Patch rails MysqlColumn so that empty string defaults are treated as nil when a column is marked as NOT NULL. This primarily affects schema dumps incorrectly assigning a default of 0 to numbers and '' to strings when none was originally specified.
127
+
128
+ [REVISION 20060909]
129
+
130
+ [CHANGED] Renamed from Foreign Key Support.
131
+
132
+ [NEW] ActiveRecord::Base.indexes.
133
+
134
+ [REVISION 20060906]
135
+
136
+ [FIXED] :on_update with :on_delete producing invalid SQL.
137
+
138
+ [REVISION 20060905]
139
+
140
+ [NEW] Schema dumper outputs foreign keys when available.
141
+
142
+ [NEW] Foreign-key meta-data for: PostgreSQL; and MySQL. (Still needs a bit of DRY-ing up but it works which is the first step.)
143
+
144
+ [REVISION 20060901]
145
+
146
+ [FIXED] Incorrect generation of ON UPDATE/ON DELETE clauses.
147
+
148
+ [NEW] Support :restrict in ON UPDATE/ON DELETE clauses.
149
+
150
+ [NEW] Preliminary support for querying foreign-keys in PostgreSQL.
151
+
152
+ [REVISION 20060831]
153
+
154
+ [NEW] Initial version.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 RedHill Consulting, Pty. Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,139 @@
1
+ = RedHill on Rails Core
2
+
3
+ RedHill on Rails Core is a plugin that adds the following features:
4
+
5
+ * Generic support for foreign-keys;
6
+ * Mechanism for obtaining indexes directly from a model class; and
7
+ * A mechanism for determining when <code>Schema.define()</code> is running.
8
+
9
+ === Foreign Key Support
10
+
11
+ The plugin provides two mechanisms for adding foreign keys as well as
12
+ preserving foreign keys when performing a schema dump. (Using SQL-92 syntax and
13
+ as such should be compatible with most databases that support foreign-key
14
+ constraints.)
15
+
16
+ The first mechanism for creating foreign-keys allows you to add a foreign key
17
+ when defining a table. For example:
18
+
19
+ create_table :orders do |t|
20
+ ...
21
+ t.foreign_key :customer_id, :customers, :id
22
+ end
23
+
24
+ You also have the option of specifying what to do on delete/update using
25
+ <code>:on_delete</code>/<code>:on_update</code>, respectively to one of: <code>:cascade</code>; <code>:restrict</code>; and <code>:set_null</code>:
26
+
27
+ create_table :orders do |t|
28
+ ...
29
+ t.foreign_key :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade
30
+ end
31
+
32
+ The second method allows you to create arbitrary foreign-keys at any time:
33
+
34
+ add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade)
35
+
36
+ In either case, if your database supports deferred foreign keys (for example PostgreSQL) you can specify this as well:
37
+
38
+ t.foreign_key :customer_id, :customers, :id, :deferrable => true
39
+ add_foreign_key(:orders, :customer_id, :customers, :id, :deferrable => true)
40
+
41
+ By default, the foreign key will be assigned a name by the underlying database. However, if this doesn't suit
42
+ your needs, you can override the default assignment using the <code>:name</code> option:
43
+
44
+ add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade, <strong>:name => :orders_customer_id_foreign_key<strong>)
45
+
46
+ You can also query the foreign keys for a model yourself by calling <code>foreign_keys()</code>:
47
+
48
+ Order.foreign_keys
49
+
50
+ Or for an arbitrary table by calling <code>foreign_keys(table_name)</code> on a database adapter.
51
+
52
+ Either method returns an array of the following meta-data:
53
+
54
+ * +name+ - The name of the foreign key constraint;
55
+ * +table_name+ - The table for which the foreign-key was generated;
56
+ * +column_names+ - The column names in the table;
57
+ * +references_table_name+ - The table referenced by the foreign-key; and
58
+ * +references_column_names+ - The columns names in the referenced table.
59
+
60
+ If you need to drop a foreign-key, use:
61
+
62
+ remove_foreign_key :orders, :orders_ordered_by_id_fkey
63
+
64
+ The plugin also ensures that all foreign keys are output when performing a
65
+ schema dump. This happens automatically when running <code>rake migrate</code> or
66
+ <code>rake db:schema:dump</code>. This has particular implications when running
67
+ unit tests that contain fixtures. To ensure the test data is correctly reset after
68
+ each test, you should list your fixtures in order of parent->child. For example:
69
+
70
+ fixtures :customers, :products, :orders, :order_lines
71
+
72
+ Rails will then set-up and tear-down the fixtures in the correct sequence.
73
+
74
+ Some databases (PostgreSQL and MySQL for example) allow you to set a comment for a
75
+ table. You can do this for existing tables by using:
76
+
77
+ set_table_comment :orders, "All pending and processed orders"
78
+
79
+ or even at the time of creation:
80
+
81
+ create_table :orders, :comment => "All pending and processed orders" do |t|
82
+ ...
83
+ end
84
+
85
+ You can also clear table comments:
86
+
87
+ clear_table_comment :orders
88
+
89
+ The plugin fully supports and understands the following active-record
90
+ configuration properties:
91
+
92
+ * <code>config.active_record.pluralize_table_names</code>
93
+ * <code>config.active_record.table_name_prefix</code>
94
+ * <code>config.active_record.table_name_suffix</code>
95
+
96
+ === Model Indexes
97
+
98
+ ActiveRecord::Base already provides a method on connection for obtaining the
99
+ indexes for a given table. This plugin now makes it possible to obtain the
100
+ indexes for a given model--<code>ActiveRecord::Base</code>--class. For example:
101
+
102
+ Invoice.indexes
103
+
104
+ Would return all the indexes for the +invoices+ table.
105
+
106
+ === Schema Defining
107
+
108
+ The plugin also adds a method--<code>defining?()</code>--to
109
+ <code>ActiveRecord::Schema</code> to indicate when <code>define()</code> is running. This is necessary
110
+ as some migration plugins must change their behaviour accordingly.
111
+
112
+ === Case-insensitive Indexes
113
+
114
+ For PostgreSQL, you can add an option <code>:case_sensitive => false</code> to <code>add_index</code>
115
+ which will generate an expression index of the form:
116
+
117
+ LOWER(column_name)
118
+
119
+ This means finder queries of the form:
120
+
121
+ WHERE LOWER(column_name) = LOWER(?)
122
+
123
+ are able to use the indexes rather require, in the worst case, full-table scans.
124
+
125
+ Note also that this ties in well with Rails built-in support for case-insensitive searching:
126
+
127
+ validates_uniqueness_of :name, :case_sensitive => false
128
+
129
+ === See Also
130
+
131
+ * Foreign Key Associations (foreign_key_associations)
132
+ * Foreign Key Migrations (foreign_key_migrations)
133
+ * Row Version Migrations (row_version_migrations)
134
+ * Schema Validations (schema_validations)
135
+
136
+ === License
137
+
138
+ This plugin is copyright 2006 by RedHill Consulting, Pty. Ltd. and is released
139
+ under the MIT license.
@@ -0,0 +1,19 @@
1
+ ActiveRecord::Base.send(:include, RedHillConsulting::Core::ActiveRecord::Base)
2
+ ActiveRecord::Schema.send(:include, RedHillConsulting::Core::ActiveRecord::Schema)
3
+ ActiveRecord::SchemaDumper.send(:include, RedHillConsulting::Core::ActiveRecord::SchemaDumper)
4
+ ActiveRecord::ConnectionAdapters::IndexDefinition.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::IndexDefinition)
5
+ ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::TableDefinition)
6
+ ActiveRecord::ConnectionAdapters::Column.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::Column)
7
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::AbstractAdapter)
8
+ ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::SchemaStatements)
9
+
10
+ if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) then
11
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::PostgresqlAdapter)
12
+ end
13
+ if defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter) then
14
+ ActiveRecord::ConnectionAdapters::MysqlColumn.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::MysqlColumn)
15
+ ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::MysqlAdapter)
16
+ end
17
+ if defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter) then
18
+ ActiveRecord::ConnectionAdapters::SQLite3Adapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::Sqlite3Adapter)
19
+ end
@@ -0,0 +1,54 @@
1
+ module RedHillConsulting::Core::ActiveRecord
2
+ module Base
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def self.extended(base)
9
+ class << base
10
+ alias_method_chain :columns, :redhillonrails_core unless method_defined?(:columns_without_redhillonrails_core)
11
+ alias_method_chain :abstract_class?, :redhillonrails_core unless method_defined?(:abstract_class_without_redhillonrails_core?)
12
+ end
13
+ end
14
+
15
+ def base_class?
16
+ self == base_class
17
+ end
18
+
19
+ def abstract_class_with_redhillonrails_core?
20
+ abstract_class_without_redhillonrails_core? || !(name =~ /^Abstract/).nil?
21
+ end
22
+
23
+ def columns_with_redhillonrails_core
24
+ unless @columns
25
+ columns_without_redhillonrails_core
26
+ cols = columns_hash
27
+ indexes.each do |index|
28
+ column_name = index.columns.reverse.detect { |name| name !~ /_id$/ } || index.columns.last
29
+ column = cols[column_name]
30
+ column.case_sensitive = index.case_sensitive?
31
+ column.unique_scope = index.columns.reject { |name| name == column_name } if index.unique
32
+ end
33
+ end
34
+ @columns
35
+ end
36
+
37
+ def pluralized_table_name(table_name)
38
+ ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name
39
+ end
40
+
41
+ def indexes
42
+ @indexes ||= connection.indexes(table_name, "#{name} Indexes")
43
+ end
44
+
45
+ def foreign_keys
46
+ @foreign_keys ||= connection.foreign_keys(table_name, "#{name} Foreign Keys")
47
+ end
48
+
49
+ def reverse_foreign_keys
50
+ connection.reverse_foreign_keys(table_name, "#{name} Reverse Foreign Keys")
51
+ end
52
+ end
53
+ end
54
+ end