Hi all, I'm trying to make a Date x map to date in...
# questions
p
Hi all, I'm trying to make a Date x map to date in MySQL instead of datetime(6). I tried mapping type, sqlType and formula, none of those are taken by $ grails dbm-gorm-diff (which checks changes on the domain and generates the migration scripts, it's generating just an empty changeSet). What am I doing wrong?
b
you can always use the mapping block on the domain like so
Copy code
static mapping = {
    x(sqlType: 'DATE')
}
Sorry, reread your question and you have already tried that
j
LocalDate x
instead of
Date x
in your domain is the ideal path so precision will be the same in Groovy and MySQL. If you have to use Date, try with lowercase 'date'
static mapping = {
x sqlType: 'date'
}
And maybe it will generate something like the following
changeSet(author: "your-name (generated)", id: "some-unique-id") {
modifyDataType(
columnName: "x",
newDataType: "date",
tableName: "your_domain"
)
}
and if not you will just have to create the migration changeset manually.
❤️ 1
p
I tried to change to LocalDate, the dbm gorm diff doesn't take the change into the changelog, and it's the same with several other changes that I did. There might be something wrong with that specific command not detecting the diffs from the GORM. I needed to create the manual migration:
databaseChangeLog = {
changeSet(author: "pablo (generated)", id: "dvdate-localdate-1") {
grailsChange {
change {
sql.execute("ALTER TABLE dv_date_index MODIFY COLUMN value DATE")
}
rollback {
sql.execute("ALTER TABLE dv_date_index MODIFY COLUMN value DATETIME")
}
}
}
}