Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add tests for alembic db script#7234

Open
SegiNyn wants to merge 18 commits intoindico:masterfrom
UNOG-Indico:add-db-test
Open

Add tests for alembic db script#7234
SegiNyn wants to merge 18 commits intoindico:masterfrom
UNOG-Indico:add-db-test

Conversation

@SegiNyn
Copy link
Contributor

@SegiNyn SegiNyn commented Dec 19, 2025

Commands:
For indico: python bin/utils/db_test.py -v --nb-scripts 10
For a plugin: python bin/utils/db_test.py -v --nb-scripts 10 --plugin-dir <plugin-dir>

The script will be added to the ci

The script checks the following:

  1. Revision history has one single head
  2. No orphaned revision were found
  3. Revision history files are properly sorted
  4. Revision hash matches the one in the docstring
  5. Downgrade and upgrade scripts are idempotent

Example Issues

  • One of the scripts was ordered incorrectly so this I just changed the file date to properly order it.
  • because functions were applied directly, the db_test script fails when it gets to the actual script introducing the function at 20250214_1136_c7d6c3641918_add_alternate_names_to_affiliations.py
  • in /20191111_1820_2496c4adc7e9_add_track_principal.py and /20191108_1713_4e459d27adab_add_tables_for_editing_revisions.py enum claasses were imported and used directly instead of creating one in the script to show the current state of the model
  • In the downgrade script at /20240307_1408_b37cbc4bb129_link_events_to_reservation_occurrences.py, index=True should have been included when adding back link_id. (This issue only shows up when the script gets to /20190118_1514_416f9c877300_add_reservationlink_table.py

@github-actions github-actions bot added the alembic Contains database changes label Dec 19, 2025
@SegiNyn SegiNyn force-pushed the add-db-test branch 2 times, most recently from 823b2ff to 020617e Compare December 22, 2025 15:49
@SegiNyn SegiNyn marked this pull request as ready for review December 22, 2025 15:50
Copy link
Member

@OmeGak OmeGak left a comment

Choose a reason for hiding this comment

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

First round of review.

Copy link
Member

Choose a reason for hiding this comment

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

If --plugin-dir is specified but it's different from the current directory, then, the script will fallback to running the test on Indico core. This seems a bug to me. Here's the pseudocode:

if not plugin_dir:
    # Run the tests on Indico core
else:
    if plugin_dir.samefile(os.getcwd()):
        # Run the tests on plugin
    else:
        with _chdir(plugin_dir):
            # Run the tests on plugin

Copy link
Member

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If --plugin-dir is specified but it's different from the current directory, then, the script will fallback to running the test on Indico core

No, it should fall back to running on indico if the plugin_dir is same as current directory. If the plugin directory is not the current indico directory then it should run on the plugin.

Copy link
Member

@OmeGak OmeGak Jan 26, 2026

Choose a reason for hiding this comment

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

The logic that I'm applying now is that --plugin-dir instructs the script to be run for a plugin.

The problem that I was facing is the following.

  1. My current working directory is the plugin directory.
  2. I pass --plugin-dir .
  3. Because plugin_dir is the same as the working directory, the script runs in Indico core mode, failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now raising an exception if the indico directory is passed as the plugin_dir

Copy link
Member

Choose a reason for hiding this comment

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

Can be marked as resolved.

@OmeGak OmeGak force-pushed the add-db-test branch 3 times, most recently from 58b4fdd to 31ab022 Compare January 26, 2026 19:32
@SegiNyn SegiNyn force-pushed the add-db-test branch 2 times, most recently from bd00a95 to ff96572 Compare January 27, 2026 13:19
_run(['psql', DB_NAME, '-c', 'CREATE EXTENSION pg_trgm;'])
_run(['psql', DBDIFF_NAME, '-c', 'CREATE EXTENSION unaccent;'])
_run(['psql', DBDIFF_NAME, '-c', 'CREATE EXTENSION pg_trgm;'])
_run(['indico', 'db', 'prepare'])
Copy link
Member

Choose a reason for hiding this comment

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

Would there be a quicker way to prepare DB? Running indico command is very slow.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

no, as it needs to import all the models etc which is what makes it slow

Comment on lines +359 to +360
# TODO: Is this the best way to get the plugin name?
packages = [x.parent.name for x in plugin_dir.glob('*/__init__.py')]
Copy link
Member

Choose a reason for hiding this comment

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

Is this the best way to get the plugin name?

Copy link
Member

Choose a reason for hiding this comment

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

@SegiNyn SegiNyn force-pushed the add-db-test branch 2 times, most recently from 5c1ca47 to 5fb7456 Compare February 3, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

alembic Contains database changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments