Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table.timestamps() creates unusable column names #59

Open
itsthatguy opened this issue Mar 27, 2015 · 4 comments
Open

table.timestamps() creates unusable column names #59

itsthatguy opened this issue Mar 27, 2015 · 4 comments

Comments

@itsthatguy
Copy link

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:

  1. If you haven't yet used table.timestamps():
table.timestamp('createdAt');
table.timestamp('updatedAt');
  1. 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)
  ]);
};
@itsthatguy
Copy link
Author

knex/knex#754

@BlueHotDog
Copy link
Owner

nice catch..
i wonder if we can fix that in some way..

@itsthatguy
Copy link
Author

Might be able to hook into our knex object and overwrite it.

@BlueHotDog
Copy link
Owner

yeah, seems like there is no easy way to configure it..
hmm, we could patch that before it's passed to the function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants