prisma1 icon indicating copy to clipboard operation
prisma1 copied to clipboard

TimeScaleDB connector

Open joshhopkins opened this issue 8 years ago • 6 comments

TimeScaleDB is a very cool Postgres Extension with time-series in mind – http://www.timescale.com

Should technically work out of the box with the Postgres connector. This is a placeholder request if that isn't the case, for any reason.

joshhopkins avatar Jan 17 '18 21:01 joshhopkins

Hi there,

Any status regarding the TimescaleDB connector ?

Even though the PostgreSQL connector should work for Timescale out-of-the-box, what do you think are the changes or constraints to respect for hypertables with Prisma ?

Thanks.

mytototo avatar May 17 '18 07:05 mytototo

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 09 '19 06:01 stale[bot]

Hi, Is timescaledb officially supported by prisma. This thread does not conclude this topic.

ragujayaraj avatar Jul 15 '19 07:07 ragujayaraj

TimescaleDB is actually an extension ontop of PostgreSQL. You can simply use the PostgreSQL connector. It is not too difficult to turn a Prisma generated table into a TimescaleDB hypertable. Here is the process:

Replace your PostgreSQL 10 docker image with: timescale/timescaledb:1.3.2-pg10

Then install TimescaleDB extension for your prisma database.

CREATE EXTENSION timescaledb; 

Run a Prisma migration that creates the table that stores your time series data

datamodel.prisma

type EventTrainer {
  id: Int! @id
  user: User
  time: DateTime! @createdAt
  meta: Json
}

TimescaleDB hypertables PRIMARY KEYs must include all dimensions that you want to partition by. So you have to drop the PRIMARY KEY Prisma generated during the data model migration, and then create one that includes the "time" dimension.

ALTER TABLE "default$default"."EventTrainer" DROP CONSTRAINT "EventTrainer_pkey";

ALTER TABLE "default$default"."EventTrainer" ADD CONSTRAINT "EventTrainer_pkey" PRIMARY KEY("id", "time");

Then convert the table into a hypertable

SELECT * FROM create_hypertable('"default$default"."EventTrainer"', 'time');
  • I am able to insert and query data using Prisma client/bindings just fine with the above hypertable.
  • The @createdAt decorator works and defaults to NOW() as expected.
  • Relation fields work

Nothing really seems to change from how you would normally use Prisma backed by vanilla PostgreSQL. Cheers my friends (-‿◦)

ZenSoftware avatar Jul 15 '19 13:07 ZenSoftware

Thanks for the detailed explanation ZenSoftware! It is fantastic and rest of the reply is coming from a different perspective and in no way disrespecting this approach and your help.

Yes, it is understandable that prisma and TimescaleDB have PostGreSQL in common. However there seems to be manual steps we need to do to make prisma to support TimescaleDB.

But if prisma officially supports TimescaleDB, this manual work will not be required.

Does prisma officially support TimescaleDB today or we need to come up approaches such as what is proposed above. If it does not support today, is there any plan in the near future?

ragujayaraj avatar Jul 16 '19 04:07 ragujayaraj

👋🏽Ajay from TimescaleDB. If there are things we can to do help with this please let us know.

akulkarni avatar Jul 07 '20 19:07 akulkarni