Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add database migrations as an Ant target #9823

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Etheryte
Copy link
Member

@Etheryte Etheryte commented Feb 21, 2025

What does this PR change?

Add database migrations as an Ant target. Uses the existing deploy logic, so can be used locally, for a remote, etc.

GUI diff

No difference.

  • DONE

Documentation

  • No documentation needed: only internal and user invisible changes

  • DONE

Test coverage

ℹ️ If a major new functionality is added, it is strongly recommended that tests for the new functionality are added to the Cucumber test suite

  • No tests: build tooling

  • DONE

Links

  • DONE

Changelogs

Make sure the changelogs entries you are adding are compliant with https://github.com/uyuni-project/uyuni/wiki/Contributing#changelogs and https://github.com/uyuni-project/uyuni/wiki/Contributing#uyuni-projectuyuni-repository

If you don't need a changelog check, please mark this checkbox:

  • No changelog needed

If you uncheck the checkbox after the PR is created, you will need to re-run changelog_test (see below)

Re-run a test

If you need to re-run a test, please mark the related checkbox, it will be unchecked automatically once it has re-run:

  • Re-run test "changelog_test"
  • Re-run test "backend_unittests_pgsql"
  • Re-run test "java_pgsql_tests"
  • Re-run test "schema_migration_test_pgsql"
  • Re-run test "susemanager_unittests"
  • Re-run test "javascript_lint"
  • Re-run test "spacecmd_unittests"

Before you merge

Check How to branch and merge properly!

Copy link
Contributor

👋 Hello! Thanks for contributing to our project.
Acceptance tests will take some time (aprox. 1h), please be patient ☕

You can see the progress at the end of this page and at https://github.com/uyuni-project/uyuni/pull/9823/checks
Once tests finish, if they fail, you can check 👀 the cucumber report. See the link at the output of the action.
You can also check the artifacts section, which contains the logs at https://github.com/uyuni-project/uyuni/pull/9823/checks.

If you are unsure the failing tests are related to your code, you can check the "reference jobs". These are jobs that run on a scheduled time with code from master. If they fail for the same reason as your build, it means the tests or the infrastructure are broken. If they do not fail, but yours do, it means it is related to your code.

Reference tests:

KNOWN ISSUES

Sometimes the build can fail when pulling new jar files from download.opensuse.org . This is a known limitation. Given this happens rarely, when it does, all you need to do is rerun the test. Sorry for the inconvenience.

For more tips on troubleshooting, see the troubleshooting guide.

Happy hacking!
⚠️ You should not merge if acceptance tests fail to pass. ⚠️

@Etheryte Etheryte force-pushed the ant-migrations branch 2 times, most recently from 594ace1 to c3ebf0d Compare February 27, 2025 12:41
@Etheryte Etheryte changed the title WIP: Add database migrations as an Ant target Add database migrations as an Ant target Feb 27, 2025
@Etheryte Etheryte marked this pull request as ready for review February 27, 2025 12:43
@Etheryte Etheryte requested a review from a team as a code owner February 27, 2025 12:43
@Etheryte Etheryte requested review from parlt91 and mackdk and removed request for a team February 27, 2025 12:43
Copy link
Contributor

@parlt91 parlt91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this. Only one remark:
I was using ant -f manager-build.xml apply-schema-migrations -Ddeploy.mode=remote-container -Ddeploy.host=<MY_SERVER>
which worked fine.

However it would be nice if we could use the default deploy mode container using the specified CONTAINER_CONNECTION like we do with the deploy target.

@Etheryte
Copy link
Member Author

Hmm, I'm not sure if I understand exactly what you mean @parlt91? The current implementation uses all the same flags and tooling as deploy does as far as I can tell? Or maybe I misunderstand what you mean?

@parlt91
Copy link
Contributor

parlt91 commented Mar 1, 2025

With the deploy-restart target you can set export CONTAINER_CONNECTION=uyuni (used by mgrctl and then call the deploy target without having to specifiy the deploy.host like:

ant -f manager-build.xml -Ddeploy.mode=container refresh-branding-jar deploy-restart

If I try the same with the new apply-schema-migration target I get an error:

ant -f manager-build.xml -Ddeploy.mode=container apply-schema-migrations 

apply-schema-migrations:
     [echo] Applying all schema migrations...
     [echo] Stopping spacewalk-service...
     [exec] find: missing argument to `-exec'

BUILD FAILED
/home/pascal/git/uyuni/java/manager-build.xml:665: The following error occurred while executing this line:
/home/pascal/git/uyuni/java/manager-build.xml:675: exec returned: 1

But in the end this is just some QOL and I don't necessarily see it as a hard requirement

@Etheryte
Copy link
Member Author

Etheryte commented Mar 3, 2025

Hmm, I see, however as is I'm not sure why there's a difference? deploy-restart depends on deploy, restart, and deploy depends on check-deploy-mode, ensure-server-access, webapp. apply-schema-migrations depends on the same first two check-deploy-mode, ensure-server-access, so I would've assumed all the related behaviors to carry across identically. @mackdk do you have ideas perhaps, you are more familiar with this than I am.

Copy link
Contributor

@mackdk mackdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if instead of copying the whole upgrade directory to the server and use find --exec we can instead create a single upgrade script using the <concat> task. In this way we could avoid the -exec escaping problem and just execute a single time spacewalk-sql. Version sorting would still be a problem in plain ant, though, so I doubt we can use a simple to list the files.

<echo message="Stopping spacewalk-service..." />
<deploy-execute command="spacewalk-service stop" />

<property name="match" value="susemanager-schema-5.*" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's probably not possible to do better than this in plain ant, but this is not totally correct and might lead to errors.

Comment on lines +675 to +677
<exec failonerror="true" executable="sh" logerror="true" outputproperty="result">
<arg line="${argline}"/>
</exec>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that the escaping of the \; is only correct when running in remote-container mode. When using a different mode, since the command is not passed around in the same way, find breaks and cannot identify the --exec parameter, as reported by @parlt91.

On top of that, I'm not sure if find is able to sort the directories in the correct order (i.e. 5.0.9 and 5.0.10)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I selected the wrong lines. I was referring to the argline:

<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;" /> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants