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

chore: Add option of skipping migrations and using init-db script #19382

Merged
merged 4 commits into from
Dec 5, 2024

Conversation

david-mackessy
Copy link
Contributor

@david-mackessy david-mackessy commented Dec 4, 2024

Problem

It currently takes ~49 seconds for a Postgres integration test to start-up locally, before executing any tests. (Different machines may have different results)
This is not ideal for local development.
Looking into why it takes so long, revealed this info:

15s  for test container to come up
7s   for PostgreSQL base schema init
20s  for migrations to complete
7s   for App to come up
--------------------------------
49s total before test starts

Goal

This PR aims to try to allow quicker running of integration tests locally.
This can be achieved by:

  • updating some config (this PR)
  • supplying an init-db.sql script in dhis2-core/dhis-2/dhis-support/dhis-support-test/src/main/resources/db
  • updating postgresTestDhis.conf test config file with flyway.skip_migration = true

Without supplying this new file or changing the test properties, Flyway and tests operate as they always have. This just gives us the option of running quicker integration tests locally if we choose to.

Using this approach reduces start-up time from ~49 seconds to ~24 seconds.

Applying this setup locally

If this option is to be used, the following steps can be followed:

  • create a new baseline schema (extensions + base schema + migrations). This can be done by:
    • starting up the App locally with an empty DB with extensions already created
    • execute the command pg_dump --schema-only --no-owner dhis2 > ~/Documents/scripts/init-db.sql (dhis2 is the DB name in this command)

Then any time you want to use the new setup:

  • copy the script to the desired directory cp init-db.sql dhis2-core/dhis-2/dhis-support/dhis-support-test/src/main/resources/db
  • and update the test properties as mentioned above
  • revert changes when finished testing

Of course, the init-db.sql would have to be refreshed from time to time (takes a few seconds).

@david-mackessy david-mackessy marked this pull request as ready for review December 4, 2024 14:48
Copy link

sonarcloud bot commented Dec 5, 2024

@david-mackessy david-mackessy merged commit c65e52e into master Dec 5, 2024
16 checks passed
@david-mackessy david-mackessy deleted the skip-migrate-use-db-int branch December 5, 2024 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants