Java Spring Boot应用程序:如何在启动时使用flyway创建shema?

Java Spring Boot应用程序:如何在启动时使用flyway创建shema?,java,spring-boot,database-migration,liquibase,flyway,Java,Spring Boot,Database Migration,Liquibase,Flyway,有一个spring引导应用程序。 以下是配置: spring flyway: locations: classpath:db/migration baseline-on-migrate: true schemas: ${app.db.schema} placeholders: schema: ${app.db.schema} init-sqls: CREATE SCHEMA IF NOT EXISTS ${app.db.schema} 但

有一个spring引导应用程序。 以下是配置:

spring
  flyway:
    locations: classpath:db/migration
    baseline-on-migrate: true
    schemas: ${app.db.schema}
    placeholders:
      schema: ${app.db.schema}
    init-sqls: CREATE SCHEMA IF NOT EXISTS ${app.db.schema}
但它不起作用


在flyway运行迁移之前,我需要创建数据库架构。

默认情况下,flyway尝试从
classpath:db/migration
文件夹读取数据库迁移脚本

所有迁移脚本都必须遵循特定的命名约定--
V_uu.sql

src/main/resources/db/migration
目录中创建名为
V1\u\u Create\u Tables.sql的新文件,并添加sql脚本,例如:

-- ----------------------------
-- Schema for helloservice
-- ----------------------------
CREATE SCHEMA IF NOT EXISTS helloworld;
-- ----------------------------
-- Table structure for user
-- ----------------------------
CREATE TABLE helloworld.users (
  id                  BIGSERIAL        PRIMARY KEY NOT NULL UNIQUE,
  username            VARCHAR(255)     UNIQUE NOT NULL,
  password            VARCHAR(255)     NOT NULL,
  first_name          VARCHAR(255),
  middle_name         VARCHAR(255),
  last_name           VARCHAR(255),
  email               VARCHAR(255),
  enabled             bool             NOT NULL DEFAULT true,
  account_locked      bool             NOT NULL,
  account_expired     bool             NOT NULL,
  credential_expired  bool             NOT NULL,
  created_on timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_on timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
COMMENT ON TABLE helloworld.users IS 'User table';
运行应用程序时,flyway将自动检查当前数据库版本并应用任何挂起的迁移。默认情况下,不需要其他属性。您还可以在此脚本中创建架构。或者,如果您指定了一个不存在的方案,flyway将为您执行此操作

如果您使用的是hibernate,请检查此属性:

spring.jpa.hibernate.ddl-auto=validate

有关更多信息,请参阅。

有文档链接:

实际上,FlyWay负责创建不存在的模式

以下是changelog历史记录表中的一个示例: