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
Copy Markdown
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
Copy Markdown
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.

Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py Outdated
configuration should be done using the various environment variables like
PGHOST, PGPORT and PGUSER) and your `.pgpass` file.
"""
if plugin_dir and not plugin_dir.samefile(os.getcwd()):
Copy link
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py
@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
Comment thread bin/utils/db_test.py
_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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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 thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The most reliable way would be getting it from the pyproject.toml entry point definition. I've seen too many unofficial plugins where people don't care about following our usual plugin naming scheme...

Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py Outdated
Comment thread bin/utils/db_test.py Outdated
@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