【问题标题】:Specifying Prisma's database name in postgresql在 postgresql 中指定 Prisma 的数据库名称
【发布时间】:2019-03-06 14:13:44
【问题描述】:

我正在尝试实现一个微服务架构,其中每个微服务都有自己的数据库。我使用prisma 作为我的服务和单个 数据库服务器之间的数据访问层。由于我有一个单一的数据库服务器,我希望每个 prisma 实例都能访问它自己在该服务器上的数据库,但我没有找到指定特定 prisma 实例使用的数据库名称的选项。

所以问题来了。有没有办法为 prisma 实例指定数据库名称?

如果有帮助,这是我的 docker-compose.yml 文件:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.14
    restart: always
    ports:
    - "${PRODUCT_PRISMA_PORT}:${PRODUCT_PRISMA_PORT}"
    environment:
      PRISMA_CONFIG: |
        port: ${PRODUCT_PRISMA_PORT}
        managementApiSecret: ${PRODUCT_PRISMA_SECRET}
        databases:
          product:
            connector: postgres
            host: postgres
            port: 5432
            user: prisma
            password: prisma
            migrations: true
  postgres:
    image: postgres:11-alpine
    restart: always
    environment:
      POSTGRES_USER: prisma
      POSTGRES_PASSWORD: prisma
    volumes:
      - /var/lib/postgresql/data
  product-app:
    command: yarn start
    image: product-web
    volumes:
      - ./product-service:/usr/app
    ports:
      - "${PRODUCT_APP_PORT}:${PRODUCT_APP_PORT}"
    depends_on:
      - prisma
    environment:
      PORT: ${PRODUCT_APP_PORT}
      PRISMA_ENDPOINT: ${PRODUCT_PRISMA_ENDPOINT}

【问题讨论】:

    标签: postgresql prisma


    【解决方案1】:

    尝试使用配置中的“数据库”键:

     environment:
      PRISMA_CONFIG: |
        port: ${PRODUCT_PRISMA_PORT}
        managementApiSecret: ${PRODUCT_PRISMA_SECRET}
        databases:
          product:
            connector: postgres
            host: postgres
            port: 5432
            user: prisma
            password: prisma
            migrations: true
            database: ${DATABASE} 
    

    但是,请注意 Prisma 使用pg_advisory_lock 来锁定数据库的独占访问。我不知道这是否会阻止您在不同的 PG 数据库 上运行多个 Prisma 实例,但我强烈建议您尝试使用两个容器设置。如果日志行 Obtaining exclusive agent lock... Successful. 出现在 both 容器日志中,则它可以工作。如果只有Obtaining exclusive agent lock... 挂起,则不会。

    希望对您有所帮助。

    【讨论】:

    • 是的,它有效。看起来锁只适用于数据库,而不是整个服务器。谢谢。
    猜你喜欢
    • 2012-12-17
    • 2011-05-27
    • 1970-01-01
    • 2011-07-17
    • 2011-06-16
    • 2018-01-10
    • 1970-01-01
    • 2023-03-26
    • 2014-11-03
    相关资源
    最近更新 更多