gpt4 book ai didi

spring - 在 spring boot 启动时在 postgres 中创建一个模式

转载 作者:行者123 更新时间:2023-11-29 13:42:33 25 4
gpt4 key购买 nike

我需要在 Spring Boot 加载时在 Postgres 中创建一个新模式。因此,它应该检查架构是否不存在,然后创建一个新架构。我正在使用 application.properties 进行数据库配置。

spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://${vcap.services.postgresql-lite.credentials.hostname}:${vcap.services.postgresql-lite.credentials.port}/${vcap.services.postgresql-lite.credentials.dbname}
spring.datasource.username=${vcap.services.postgresql-lite.credentials.username}
spring.datasource.password=${vcap.services.postgresql-lite.credentials.password}
spring.jpa.properties.hibernate.default_schema=${DATABASE_SCHEMA}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

Postgres 使用的默认模式是公共(public)的,我需要更改它来创建我自己的模式,我将在 env 中定义它。

最佳答案

使用以下您的 application.properties 文件:

spring.datasource.initialize=true
spring.datasource.schema=${DB_SCHEMA}

在您的架构文件中添加以下内容:

CREATE TABLE IF NOT EXISTS...

关于spring - 在 spring boot 启动时在 postgres 中创建一个模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53115518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com