Skip to content

Commit

Permalink
Add database migrations as an Ant target
Browse files Browse the repository at this point in the history
  • Loading branch information
Etheryte committed Feb 27, 2025
1 parent d178cdd commit c3ebf0d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
Empty file added java/a
Empty file.
55 changes: 47 additions & 8 deletions java/manager-build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<property name="branding.src.dir" value="${basedir}/../branding/java/code/src"/>
<property name="frontend.src.dir" value="${basedir}/../web/html/src"/>
<property name="frontend.dist.dir" value="${basedir}/../web/html/src/dist"/>
<property name="schema.src.dir" value="${basedir}/../schema/spacewalk/upgrade"/>

<property name="ssh.socket.file" value="${user.home}/.ssh/manager-build-tunnel-${deploy.host}-${deploy.user}"/>
<property name="ssh.socket.option" value="-o ControlPath=${ssh.socket.file}"/>
Expand Down Expand Up @@ -119,30 +120,44 @@
</condition>

<!-- macros for deployment -->
<macrodef name="deploy-directory">
<macrodef name="deploy-to-temp-directory">
<attribute name="source"/>
<attribute name="destination"/>
<attribute name="syncParameters" default=""/>
<element name="tasks" implicit="true" optional="true" />
<sequential>
<echo message="Creating temp directory" level="verbose" />
<!-- Define a temporary directory or fallback to /tmp/deploy-dir -->
<local name="deploy.temp.dir" />
<deploy-execute outputProperty="deploy.temp.dir" command="mktemp -d" />
<property name="deploy.temp.dir" value="/tmp/deploy-temp-dir" />

<echo message="Deploying directory @{source} to @{destination} using ${deploy.temp.dir}" />

<!-- Extract to the temporary directory -->
<echo message="Executing sh -c &quot;tar c -C @{source} -f - . | ${deploy.executor.command} ${deploy.executor.parameters} 'tar xf - -C ${deploy.temp.dir}/'&quot;" level="verbose"/>
<exec failonerror="true" executable="sh" logerror="true">
<arg line="-c &quot;tar c -C @{source} -f - . | ${deploy.executor.command} ${deploy.executor.parameters} 'tar xf - -C ${deploy.temp.dir}/ --no-same-owner --no-same-permissions'&quot;"/>
</exec>
<!-- Use rsync to synchronize the folder -->
<deploy-execute command="rsync -a @{syncParameters} ${deploy.temp.dir}/ @{destination}" />
<!-- Remove the temporary stuff -->

<tasks/>

<echo message="Cleaning up temp directory ${deploy.temp.dir}" level="verbose" />
<!-- Cleanup -->
<deploy-execute command="rm -rf ${deploy.temp.dir}" />
</sequential>
</macrodef>

<macrodef name="deploy-directory">
<attribute name="source"/>
<attribute name="destination"/>
<attribute name="syncParameters" default=""/>
<sequential>
<deploy-to-temp-directory source="@{source}">
<echo message="Deploying directory @{source} to @{destination} using ${deploy.temp.dir}" />

<!-- Use rsync to synchronize the folder -->
<deploy-execute command="rsync -a @{syncParameters} ${deploy.temp.dir}/ @{destination}" />
</deploy-to-temp-directory>
</sequential>
</macrodef>

<macrodef name="deploy-execute">
<attribute name="command"/>
<attribute name="outputProperty" default="" />
Expand Down Expand Up @@ -643,4 +658,28 @@
<echo message="This target is obsolete and will be removed. Please use:" />
<echo message=" ant -f manager-build.xml -Ddeploy.mode=container deploy-restart" />
</target>

<target name="apply-schema-migrations" depends="check-deploy-mode, ensure-server-access" description="Apply all available schema migrations">
<echo message="Applying all schema migrations..."/>
<sequential>
<deploy-to-temp-directory source="${schema.src.dir}">
<echo message="Stopping spacewalk-service..." />
<deploy-execute command="spacewalk-service stop" />

<property name="match" value="susemanager-schema-5.*" />
<property name="argline" value="-c &quot;${deploy.executor.command} ${deploy.executor.parameters} 'find ${deploy.temp.dir}/${match} -type f -name &quot;*.sql&quot; -exec spacewalk-sql --select-mode-direct {} \\\;'&quot;" />

<echo message="Finding and applying migrations with:" level="verbose" />
<echo message="${argline}" level="verbose" />
<local name="result" />
<exec failonerror="true" executable="sh" logerror="true" outputproperty="result">
<arg line="${argline}"/>
</exec>
<echo message="${result}" />

<echo message="Starting spacewalk-service..." />
<deploy-execute command="spacewalk-service start" />
</deploy-to-temp-directory>
</sequential>
</target>
</project>

0 comments on commit c3ebf0d

Please sign in to comment.