How to do database migration using Flyway and SpringBoot

Поделиться
HTML-код
  • Опубликовано: 9 янв 2025

Комментарии • 1

  • @fvhiveproductionsbyLadyAga
    @fvhiveproductionsbyLadyAga  9 месяцев назад

    1. Create Springboot app
    2. Add required maven dependencies
    3. Configure datasource and flyway
    4. Create SQL script
    pom.xml
    -------
    org.flywaydb
    flyway-core

    org.springframework.boot
    spring-boot-starter-jdbc

    org.postgresql
    postgresql
    42.3.9

    application.properties
    ----------------------
    spring.datasource.driverClassName = org.postgresql.Driver
    spring.datasource.url = jdbc:postgresql://localhost:5432/test_db
    spring.datasource.username = root
    spring.datasource.password = root
    spring.datasource.schema = USERSERVICE
    spring.datasource.max-active = 15
    spring.datasource.max-idle = 10
    spring.datasource.max-wait = 8000
    flyway.url = jdbc:postgresql://localhost:5432/test_db
    flyway.schemas = USERSERVICE
    flyway.user = root
    flyway.password = root
    flyway.locations=filesystem:db/migration
    V1_0__create_employee_schema.sql
    --------------------------------
    CREATE TABLE IF NOT EXISTS employee (
    id int NOT NULL,
    name varchar(20),
    email varchar(50),
    date_of_birth timestamp
    );
    INSERT INTO public.employee
    (id, "name", email, date_of_birth)
    VALUES(0, 'ricky', 'ricky@gmail.com', '1990-06-14');
    INSERT INTO public.employee
    (id, "name", email, date_of_birth)
    VALUES(1, 'aga', 'aga@gmail.com', '1995-06-14');