0

I am using MySQL db with Sails.js (Waterline).

How do I set the initial value for an "id" column in a MySQL table that start from 1000?

attributes: {
  id: {
    type: 'integer'
    // start from 1000
  }
}
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
adnan kamili
  • 8,967
  • 7
  • 65
  • 125
  • 1
    I don't think setting the initial auto-increment value is supported in `sails-mysql`/`waterline`. Perhaps add as issue on Github? – Viktor Oct 16 '16 at 17:47

1 Answers1

0

So you want to

ALTER TABLE model AUTO_INCREMENT = 1000

In waterline you can run this query with the .query() method. However since this query will rebuild your entire table, it is not recommended to be run while bootstrapping your app. Depending on the size of your table it could slow down startup of your app.

Best match would be to somehow hook into the table create event and run above query once or even better: use migrations https://github.com/BlueHotDog/sails-migrations

Further reading:

Community
  • 1
  • 1
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
  • If this query is executed on every startup won't it reset the counter everytime, and id may not be primary key (composite), also shouldn't cb() be inside callback? – adnan kamili Oct 17 '16 at 12:35