Git Product home page Git Product logo

Comments (3)

liemle3893 avatar liemle3893 commented on July 25, 2024 1

Here is my solution:
Environment
Gradle version: 4.1
Plugin version: 1.2.4

build.gradle:

def changeLog = "$projectDir/src/main/resources/db/db.changelog-master.xml"

def getProperties(environment) {
    Properties properties = new Properties()
    File propertiesFile = new File("$projectDir/.environment/${environment}.properties")
    propertiesFile.withInputStream {
        properties.load(it)
    }
    return properties
}

task dbMigration {
    doLast {
        def environment = System.properties['APP_ENV'] ?: 'local'
        println "Migrating ${environment}..."
        def properties = getProperties(environment)

        liquibase {
            activities {
                main {
                    changeLogFile changeLog
                    classpath "$projectDir/src/main/resources/"
                    url properties.jdbcUrl
                    username properties.username
                    password properties.password
                }
            }
        }
    }
}

db.changelog-master.xml:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
		xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
	<include file="db/changelog/V_20180429165618__db.changelog-create-short-video-table.xml"/>
	<include file="db/changelog/V_20180429165618__db.changelog-create-video-metadata-table.xml"/>
	<include file="db/changelog/V_20180501121226__db.changelog-create-trigger-after-insert-video.xml"/>
</databaseChangeLog>

Structure:

        └── resources
            └── db
                ├── changelog
                │   ├── V_20180429165618__db.changelog-create-short-video-table.xml
                │   ├── V_20180429165618__db.changelog-create-video-metadata-table.xml
                │   └── V_20180501121226__db.changelog-create-trigger-after-insert-video.xml
                ├── db.changelog-master.xml
                ├── generator.py
                └── sql
                    ├── V_20180501121226__IncreaseStoredProcedure_1.sql
                    └── V_20180501121226__create_metadata_after_insert_video.sql

And then:

gradle -DAPP_ENV=development dbMigration dropAll update

NOTE:

  1. classpath is important
  2. Do not use relativeToChangelogFile
  3. XML/Groovy/ Etc.. doesn't matter, choose one which fit you. XML Fit me well when using IDEA, there're autocompletion.

from liquibase-gradle-plugin.

stevesaliman avatar stevesaliman commented on July 25, 2024

Is there a publicly available project that exhibits this behavior? I don't have any projects locally that call liquibase on startup.

The gradle plugin doesn't decide how the filenames show up in the database, so my hunch is that this is in Liquibase itself, but I'd be interested in tracing this through the liquibase groovy dsl to see how it is being asked to load the file during application startup - I might be able to get the plugin to do the same.

from liquibase-gradle-plugin.

stevesaliman avatar stevesaliman commented on July 25, 2024

Closed due to inactivity, and the fact that later versions of Liquibase have changed how files are handled. If this is still an issue with the latest versions of Liquibase and the plugin, we can always open a new issue.

from liquibase-gradle-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.