This is why it is important that the partition
conditions are a proper partitioning such as status = 'C' and status != 'C'
(non-overlapping and completely covering all possibilities). This ensures that every
row is inserted into one of the child tables, not the parent. Note that this would not
be a proper partitioning if the status column allowed NULL values, as both conditions
would be false.
Now we can insert and select data against listings as if it were one table, while
PostgreSQL transparently handles the partitioning and works with the proper partition.
This is a very simple example. In particular, we need to implement rules for
UPDATE and DELETE queries before using this scheme. This method can easily be
extended to many partitions, even on complicated conditions.
Connecting to Multiple Databases
Occasionally, you will have the need to connect to several different databases from
one application. This is useful for migrating from an old schema to a new one. It is also
helpful if you have differing data requirements within one application; perhaps some
data is more critical and is stored on a high-availability database cluster. In any case, it
is easy in Rails. First, specify multiple database environments in the database.yml configuration
file:
Connecting to Multiple Databases | 117
legacy:
adapter: mysql
database: my_db
username: user
password: pass
host: legacy_host
new:
adapter: mysql
database: my_db
username: user
password: pass
host: new_host
Then, you can simply refer to these configuration blocks from the ActiveRecord class
definition using the ActiveRecord::Base.
Pages:
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185