#✅ Directus with Prisma

16 messages · Page 1 of 1 (latest)

peak knot
#

Is there any guide to doing this?

I found a blog post which outlines the problem quite well:

One of Directus’ most useful features is its ability to directly update your database, [...] and Prisma has a powerful migration engine

Unfortunately, these two methods for updating your database tables directly conflict with each other. Prisma migrations are so strict that if your Directus and Prisma models go out of sync at all, Prisma will insist that you reset your entire database. Ouch.

wraith pewterBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

peak knot
#

I'm using postgres. Is there any way I can put directus' data into a different schema than my Prisma stuff? While still being able to edit my public schema's data (e.g. public."Users" which is created by Prisma)

#

I really don't want to give up the ability to edit my schema.prisma.

Ideally, i'd be able to add/alter tables and columns with prisma, and use Directus solely for data stuff (CRUD)

#

My use-case for Directus is an admin panel

peak knot
#

What I've done for now is set DB_SEARCH_PATH=directus,public. This way, all directus tables will be created in the directus schema, not in public.

Then public will only have my Prisma stuff, and directus my Directus stuff.

For this to work, I had to create a new prisma migration with CREATE SCHEMA IF NOT EXISTS directus

#

Now the only problem is that I can still alter tables/columns from Directus. I want this to be Prisma-first, so if I ever need to alter any tables/columns, I'd do so in my schema.prisma

#

Can I enforce that with RBAC?

And most important of all: is this a good approach?

steep plank
#

Well, you will always be able to edit schema from directus as an admin. so just do not touch that part, only configure interfaces and other meta data. 🙂 I think your approach is good, as directus system tables will receive migrations sometimes when updating directus core and prisma does not like that.

peak knot
#

Even when just updating interfaces/display/metadata, not the column itself

steep plank
#

I responded to your other question about the reason.

#

As an additional idea you could limit the db user of directus and disallow modifying the schema, so prisma is the one and only super db admin. Of course, this causes problems once it wants to apply core migrations, so it is more for a version-locked production environment where it also serves as additional security in case somebody can hack directus and gets admin rights.

peak knot
#

Good idea. I doubt that'll be necessary for us right now, but good to keep in mind

#

We'll just not touch the schema for now :P only interface/display

wraith pewterBOT
#

✅ Directus with Prisma