prisma: Multiple datasources not working

I’m following the documentation to target multiple datasources:

datasource postgres {
  provider = "postgres"
  enabled = env("POSTGRES_URL")
  url = env("POSTGRES_URL") 
}

datasource sqlite {
  provider = "sqlite"
  enabled = env("SQLITE_URL")
  url = env("SQLITE_URL")
}
$ echo $POSTGRES_URL
postgresql://peterp:xxx@localhost:5432/peterp?schema=public

$ prisma2 lift up
Error: Error in lift engine for rpc listMigrations:
  thread 'main' panicked at 'loading the connector failed.: DataModelErrors { code: 1001, errors: ["Expected a boolean value, but failed while parsing \"postgresql://peterp:xxx@localhost:5432/peterp?schema=public\": failed to parse bool.", "Environment variable not found: SQLITE_URL."] }', src/libcore/result.rs:997:5
stack backtrace:

Environment variable not found: SQLITE_URL.

$ export SQLITE_URL=false

$ prisma2 lift up
Error: Error in lift engine for rpc listMigrations:
  thread 'main' panicked at 'loading the connector failed.: DataModelErrors { code: 1001, errors: ["Expected a boolean value, but failed while parsing \"postgresql://peterp:xxx@localhost:5432/peterp?schema=public\": failed to parse bool."] }', src/libcore/result.rs:997:5

Expected a boolean value, but failed while parsing \"postgresql://peterp:xxx@localhost:5432/peterp?schema=public\": failed to parse bool."

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 20 (12 by maintainers)

Most upvoted comments

I’ll create a PR later today, if it’s ok.

UPD: #285

@Sytten regardless of your opinion of my dev-setup, the fact remains that the above advice no longer works. I’ll also add that the main point for using prisma, for me, is that it abstracts this stuff away. I haven’t had any issues if I switch database-types in prisma2, I just can’t do it with an env-var (as stated above.) If you look at the database feature support matrix you’ll see that there isn’t any “query optimization” I could even be doing here. It’s basic (shared) types & CRUD, and regardless of which database I use, the syntax to query with prisma is identical. I won’t be using (optional, not implemented) native-types, specifically because I value prisma’s cross-database capabilities, in this situation. What do you even mean by “optimize queries correctly” in this case? Sure, I’d be doing lots of that if I was using raw SQL (I mean even field/value quoting differences between postgres, mysql, and sqlite require some care) but with any multi-database ORM, when you haven’t shot yourself in the foot with native-type requirements, it’s not really a thing. prisma1 could do it fine, as can knex or any other ORM, so it’s not an unreasonable thing to add to this issue.

@Sytten Yeh, I mean I understand what the error message says. It seems like a fairly common need to not use your production database in dev. I’d like to use SQLite locally, so I don’t have to run a postgres server in docker for local dev.

I am pointing out that the above advice doesn’t work (from @peterp), and also that there isn’t an alternative for this use-case.

Multiple datasources are currently not implemented.

Would it make sense to add a note to the docs?

I’ve spent a couple of hours trying to make it work : )

Thats usually not a good idea to change database for local development since each database behave quite differently and it would be hard to optimize queries correctly. Plus with native types on the roadmap I am not sure it would even make sense to support this use case. Its so easy so spawn a DB in docker and most CI platforms have companion services you can launch to do end to end testing.

With the prisma2 init command this is kind of expected as it will try to bootstrap a new project. But I do think a dedicated command for this will add some value.

Right now we are working on a better CLI flow. Please have a look here:https://prisma-specs.netlify.com/cli/

Really love the flow diagram which you guys have here: https://prisma-specs.prisma.now.sh/cli/figma-proxy?id=822:4

Looks like a lot of planning has gone in behind the scenes

@konsumer I think https://github.com/prisma/prisma/issues/1487 will solve your problem. We intend to get rid of provider block entirely and infer database type from url

Seems clear enough, you cannot use env in the provider, its embedded quite deep in the grammar actually.

With the prisma2 init command this is kind of expected as it will try to bootstrap a new project. But I do think a dedicated command for this will add some value.

Right now we are working on a better CLI flow. Please have a look here:https://prisma-specs.netlify.com/cli/

Multiple datasources are currently not implemented. But if you want to switch sources, you are doing it right using environment variables.