sails-migrations
sails-migrations copied to clipboard
table.timestamps() creates unusable column names
This is more a knex issue than sails-migrations issue, but wanted to have the issue documented for future users. http://knexjs.org/#Schema-timestamps
Issue:
table.timestamps()
creates created_at
and updated_at
while sails is expecting createdAt
and updatedAt
Resolutions:
- If you haven't yet used
table.timestamps()
:
table.timestamp('createdAt');
table.timestamp('updatedAt');
- If you've already used
table.timestamps()
:
Create a migration for fixing the erroneous columns (sails-migrations generate fix_timestamps
)
'use strict';
exports.up = function(knex, Promise) {
function renameUp(table) {
table.renameColumn('created_at', 'createdAt')
.renameColumn('updated_at', 'updatedAt');
}
Promise.all([
knex.schema.table('myTable', renameUp)
]);
};
exports.down = function(knex, Promise) {
function renameDown(table) {
table.renameColumn('createdAt', 'created_at')
.renameColumn('updatedAt', 'updated_at');
}
Promise.all([
knex.schema.table('myTable', renameDown)
]);
};
https://github.com/tgriesser/knex/issues/754
nice catch.. i wonder if we can fix that in some way..
Might be able to hook into our knex object and overwrite it.
yeah, seems like there is no easy way to configure it.. hmm, we could patch that before it's passed to the function