question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to run migrations by code

See original GitHub issue

I have a project with a main database, called general and inside it a table of companies, each company has a different database. My problem is the following, in this project I use the typeorm, but I am considering migrating to the prisma, the problem is that in the typeorm I can run the migrations inside the connection.

await connection.runMigrations({
       transaction: 'all',
});

Is there any way to get it to run in the same way as typeorm here in prisma??

I can connect to another db with a custom url:

import { PrismaClient } from '@prisma/client'

const client1 = new PrismaClient({ datasources: { db: { url: 'postgres://localhost/db1' }} })

https://github.com/prisma/prisma/issues/2443#issuecomment-630679118

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:52
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
kbariotiscommented, Nov 24, 2022

@janpio I have a use case for you. We’re trying out https://github.com/testcontainers/testcontainers-node and we would like each of our test cases to bring up their own containers (postgres in this case), migrate the full database using Prisma programmatic API which will be fed with the temporal hosts/ports given from testcontainers (because it assigns different ones in each container) and then have all test cases run in parallel.

So programmatic access to Prisma will allow us to do that in just a cleaner way instead of running a script directly from the test case. Thanks, hope that makes sense

3reactions
eemelipacommented, Aug 15, 2022

Here’s also older issue related to having programmatic access to the prisma migrator: https://github.com/prisma/prisma/issues/4703

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code-Based Migration in Entity Framework 6
To use code-based migrations, first execute the enable-migrations command in the Package Manager Console. Open the Package Manager Console from Tools ...
Read more >
Code First Migrations - EF6 - Microsoft Learn
Generating & Running Migrations · Run the Update-Database command in Package Manager Console · Code First Migrations will compare the migrations ...
Read more >
Running EFCore Migrations From Your Own Code
A beginner's guide to creating a simple console application that will allow you to run EF Core migrations from your own code.
Read more >
Execute code first migration in code? - Stack Overflow
I think what I have to do is to use migrations for the base entities like Accounts and then run SQL scripts to...
Read more >
Running & Scripting Migrations from Code - romiller.com
Running Migrations from Code. Running migrations is actually very simple. You need to instantiate an instance on the Configuration class that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found