Skip to content
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 the result of prisma db push without calling it from cli #1049

Open
SMorawiec opened this issue Nov 27, 2024 · 0 comments
Open

create the result of prisma db push without calling it from cli #1049

SMorawiec opened this issue Nov 27, 2024 · 0 comments

Comments

@SMorawiec
Copy link

SMorawiec commented Nov 27, 2024

Problem

I want to write UTs that test interractions with DB. I dont want to use my Dev DB which i use in day-to-day testing and interation.
I want my UT to be isolated, so each UT requires its own DB (inmemory or as file, whatever it means).

I couldnt find a programmatic way to create DB given my schema in tests. I can pass datasource to change DB, but it still requires me to run DB push beforehand to create all the tables.

@pytest_asyncio.fixture
async def session():
    # Create a unique database URL for testing
    test_db_url = "file:./x.db"

    prisma = Prisma(
        datasource={
            "url": test_db_url
        }
    )

    await prisma.connect()

    try:
        yield prisma
    finally:
        await prisma.disconnect()

For this to work, x.db doesnt have to exist, but if you try to actually act on that DB you will get errors as DB does not have proper tables etc.

Suggested solution

add function in python client to do prisma db push programatically

Alternatives

I can call prisma db push programatically using some CLI tool, but it seems pointless as client is right there

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant