Home > Software design >  How can I add a number column that tracks deletions?
How can I add a number column that tracks deletions?

Time:05-08

Is there a gem or some database logic which I can use to add a number column to my database that tracks adds and deletes?

For example, GitHub has issues. An issue has a database ID. But it also has a number which is like a human readable identifier. If an issue is deleted, the number continues to increase. And repo A can have an issue with a number, and that doesn’t conflict with repo B.

CodePudding user response:

Create a new table add a column to the Table like deleteCount. Everytime you call delete function or method. Just add a line that increments deleteCount like deleteCount to the success block. Same goes to the add method.

CodePudding user response:

I believe you are overthinking it. The id column in rails (which all models possess by default) works the way you are thinking.

If you want a more human readable number as well, I would look at this gem (it has a ton of potential uses): https://github.com/norman/friendly_id

  • Related