0

I'm currently migrating a Rails application running with Mongodb to move to Psql. There are some roadblocks and this is one of them that I'm investigating solutions for. Is there a way to set expiration index on a model attribute or an alternative solution to achieve similar functionality? This is how we have implemented in Mongo,

field :impersonate_token
index({ impersonate_token: 1 }, expire_after_seconds: 60)

This is a custom token with :impersonatable by devise. Please share if you know of a way to achieve this with Postgres.

Thank you.

Coding active
  • 1,620
  • 3
  • 23
  • 40

1 Answers1

0

Postgres doesn't have a counterpart feature.

There is another question quite similar to yours which may help you resolve this issue.

If you don't need to delete the row from your table then you could simply add an expires_at field which you set to the date-time when the token isn't valid anymore. Then you would be able to get the valid tokens by adding the following where method call.

Token.where('expires_at < ?', Time.zone.now)
Community
  • 1
  • 1
Stanko
  • 500
  • 5
  • 13