Does anyone know if this information shows up in schema.rb after a
rake db:schema:dump ?
If not, that's a whole new level of complication to get this working -
so far we have relied on the Rails schema dumper.
Tom
Does anyone know if this information shows up in schema.rb after a
rake db:schema:dump ?
Looks good, or even
indexed_field :integer, :indexed
We do this already for flag-like options like :required and :unique
Then again, I like you're idea of :index => "my_index_name" so your
way is probably better.
> a field declared with :unique => true would seem likely to
> want a unique index.
Naturally : )
> It could even be taken a step farther, adding an implicit :index to
> belongs_to, so foreign keys are always indexed.
Someone once explained to me that depending on the density of the
data, this is not always the right thing to do - i.e. scanning the
index can become more work than searching the unindexed table. Someone
who knows more about databases than me better chime in : )
> Thoughts? If people like this, I can work on rolling it into the other
> changes I've got waiting in the queue for the migration generator
> (better behavior of HABTM, adding fields in STI subclasses, better
> ignoring of non-Hobo tables).
That would be excellent : )
Tom
fields do
...
end
index :my_nice_index, :fields => [:a, :b, :c]
or maybe
index :a, :b, :c, :as => :my_nice_index
Tom
Yeah I think the :index => true is just a shorthand for the common
case, much as :required and :unique are shorthands already.
Tom
>I don't think these should go in the fields block at all, since they
>are not fields.
>
Since "belongs_to" (which generates a field/column) is not is the the fields
block, your argument is even stronger.
>The :index => true shorthand is OK, but I would but
>the index declarations outside, like
>
> fields do
> ...
> end
>
> index :my_nice_index, :fields => [:a, :b, :c]
>
>or maybe
>
> index :a, :b, :c, :as => :my_nice_index
I like this second version, since "as" could have a reasonable default.
>Tom
Regards,
Henry
--
Henry Baragar
Instantiated Software
Yep all looks good.
> Outside of fields:
> - index :foo will create an index on :foo
> - index [:foo, :bar, :baz] will create an index on the three fields
> together
> - pass :name => 'foo' to name the index
> - pass :unique => true to get a unique index
> Note: the [] on the multi-field index is important to distinguish from
> code that's expecting an attr_accessor-like behavior (pass N fields,
> get N declarations). We could support this behavior as well, if
> desired.
I think I would rather see one index generated per declaration, and
drop the [...]. There are examples of both styles in Rails, e.g. you
can't do "belongs_to :user, :project, :group"
I also kinda like :as => 'foo' rather than :name => 'foo', just
because I'm a sucker for APIs that read a little like English, but I
don't feel strongly about that one. Maybe :name is more obvious.
> Automatic indexing:
> - belongs_to will automatically add an index for their foreign key
> (and type, if polymorphic); pass :index => false to turn off
> - STI bases should automatically add an index for the type field
> - lifecycles will automatically add an index to the state field,
> pass :index => false to the lifecycle block to turn off
All good
> - should timestamps auto-add indexes? It can apparently help with
> sorting...
I'd vote no on this one. But how about supporting
timestamps :index => true
in the fields block
> - should the attribute marked 'login' be indexed? It would certainly
> make sense in user models.
Yeah I think this makes sense.
> Thoughts? I'm particularly interested in any other cases where
> automatic indexing could be useful.
I'd warn against going too far on this (we've made that mistake in the
past with aspects of Hobo). For the obscure cases I think it's much
better to put a tiny bit more work on the user, than to do things that
were not expected.
Tom
I don't really like the idea that we make the syntax (a little)
messier on behalf of people who don't know how it works. There's so
many things we can do with class-level declarations like this, surely
we can't apply the rule of "attr_accessor style" to all of them for
ever : )
> I've got no preference for the :name / :as thing - I used :name
> because that's what the underlying API uses.
OK let's go with .... um ..... :name (obvious wins the day over
slickness ; )
> The one remaining issue is what to do about existing indexes that
> aren't declared - it's actually a subset of the larger "what should
> the migration generator do with undeclared fields" issue. But that's
> really a better subject for another post.
Agreed - for now you have to declare them.
Tom