aspgems-redhillonrails_core 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +194 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README +161 -0
- data/Rakefile +59 -0
- data/init.rb +1 -0
- data/lib/redhillonrails_core.rb +46 -0
- data/lib/redhillonrails_core/active_record/base.rb +45 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/abstract/column.rb +14 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/abstract/foreign_key_definition.rb +63 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/abstract/index_definition.rb +11 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/abstract/schema_statements.rb +23 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/abstract/table_definition.rb +27 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb +84 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/mysql_adapter.rb +131 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/mysql_column.rb +8 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/postgresql_adapter.rb +131 -0
- data/lib/redhillonrails_core/active_record/connection_adapters/sqlite3_adapter.rb +115 -0
- data/lib/redhillonrails_core/active_record/schema.rb +25 -0
- data/lib/redhillonrails_core/active_record/schema_dumper.rb +75 -0
- data/lib/redhillonrails_core/version.rb +3 -0
- data/lib/tasks/db/comments.rake +9 -0
- data/redhillonrails_core.gemspec +27 -0
- data/spec/connections/mysql/connection.rb +18 -0
- data/spec/connections/mysql2/connection.rb +18 -0
- data/spec/connections/postgresql/connection.rb +15 -0
- data/spec/connections/sqlite3/connection.rb +14 -0
- data/spec/foreign_key_definition_spec.rb +21 -0
- data/spec/foreign_key_spec.rb +100 -0
- data/spec/index_definition_spec.rb +145 -0
- data/spec/index_spec.rb +67 -0
- data/spec/models/comment.rb +5 -0
- data/spec/models/post.rb +6 -0
- data/spec/models/user.rb +5 -0
- data/spec/schema/schema.rb +21 -0
- data/spec/schema_dumper_spec.rb +138 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/reference.rb +66 -0
- metadata +159 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
[REVISION 20110112]
|
2
|
+
|
3
|
+
[REMOVE] Remove unused columns monkeypatch and avoid a query to get the indexes of a table that cost so much in tables with so many records
|
4
|
+
|
5
|
+
[REVISION 20080701]
|
6
|
+
|
7
|
+
[FIXED] Looking up schema version fails on Rails 2.1.
|
8
|
+
|
9
|
+
[REVISION 20080318]
|
10
|
+
|
11
|
+
[FIXED] Case-insensitive text columns not recognised.
|
12
|
+
|
13
|
+
[REVISION 20080221]
|
14
|
+
|
15
|
+
[NEW] PostgreSQL view management via create_view and drop_view.
|
16
|
+
|
17
|
+
[REVISION 20080209]
|
18
|
+
|
19
|
+
[FIXED] PostgreSQL columns named the same as database keywords (eg. type, column, user, etc.) caused NoSuchMethod errors during model validation.
|
20
|
+
|
21
|
+
[REVISION 20080110]
|
22
|
+
|
23
|
+
[FIXED] Workaround for bug in MySQL that adversely affects INFORMATION schema performance take 3 (Michael Latta).
|
24
|
+
|
25
|
+
[REVISION 20080103]
|
26
|
+
|
27
|
+
[FIXED] Workaround for bug in MySQL that adversely affects INFORMATION schema performance take 2 (Michael Latta).
|
28
|
+
|
29
|
+
[REVISION 20080102]
|
30
|
+
|
31
|
+
[FIXED] Workaround for bug in MySQL that adversely affects INFORMATION schema performance (Michael Latta).
|
32
|
+
|
33
|
+
[REVISION 20071128]
|
34
|
+
|
35
|
+
[FIXED] Workaround to ensure plugin is only ever loaded once.
|
36
|
+
|
37
|
+
[REVISION 20071013]
|
38
|
+
|
39
|
+
[NEW] Rake task (db:comments) to show database table comments.
|
40
|
+
|
41
|
+
[REVISION 20071013]
|
42
|
+
|
43
|
+
[NEW] New migration script methods: set_table_comment and clear_table_comment. Implemented for MySQL and PostgreSQL. Currently not written to schema.rb.
|
44
|
+
|
45
|
+
[REVISION 20070905]
|
46
|
+
|
47
|
+
[NEW] Explicitly ignore add_foreign_key() and remove_foreign_key() when running under SQLite. This solves issues when migrating schema from other databases.
|
48
|
+
|
49
|
+
[REVISION 20070707]
|
50
|
+
|
51
|
+
[NEW] Make the table name in table definition accessible.
|
52
|
+
|
53
|
+
[REVISION 20070529]
|
54
|
+
|
55
|
+
[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).
|
56
|
+
|
57
|
+
[REVISION 20070503]
|
58
|
+
|
59
|
+
[NEW] Support for SQL92 [NOT] DEFERRABLE on foreign keys.
|
60
|
+
[CHANGED] Foreign key names are now assigned by the database unless an explicit name is given (using :name).
|
61
|
+
|
62
|
+
[REVISION 20070221]
|
63
|
+
|
64
|
+
[NEW] Where possible, determine if a column is case sensitive (or not) based on the presence of case-insensitive indexes.
|
65
|
+
|
66
|
+
[REVISION 20070220]
|
67
|
+
|
68
|
+
[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.
|
69
|
+
|
70
|
+
[FIXED] Multi-column, case-insensitive indexes only selecting one of the columns!
|
71
|
+
|
72
|
+
[REVISION 20070219]
|
73
|
+
|
74
|
+
[FIXED] Can't drop table referenced in a foreign-key. All reverse foreign keys are now dropped before dropping the table.
|
75
|
+
|
76
|
+
[CHANGED] Upgrade to Rails 1.2.2.
|
77
|
+
|
78
|
+
[REVISION 20070217]
|
79
|
+
|
80
|
+
[NEW] Support reverse_foreign_keys for MySQL using the (typically bastardised) MySQL flavour of information_schema.
|
81
|
+
|
82
|
+
[CHANGED] Merged ForiegnKey and ForeignKeyDefinition as they were practically the same.
|
83
|
+
|
84
|
+
[REVISION 20070214]
|
85
|
+
|
86
|
+
[NEW] :name option when creating foreign keys.
|
87
|
+
|
88
|
+
[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.
|
89
|
+
|
90
|
+
[NEW] Foreign keys are automatically assigned a name (fkey_<tablename>_col1_and_col2_and_col3) if none is specified.
|
91
|
+
|
92
|
+
[REVISION 20061206]
|
93
|
+
|
94
|
+
[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).
|
95
|
+
|
96
|
+
[REVISION 20061206]
|
97
|
+
|
98
|
+
[NEW] reverse_foreign_keys methods.
|
99
|
+
|
100
|
+
[REVISION 20061202]
|
101
|
+
|
102
|
+
[CHANGED] Use Rails 1.2 alias_method_chain.
|
103
|
+
|
104
|
+
[CHANGED] Separate modules into individual files.
|
105
|
+
|
106
|
+
[REVISION 20061129]
|
107
|
+
|
108
|
+
[FIXED] Foreign-key ON DELETE and ON UPDATE flipped in schema dump.
|
109
|
+
|
110
|
+
[REVISION 20061121]
|
111
|
+
|
112
|
+
[FIXED] MySQL doesn't support SQL92 'DROP CONSTRAINT SYNTAX'; use 'DROP FOREIGN KEY' instead.
|
113
|
+
|
114
|
+
[REVISION 20061116]
|
115
|
+
|
116
|
+
[FIXED] 'DROP FOREIGN KEY' should be 'DROP CONSTRAINT'.
|
117
|
+
|
118
|
+
[REVISION 20061114]
|
119
|
+
|
120
|
+
[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).
|
121
|
+
|
122
|
+
[REVISION 20061110]
|
123
|
+
|
124
|
+
[FIXED] MySQL driver uses single AND double quotes around identifiers.
|
125
|
+
|
126
|
+
[REVISION 20061028]
|
127
|
+
|
128
|
+
[FIXED] Syntax error when generating schema under MySQL when a foreign key specifies both ON UPDATE and ON DELETE.
|
129
|
+
|
130
|
+
[REVISION 20061024]
|
131
|
+
|
132
|
+
[FIXED] Foreign key associations for key-word table-names are quoted in postgresql.
|
133
|
+
|
134
|
+
[REVISION 20061011]
|
135
|
+
|
136
|
+
[NEW] ActiveRecord::Base.base_class? returns true if the class is a base class; false otherwise.
|
137
|
+
|
138
|
+
[REVISION 20061009]
|
139
|
+
|
140
|
+
[NEW] ActiveRecord::Base.abstract_class? returns true if class name starts with 'Abstract'; false otherwise.
|
141
|
+
|
142
|
+
[REVISION 20061001]
|
143
|
+
|
144
|
+
[NEW] remove_foreign_key for completeness.
|
145
|
+
|
146
|
+
[FIXED] MySQL barfs when attempting to drop a column that participates in a foreign key constraint.
|
147
|
+
|
148
|
+
[REVISION 20060921]
|
149
|
+
|
150
|
+
[FIXED] add_foreign_key doesn't support on_delete or on_update--It doesn't do anything with the options hash.
|
151
|
+
|
152
|
+
[REVISION 20060919]
|
153
|
+
|
154
|
+
[CHANGED] Column.unique is now derived based on the presence of Column.unique_scope (which is an empty array for single column unique indexes).
|
155
|
+
|
156
|
+
[REVISION 20060915]
|
157
|
+
|
158
|
+
[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].
|
159
|
+
|
160
|
+
[REVISION 20060913]
|
161
|
+
|
162
|
+
[NEW] Column.required: returns true if a column is marked as not allowing null and has no default.
|
163
|
+
|
164
|
+
[REVISION 20060911]
|
165
|
+
|
166
|
+
[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.
|
167
|
+
|
168
|
+
[REVISION 20060909]
|
169
|
+
|
170
|
+
[CHANGED] Renamed from Foreign Key Support.
|
171
|
+
|
172
|
+
[NEW] ActiveRecord::Base.indexes.
|
173
|
+
|
174
|
+
[REVISION 20060906]
|
175
|
+
|
176
|
+
[FIXED] :on_update with :on_delete producing invalid SQL.
|
177
|
+
|
178
|
+
[REVISION 20060905]
|
179
|
+
|
180
|
+
[NEW] Schema dumper outputs foreign keys when available.
|
181
|
+
|
182
|
+
[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.)
|
183
|
+
|
184
|
+
[REVISION 20060901]
|
185
|
+
|
186
|
+
[FIXED] Incorrect generation of ON UPDATE/ON DELETE clauses.
|
187
|
+
|
188
|
+
[NEW] Support :restrict in ON UPDATE/ON DELETE clauses.
|
189
|
+
|
190
|
+
[NEW] Preliminary support for querying foreign-keys in PostgreSQL.
|
191
|
+
|
192
|
+
[REVISION 20060831]
|
193
|
+
|
194
|
+
[NEW] Initial version.
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -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.
|
data/README
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
= Disclaimer
|
2
|
+
|
3
|
+
redhillonrails_core was originally created by http://github.com/harukizaemon but it was retired and is no longer supported.
|
4
|
+
|
5
|
+
That fork is intended to make redhillonrails_core compatible with edge rails and introduce some new features.
|
6
|
+
|
7
|
+
= RedHill on Rails Core
|
8
|
+
|
9
|
+
Goal of redhillonrails_core is to provided missing ActiveRecord support for database specific features:
|
10
|
+
|
11
|
+
* foreign_keys
|
12
|
+
* case-insensitive and partial indexes (pgsql only)
|
13
|
+
* views
|
14
|
+
|
15
|
+
== Installation
|
16
|
+
|
17
|
+
As a gem
|
18
|
+
|
19
|
+
gem install aspgems-redhillonrails_core
|
20
|
+
|
21
|
+
== Compatibility
|
22
|
+
|
23
|
+
* Ruby - 1.8, 1.9
|
24
|
+
* ActiveRecord - 2.X, 3.X
|
25
|
+
* Databases - PostgreSQL, MySQL, SQLite3 (most features should also run on others)
|
26
|
+
|
27
|
+
=== Foreign Key Support
|
28
|
+
|
29
|
+
The plugin provides two mechanisms for adding foreign keys as well as
|
30
|
+
preserving foreign keys when performing a schema dump. (Using SQL-92 syntax and
|
31
|
+
as such should be compatible with most databases that support foreign-key
|
32
|
+
constraints.)
|
33
|
+
|
34
|
+
The first mechanism for creating foreign-keys allows you to add a foreign key
|
35
|
+
when defining a table. For example:
|
36
|
+
|
37
|
+
create_table :orders do |t|
|
38
|
+
...
|
39
|
+
t.foreign_key :customer_id, :customers, :id
|
40
|
+
end
|
41
|
+
|
42
|
+
You also have the option of specifying what to do on delete/update using
|
43
|
+
<code>:on_delete</code>/<code>:on_update</code>, respectively to one of: <code>:cascade</code>; <code>:restrict</code>; and <code>:set_null</code>:
|
44
|
+
|
45
|
+
create_table :orders do |t|
|
46
|
+
...
|
47
|
+
t.foreign_key :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade
|
48
|
+
end
|
49
|
+
|
50
|
+
The second method allows you to create arbitrary foreign-keys at any time:
|
51
|
+
|
52
|
+
add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade)
|
53
|
+
|
54
|
+
In either case, if your database supports deferred foreign keys (for example PostgreSQL) you can specify this as well:
|
55
|
+
|
56
|
+
t.foreign_key :customer_id, :customers, :id, :deferrable => true
|
57
|
+
add_foreign_key(:orders, :customer_id, :customers, :id, :deferrable => true)
|
58
|
+
|
59
|
+
By default, the foreign key will be assigned a name by the underlying database. However, if this doesn't suit
|
60
|
+
your needs, you can override the default assignment using the <code>:name</code> option:
|
61
|
+
|
62
|
+
add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade, <strong>:name => :orders_customer_id_foreign_key<strong>)
|
63
|
+
|
64
|
+
You can also query the foreign keys for a model yourself by calling <code>foreign_keys()</code>:
|
65
|
+
|
66
|
+
Order.foreign_keys
|
67
|
+
|
68
|
+
Or for an arbitrary table by calling <code>foreign_keys(table_name)</code> on a database adapter.
|
69
|
+
|
70
|
+
Either method returns an array of the following meta-data:
|
71
|
+
|
72
|
+
* +name+ - The name of the foreign key constraint;
|
73
|
+
* +table_name+ - The table for which the foreign-key was generated;
|
74
|
+
* +column_names+ - The column names in the table;
|
75
|
+
* +references_table_name+ - The table referenced by the foreign-key; and
|
76
|
+
* +references_column_names+ - The columns names in the referenced table.
|
77
|
+
|
78
|
+
If you need to drop a foreign-key, use:
|
79
|
+
|
80
|
+
remove_foreign_key :orders, :orders_ordered_by_id_fkey
|
81
|
+
|
82
|
+
The plugin also ensures that all foreign keys are output when performing a
|
83
|
+
schema dump. This happens automatically when running <code>rake migrate</code> or
|
84
|
+
<code>rake db:schema:dump</code>. This has particular implications when running
|
85
|
+
unit tests that contain fixtures. To ensure the test data is correctly reset after
|
86
|
+
each test, you should list your fixtures in order of parent->child. For example:
|
87
|
+
|
88
|
+
fixtures :customers, :products, :orders, :order_lines
|
89
|
+
|
90
|
+
Rails will then set-up and tear-down the fixtures in the correct sequence.
|
91
|
+
|
92
|
+
Some databases (PostgreSQL and MySQL for example) allow you to set a comment for a
|
93
|
+
table. You can do this for existing tables by using:
|
94
|
+
|
95
|
+
set_table_comment :orders, "All pending and processed orders"
|
96
|
+
|
97
|
+
or even at the time of creation:
|
98
|
+
|
99
|
+
create_table :orders, :comment => "All pending and processed orders" do |t|
|
100
|
+
...
|
101
|
+
end
|
102
|
+
|
103
|
+
You can clear table comments using:
|
104
|
+
|
105
|
+
clear_table_comment :orders
|
106
|
+
|
107
|
+
There is also a rake tasks to show all database tables and their comments:
|
108
|
+
|
109
|
+
rake db:comments
|
110
|
+
|
111
|
+
The plugin fully supports and understands the following active-record
|
112
|
+
configuration properties:
|
113
|
+
|
114
|
+
* <code>config.active_record.pluralize_table_names</code>
|
115
|
+
* <code>config.active_record.table_name_prefix</code>
|
116
|
+
* <code>config.active_record.table_name_suffix</code>
|
117
|
+
|
118
|
+
=== View Support
|
119
|
+
|
120
|
+
The plugin provides a mechanism for creating and dropping views as well as
|
121
|
+
preserving views when performing a schema dump:
|
122
|
+
|
123
|
+
create_view :normal_customers, "SELECT * FROM customers WHERE status = 'normal'"
|
124
|
+
drop_view :normal_customers
|
125
|
+
|
126
|
+
=== Model Indexes
|
127
|
+
|
128
|
+
ActiveRecord::Base already provides a method on connection for obtaining the
|
129
|
+
indexes for a given table. This plugin now makes it possible to obtain the
|
130
|
+
indexes for a given model--<code>ActiveRecord::Base</code>--class. For example:
|
131
|
+
|
132
|
+
Invoice.indexes
|
133
|
+
|
134
|
+
Would return all the indexes for the +invoices+ table.
|
135
|
+
|
136
|
+
=== Schema Defining
|
137
|
+
|
138
|
+
The plugin also adds a method--<code>defining?()</code>--to
|
139
|
+
<code>ActiveRecord::Schema</code> to indicate when <code>define()</code> is running. This is necessary
|
140
|
+
as some migration plugins must change their behaviour accordingly.
|
141
|
+
|
142
|
+
=== Case-insensitive Indexes
|
143
|
+
|
144
|
+
For PostgreSQL, you can add an option <code>:case_sensitive => false</code> to <code>add_index</code>
|
145
|
+
which will generate an expression index of the form:
|
146
|
+
|
147
|
+
LOWER(column_name)
|
148
|
+
|
149
|
+
This means finder queries of the form:
|
150
|
+
|
151
|
+
WHERE LOWER(column_name) = LOWER(?)
|
152
|
+
|
153
|
+
are able to use the indexes rather require, in the worst case, full-table scans.
|
154
|
+
|
155
|
+
Note also that this ties in well with Rails built-in support for case-insensitive searching:
|
156
|
+
|
157
|
+
validates_uniqueness_of :name, :case_sensitive => false
|
158
|
+
|
159
|
+
=== See Also
|
160
|
+
|
161
|
+
* Foreign Key Migrations (foreign_key_migrations)
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
%w[postgresql mysql mysql2 sqlite3].each do |adapter|
|
6
|
+
namespace adapter do
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
|
+
spec.rspec_opts = "-Ispec/connections/#{adapter}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Run postgresql and mysql tests'
|
14
|
+
task :spec do
|
15
|
+
%w[postgresql mysql mysql2 sqlite3].each do |adapter|
|
16
|
+
Rake::Task["#{adapter}:spec"].invoke
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :spec
|
21
|
+
|
22
|
+
namespace :postgresql do
|
23
|
+
desc 'Build the PostgreSQL test databases'
|
24
|
+
task :build_databases do
|
25
|
+
%x( createdb -E UTF8 rh_core_unittest )
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Drop the PostgreSQL test databases'
|
29
|
+
task :drop_databases do
|
30
|
+
%x( dropdb rh_core_unittest )
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Rebuild the PostgreSQL test databases'
|
34
|
+
task :rebuild_databases => [:drop_databases, :build_databases]
|
35
|
+
end
|
36
|
+
|
37
|
+
task :build_postgresql_databases => 'postgresql:build_databases'
|
38
|
+
task :drop_postgresql_databases => 'postgresql:drop_databases'
|
39
|
+
task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
|
40
|
+
|
41
|
+
MYSQL_DB_USER = 'rh_core'
|
42
|
+
namespace :mysql do
|
43
|
+
desc 'Build the MySQL test databases'
|
44
|
+
task :build_databases do
|
45
|
+
%x( echo "create DATABASE rh_core_unittest DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{MYSQL_DB_USER})
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Drop the MySQL test databases'
|
49
|
+
task :drop_databases do
|
50
|
+
%x( mysqladmin --user=#{MYSQL_DB_USER} -f drop rh_core_unittest )
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'Rebuild the MySQL test databases'
|
54
|
+
task :rebuild_databases => [:drop_databases, :build_databases]
|
55
|
+
end
|
56
|
+
|
57
|
+
task :build_mysql_databases => 'mysql:build_databases'
|
58
|
+
task :drop_mysql_databases => 'mysql:drop_databases'
|
59
|
+
task :rebuild_mysql_databases => 'mysql:rebuild_databases'
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'redhillonrails_core' unless defined?(RedHillConsulting::Core)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#require 'active_record/migration'
|
2
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
3
|
+
|
4
|
+
module RedhillonrailsCore
|
5
|
+
mattr_accessor :loaded_into_rails_core
|
6
|
+
|
7
|
+
module ActiveRecord
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
|
10
|
+
autoload :Base
|
11
|
+
autoload :Schema
|
12
|
+
autoload :SchemaDumper
|
13
|
+
|
14
|
+
module ConnectionAdapters
|
15
|
+
extend ActiveSupport::Autoload
|
16
|
+
|
17
|
+
autoload_under 'abstract' do
|
18
|
+
autoload :IndexDefinition
|
19
|
+
autoload :TableDefinition
|
20
|
+
autoload :Column
|
21
|
+
autoload :ForeignKeyDefinition
|
22
|
+
autoload :SchemaStatements
|
23
|
+
end
|
24
|
+
|
25
|
+
autoload :AbstractAdapter
|
26
|
+
autoload :PostgresqlAdapter
|
27
|
+
autoload :MysqlAdapter
|
28
|
+
autoload :MysqlColumn
|
29
|
+
autoload :Sqlite3Adapter
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
unless loaded_into_rails_core
|
34
|
+
::ActiveRecord::Base.send(:include, RedhillonrailsCore::ActiveRecord::Base)
|
35
|
+
::ActiveRecord::Schema.send(:include, RedhillonrailsCore::ActiveRecord::Schema)
|
36
|
+
::ActiveRecord::SchemaDumper.send(:include, RedhillonrailsCore::ActiveRecord::SchemaDumper)
|
37
|
+
::ActiveRecord::ConnectionAdapters::IndexDefinition.send(:include, RedhillonrailsCore::ActiveRecord::ConnectionAdapters::IndexDefinition)
|
38
|
+
::ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, RedhillonrailsCore::ActiveRecord::ConnectionAdapters::TableDefinition)
|
39
|
+
::ActiveRecord::ConnectionAdapters::Column.send(:include, RedhillonrailsCore::ActiveRecord::ConnectionAdapters::Column)
|
40
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, RedhillonrailsCore::ActiveRecord::ConnectionAdapters::AbstractAdapter)
|
41
|
+
::ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, RedhillonrailsCore::ActiveRecord::ConnectionAdapters::SchemaStatements)
|
42
|
+
|
43
|
+
self.loaded_into_rails_core = true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|