thosakwe / feathers-seeder

Straightforward data seeder for Feathers.js services. Promise-based.
https://docs.feathersjs.com/guides/seeding-services.html
MIT License
38 stars 6 forks source link

Reset autoincrement value for sequelize-adapter #10

Open eikaramba opened 7 years ago

eikaramba commented 7 years ago

The primary field auto increment value is not resetted on delete operation, thus when seeding the app the first time and creating 1 user he will have the id 1. After restarting node.js and seeding again, the database is clean but the id of the user is 2.

Currently with the callback one can store the ids of entities to dynamically set the correct relationships in later services(e.g. if i want to relate an item to the first user i created i need to know the userId). But to make life simpler, it would be great if the auto increment value is resetted, because one can then easier prototype the config, without having to make sure to not use hard-coded ids.

eikaramba commented 7 years ago

One remark: For now i'm just setting the id field manually myself to make sure it has a certain id. So this issue is not on high priority.

thosakwe commented 7 years ago

Perhaps I can add a hooking option to the seed function, like:

const seederConfig = {
  services: [...],
  hooks: {
    after: {
      delete() {
        return new Promise((resolve, reject) => {
          resetAutoIncrement((err) => {
            // ...
          });
        });
      }
    }
  }
};

I want to keep the seeder provider-agnostic, so this would probably be the best method to maintain that.

jamesholcomb commented 7 years ago

I agree with @thosakwe here. feathers-seeder just deals with services and not those types of concerns.

Can you have sequelize drop/create the db before seeding?

eikaramba commented 7 years ago

Sure feathers shouldn't be aware of any implementation details of the service adapters. But the hook would be great!