Custom index names #84

Closed
Soliah opened this Issue Aug 21, 2014 · 7 comments

Comments

Projects
None yet
2 participants
@Soliah

Soliah commented Aug 21, 2014

Is it possible to specify an index name against a field rather than having it default to the field name?

Something like:

field :field1, index: true, name: "index_table_on_field1"
index :field2, name: "index_table_on_field2"
@nviennot

This comment has been minimized.

Show comment
Hide comment
@nviennot

nviennot Aug 21, 2014

Owner

it could be, but it would be quite a bit of work, and I'll have to rethink all the assumptions.
What's the usecase?

Owner

nviennot commented Aug 21, 2014

it could be, but it would be quite a bit of work, and I'll have to rethink all the assumptions.
What's the usecase?

@Soliah

This comment has been minimized.

Show comment
Hide comment
@Soliah

Soliah Aug 21, 2014

It's probably not a really compelling case but:

  1. Providing more meaningful index names where data is being imported from a third party API / source
  2. Being able to impose a consistent index naming scheme

1 is more important for myself as I'm dealing with raw data from embedded devices which don't have very human readable field names. field :naaanraa69_e1_utc, index: true isn't very nice when I need to refer to the index, whereas field :naaanraa69_e1_utc, index: true, name: "index_on_timestamp" is better.

The field names I can alias myself as I can see you're doing a method definition in the source. So alias_method :timestamp, :naaanraa69_e1_utc works well.

Soliah commented Aug 21, 2014

It's probably not a really compelling case but:

  1. Providing more meaningful index names where data is being imported from a third party API / source
  2. Being able to impose a consistent index naming scheme

1 is more important for myself as I'm dealing with raw data from embedded devices which don't have very human readable field names. field :naaanraa69_e1_utc, index: true isn't very nice when I need to refer to the index, whereas field :naaanraa69_e1_utc, index: true, name: "index_on_timestamp" is better.

The field names I can alias myself as I can see you're doing a method definition in the source. So alias_method :timestamp, :naaanraa69_e1_utc works well.

@nviennot

This comment has been minimized.

Show comment
Hide comment
@nviennot

nviennot Aug 21, 2014

Owner

Okay, so we need to have fields and indexes aliases.
I need some time to think about how it's going to play out.

Owner

nviennot commented Aug 21, 2014

Okay, so we need to have fields and indexes aliases.
I need some time to think about how it's going to play out.

@nviennot

This comment has been minimized.

Show comment
Hide comment
@nviennot

nviennot Aug 21, 2014

Owner

The alias_method is not going to work, because you won't be able to use them in queries

Owner

nviennot commented Aug 21, 2014

The alias_method is not going to work, because you won't be able to use them in queries

@nviennot nviennot closed this in b0ed222 Aug 24, 2014

@nviennot

This comment has been minimized.

Show comment
Hide comment
@nviennot

nviennot Aug 24, 2014

Owner

I've implemented the alias feature for fields and indexes.

Here are a couple of examples:

class Model
  field :field1, :as => :f1 # field is stored as f1 in the DB.
  field :field1, :as => :f1, :index => true # both field and index are called f1 in the DB
  field :field1, :index => { :as => :index_f1 } # only the index name changes to index_f1

  # creates a custom named compound index.
  # If field1 or field2 is aliased, the mapping is done properly on the DB.
  index :field12, [:field1, :field2], :as => :compound_index_12
Owner

nviennot commented Aug 24, 2014

I've implemented the alias feature for fields and indexes.

Here are a couple of examples:

class Model
  field :field1, :as => :f1 # field is stored as f1 in the DB.
  field :field1, :as => :f1, :index => true # both field and index are called f1 in the DB
  field :field1, :index => { :as => :index_f1 } # only the index name changes to index_f1

  # creates a custom named compound index.
  # If field1 or field2 is aliased, the mapping is done properly on the DB.
  index :field12, [:field1, :field2], :as => :compound_index_12
@Soliah

This comment has been minimized.

Show comment
Hide comment
@Soliah

Soliah Aug 26, 2014

This is great. Thanks!

Soliah commented Aug 26, 2014

This is great. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment