Maintaining Column Positions in Grails / GORM

Is there a way to fix the position of columns in a domain? I have this domain:

class SnbrActVector {

    int nid
    String term
    double weight

    static mapping = {
        version false
        id(generator: 'assigned')
    }

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

This is the schema of the generated table:

CREATE TABLE  `fractor_grailsDEV`.`snbr_act_vector` (
  `id` bigint(20) NOT NULL,
  `weight` double NOT NULL,
  `term` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `nid` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

It seems that the order of the columns has been reversed. Is there any way to do this like this? (the order is nid, term, weight)

CREATE TABLE  `fractor_grailsDEV`.`snbr_act_vector` (
  `id` bigint(20) NOT NULL,
  `nid` int(11) NOT NULL,
  `term` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `weight` double NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
+3
source share
1 answer

It is better not to rely on grails to create tables for you, unless it is in memory / for testing. Use a tool like liquibase to control your circuit.

+3
source

Source: https://habr.com/ru/post/1739954/


All Articles