-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Create TTL indexes for models #5430
Comments
This would be great. Right now I have an |
TTL functionality would be a really great addition! Providing this with logic as |
Is this something that's supported natively by the MongoDB driver? If so, you could probably use the raw query support we recently released. Not ideal, but might be a decent enough workaround until we support this feature. Let us know! |
Update 2: those who just want to get it done... here
Yes. It is supported by the official driver and mongoose. Update: |
hi! is there still no TTL support for prisma? |
No, otherwise this issue would be closed and we would have documentation for how to use and create them. |
Any update / eta on this feature? |
@janpio, this feature will be implemented in a close future? |
We do not make statements about when features will be tackled until we tackle them. Right now this is not on our definitive roadmap, so we are not making any statements. The original issue asks for support for other databases via constructs like triggers - that is definitely far off, as we are focussing on database features first (which might include the ability to define a trigger like that). For MongoDB where this is a feature of the database itself, I see much higher chances: https://www.mongodb.com/docs/upcoming/core/index-ttl/ I also notice that the suggestion adds a new fiel level property. Would this not be more something to add to |
Related functionality for CockroachDB (which implements this on a table level (which makes a lot more sense than an index to me...)): #13982 |
still wating for this implementation for mongodb TTL |
i come from future(08/23) and they are no updates |
This would be really helpful... right now we rely on a cron to ensure the index is being created in the service that needs it because every new deployment removes the index from the collection... 🤦🏽 |
Any specific reason we are not moving ahead with this ticket? Anyone working on it? Happy to contribute here |
i had to give up on Prisma, currently only using mongodb driver with JSON schemas untill they add this feature, it's very important. P.S. I'm like many of you that keeps constantly ending up in this post checking for news and yet theres nothing .. lol |
Is there any update on this issue? |
I just started out with Prisma, and I need this feature for a task. |
any updates? |
Yeah, we've been following this since a long time ago, currently, we have to run a specific script after model changes to restore the TTL indexes that we are creating manually due to the lack of this crucial feature on the Prisma library |
are we going to get it anytime soon? |
when we are getting this feature? |
Just use MongoDB driver and set TTL on the desired collection and time. Unfortunately, Prisma wont do that update anytime soon. They prioritize SQL, not NoSQL. I already left prisma and only use the mongodb driver with JSON schemas made from zod. |
This would be incredibly useful to have. |
Is there anything new? I'm leaving prism because of this very important role. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Hey everyone I've created my own function that deletes a record using setTimeout. This is the best approach i've found using code, as it is purely async.
|
This solution is real bad, if your service goes down, then the record will stay there forever |
A simple solution might be to just create a cron job that checks if the current time is greater than the deletion time and if it is greater then automatically delete :) |
Problem
Create Time to Live (TTL) indexes on the model and let database do it automatically.
We are currently working on an app using Prisma with Postgres, and we wanted to set expiration time for entries in a row, something already available in Redis, Mongo and also Postgres (using TRIGGERS) or storing a timestamp and then manually code some sort of cron job to check what entries have expired. How to do this is currently not possible with Prisma (unless editing the generated SQL).
In Mongo:
👉 TTL indexes are special single-field indexes that MongoDB can use to automatically remove documents from a collection after a certain amount of time or at a specific clock time.
👉 A background thread in mongod reads the values in the index and removes expired documents from the collection.
Use Cases:
We want data entries/rows to be deleted automatically when the database table starts overflowing and our database memory reaches the max limit after a set time without manually writing cron jobs.
Few types of data that need to be cleaned periodically are:
Consider a coupon generator app with Prisma, with the following schema:
In this case, we want Postgres to set EXPIRE time for each coupon based on a directive @Expire(after: “60s”, when: “useCount>100”) or just delete the affected row after a minute of insertion @Expire(after: “1m”)
Also consider a Chat app using Prisma and Postgres, that allows messages to be deleted 60 seconds after the message is marked as ‘read’ with the following schema:
Suggested solution
Create Time to Live (TTL) indexes on the model and let database do it automatically after a certain amount of time or at a specific clock time. Prisma can then generate Postgres/SQL TRIGGERS based on the
@expire
directive for every model.Alternatives
Our current alternative is using a cron to check for an expiring timestamp - to delete old records, which is heavy on the app. Postgres should be able to handle this seamlessly.
I really think Prisma should provide this sort of functionality, and should be in the roadmap as a feature for future releases.
The text was updated successfully, but these errors were encountered: