Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding index key in Grails' Domain

I tried following this reference and this is now my domain's code:

class SnbrActVector {

    long nid
    String term
    double weight

    static mapping = {
        version false
        nid index:'Nid_Idx'
    }

    static constraints = {
        term(blank:false)
    }
}

What I want is to do is to add an index key for the nid column. I dropped the existing table and ran the app again so the table is then recreated. However, when I check for list of indices, I can't see an Nid_Idx, only PRIMARY. Do I have to manually create the index and name it Nid_idx in my mysql database?

like image 409
firnnauriel Avatar asked May 04 '10 06:05

firnnauriel


2 Answers

Yes, it's working only when using dbCreate = "create".

Let's say I have an empty database and my dbCreate set to "update". In this case index is not created.

like image 165
Tajul islam Avatar answered Oct 17 '22 09:10

Tajul islam


Your syntax is correct so it might be another problem or a Grails bug. My advice :

  1. Create a new grails application (grails create-app) with SnbrActVector as the only domain (grails create-domain...). Copy your code inside.
  2. Check that your DataSource.groovy file has dbCreate = "create-drop"
  3. Verify the indices of the SnbrActVector table.

If you see an index created for nid column, then it means that there is problem in your application (you might not have used "create-drop" or something else)

If the index is NOT created => This is a grails bug and you should open a JIRA issue here

like image 30
fabien7474 Avatar answered Oct 17 '22 09:10

fabien7474