Prisma Migrate: programmatic access to CLI commands (deploy, reset...)
See original GitHub issueProblem
It would be nice to have a way to run the migrate programmatically. I am running into an issue where my api is using lambdas (serverless) and my database is only accessible from within an aws vpc. Because of this I cannot “execute commands” on deploy in an easy way. My current solution is to ssh into an ec2 that is within the vpc, execute the prisma commands, and then spin the ec2 back down. While this is working, it is far from ideal. If I was instead able to have a separate lambda that had all the migration data bundled with it I could execute the migration from a lambda (that is within the vpc).
While this may seem like a specialized use case, databases that are not publicly accessible are common place, and solutions for migration that don’t include running npm commands from the cli I think become critical.
Solution
import {migrate} from '@prisma/cli';
migrate('up');
Alternatives
Stated above, no great alternatives for common usecases.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:268
- Comments:67 (11 by maintainers)
Recently I was working on Knex Migration API. Prisma Migration can benefit heavily if it can be run programmatically completely. That is:
This enables complete end-to-end functionality such as:
The migrations, if required, could be stored inside the database itself as
meta
tables and expose it to the user to rollback or migrate up inside Web UI. Or they could be stored or S3 or similar, based on user-configured storage systems inside their application. Or no storage at all, it could all be in memory.Prisma can expose base Migrate Storage interface and users can be allowed to implement their custom sources.
I had some thoughts on this feature and already shared them with @albertoperdomo from the Prisma team. To me, a very essential feature that would be possible with this addition would be to run a custom seeder. Imagine freshly deploying the app onto a server, and when it detects that there are 0 migrations in the database yet, it runs a custom function creating some essential entries.
Imagine something like this: