Skip to content

Conversation

@shlokgilda
Copy link
Collaborator

Description

  • Renames misspelled current_verion column to current_version in repo_deps_libyear table
  • Adds Alembic migration (rev 38) that drops/recreates the explorer_libyear_detail materialized view
  • Updates ORM model, task code, and all schema files for consistency
  • Follow-up to Fixed the Typo in current version #2716 which was closed because it lacked the migration

This PR fixes #2662

Notes for Reviewers
@sgoggins mentioned in #2716 that renaming might require temp tables and data copying. This isn't necessary for PostgreSQL - column renames are simple metadata operations (ALTER TABLE ... RENAME COLUMN). The only complexity is the materialized view that references the column, which we drop and recreate with the corrected name. No data copying involved.

Signed commits

  • Yes, I signed my commits.

AI Disclosure: Used Claude Code to write this PR draft, comments in the alembic migration and verify the migration.

Fixes chaoss#2662

The column 'current_verion' in repo_deps_libyear table was misspelled
(missing 's'). This commit:

- Adds Alembic migration (rev 38) to rename the column
- Drops and recreates explorer_libyear_detail materialized view
- Updates ORM model, task code, and all schema files for consistency

Note: PostgreSQL supports simple column renames via ALTER TABLE,
so no temp tables or data copying is needed.

Signed-off-by: Shlok Gilda <gildashlok@hotmail.com>
@shlokgilda shlokgilda requested a review from sgoggins as a code owner December 19, 2025 01:24
@sgoggins sgoggins self-assigned this Dec 23, 2025
@sgoggins sgoggins added release Related to releasing a new version of Augur tech debt labels Dec 23, 2025
@MoralCode MoralCode added the database Related to Augur's unifed data model label Jan 8, 2026
@MoralCode
Copy link
Contributor

The only complexity is the materialized view that references the column, which we drop and recreate with the corrected name. No data copying involved.

Which view? Are we still using it for anything?

I know on the 8knot side we have wanted to move the 8knot-specifiv mat views over to our 8knot instance for a while. maybe theres a way we can do that more generally, not just in our instance

@MoralCode
Copy link
Contributor

AI Disclosure: Used Claude Code to write this PR draft, comments in the alembic migration and verify the migration.

Did you also run the migration?

Looks like the CI is failing:

Stack Trace
 /augur/.venv/lib/python3.11/site-packages/alembic/ddl/postgresql.py:192: UserWarning: autoincrement and existing_autoincrement only make sense for MySQL
augur-1         |   super().alter_column(
augur-1         | INFO  [alembic.runtime.migration] Running upgrade 37 -> 38, Fix typo in repo_deps_libyear column: current_verion -> current_version
augur-db-1      | 2026-01-07 06:58:51.187 UTC [72] ERROR:  column "current_verion" does not exist
augur-db-1      | 2026-01-07 06:58:51.187 UTC [72] STATEMENT:  
augur-db-1      | 	        ALTER TABLE augur_data.repo_deps_libyear
augur-db-1      | 	        RENAME COLUMN current_verion TO current_version;
augur-db-1      | 	    
augur-1         | Traceback (most recent call last):
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1969, in _exec_single_context
augur-1         |     self.dialect.do_execute(
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 922, in do_execute
augur-1         |     cursor.execute(statement, parameters)
augur-1         | psycopg2.errors.UndefinedColumn: column "current_verion" does not exist
augur-1         | 
augur-1         | 
augur-1         | The above exception was the direct cause of the following exception:
augur-1         | 
augur-1         | Traceback (most recent call last):
augur-1         |   File "/augur/.venv/bin/alembic", line 10, in <module>
augur-1         |     sys.exit(main())
augur-1         |              ^^^^^^
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/alembic/config.py", line 1033, in main
augur-1         |     CommandLine(prog=prog).main(argv=argv)
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/alembic/config.py", line 1023, in main
augur-1         |     self.run_cmd(cfg, options)
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/alembic/config.py", line 957, in run_cmd
augur-1         |     fn(
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/alembic/command.py", line 483, in upgrade
augur-1         |     script.run_env()
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/alembic/script/base.py", line 545, in run_env
augur-1         |     util.load_python_file(self.dir, "env.py")
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/alembic/util/pyfiles.py", line 116, in load_python_file
augur-1         |     module = load_module_py(module_id, path)
augur-1         |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/alembic/util/pyfiles.py", line 136, in load_module_py
augur-1         |     spec.loader.exec_module(module)  # type: ignore
augur-1         |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
augur-1         |   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
augur-1         |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
augur-1         |   File "/augur/augur/application/schema/alembic/env.py", line 116, in <module>
augur-1         |     run_migrations_online()
augur-1         |   File "/augur/augur/application/schema/alembic/env.py", line 110, in run_migrations_online
augur-1         |     context.run_migrations()
augur-1         |   File "<string>", line 8, in run_migrations
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/alembic/runtime/environment.py", line 946, in run_migrations
augur-1         |     self.get_context().run_migrations(**kw)
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/alembic/runtime/migration.py", line 627, in run_migrations
augur-1         |     step.migration_fn(**kw)
augur-1         |   File "/augur/augur/application/schema/alembic/versions/38_fix_libyear_column_typo.py", line 34, in upgrade
augur-1         |     conn.execute(text("""
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1416, in execute
augur-1         |     return meth(
augur-1         |            ^^^^^
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/sql/elements.py", line 516, in _execute_on_connection
augur-1         |     return connection._execute_clauseelement(
augur-1         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1639, in _execute_clauseelement
augur-1         |     ret = self._execute_context(
augur-1         |           ^^^^^^^^^^^^^^^^^^^^^^
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1848, in _execute_context
augur-1         |     return self._exec_single_context(
augur-1         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1988, in _exec_single_context
augur-1         |     self._handle_dbapi_exception(
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 2343, in _handle_dbapi_exception
augur-1         |     raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1969, in _exec_single_context
augur-1         |     self.dialect.do_execute(
augur-1         |   File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 922, in do_execute
augur-1         |     cursor.execute(statement, parameters)
augur-1         | sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column "current_verion" does not exist
augur-1         | 
augur-1         | [SQL: 
augur-1         |         ALTER TABLE augur_data.repo_deps_libyear
augur-1         |         RENAME COLUMN current_verion TO current_version;
augur-1         |     ]

Copy link
Contributor

@MoralCode MoralCode left a comment

Choose a reason for hiding this comment

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

Looks like you may have been a little overzealous with the find and replace.

you got the model change (augur_data.py) and any dependent code changes (core.py) but you only need to add one new migration file. previous migrations are intended to help migrate users from older versions of the DB and should be using the old name since thats what exists in their DBs

Comment on lines 647 to 654
b.current_verion,
b.current_version,
b.latest_version,
b.current_release_date,
b.libyear,
max(b.data_collection_date) AS max
FROM augur_data.repo a,
augur_data.repo_deps_libyear b
GROUP BY a.repo_id, a.repo_name, b.name, b.requirement, b.current_verion, b.latest_version, b.current_release_date, b.libyear
GROUP BY a.repo_id, a.repo_name, b.name, b.requirement, b.current_version, b.latest_version, b.current_release_date, b.libyear
Copy link
Contributor

Choose a reason for hiding this comment

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

old migrations should not be touched. this is probably the source of your CI error

Comment on lines 29 to 41
conn.execute(text("""
DROP MATERIALIZED VIEW IF EXISTS augur_data.explorer_libyear_detail;
"""))

# Step 2: Rename the column (simple metadata operation in PostgreSQL)
conn.execute(text("""
ALTER TABLE augur_data.repo_deps_libyear
RENAME COLUMN current_verion TO current_version;
"""))

# Step 3: Recreate the materialized view with the corrected column name
conn.execute(text("""
CREATE MATERIALIZED VIEW augur_data.explorer_libyear_detail AS
Copy link
Contributor

Choose a reason for hiding this comment

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

im not really a fan of these text-based queries in the migration.

It would be much preferable to use the alembic revision --autogenerate -m "message" command, however, until #3435 is merged, that will cause your migration to contain a lot of unrelated changes

This issue may need to wait until that goes through (unless you want to give it a try and manually remove the unrelated migrations after they are generated)

@shlokgilda
Copy link
Collaborator Author

shlokgilda commented Jan 8, 2026

Hey, sorry about this. Meant to mark this as a draft since I knew there were a couple other PRs with migrations in progress (#3435). Completely lost track of this one over the Christmas break and didn't get around to testing it.

Re: the feedback:

  • Reverted the old migrations (1 and 4) - should be immutable, my apologies
  • Simplified migration 38 significantly - turns out explorer_libyear_detail was already dropped in migration 25 and never recreated, so we don't need any view manipulation. Just a simple column rename now.

Also noticed scripts/control/refresh-matviews.sh still references explorer_libyear_detail - is that intentional or should it be cleaned up?

Still planning to wait for #3435 to land so I can regenerate with autogenerate instead of the text-based queries. Will convert to draft in the meantime.

@shlokgilda shlokgilda marked this pull request as draft January 8, 2026 23:24
Old migrations should be immutable - the typo fix belongs only in
migration 38, not in historical migrations 1 and 4.

Signed-off-by: Shlok Gilda <gildashlok@hotmail.com>
The explorer_libyear_detail view was dropped in migration 25,
so no view manipulation is needed - just rename the column.

Signed-off-by: Shlok Gilda <gildashlok@hotmail.com>
@MoralCode
Copy link
Contributor

Also noticed scripts/control/refresh-matviews.sh still references explorer_libyear_detail - is that intentional or should it be cleaned up?

id say needs cleanup. up to you how to handle.
IMO if its breaking that script, id say make a new PR
if its not going to break that script and is just some old debt that needs cleaning out, maybe its a good first issue that we can leave for a newcomer

@MoralCode MoralCode added the waiting This change is waiting for some other changes to land first label Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

database Related to Augur's unifed data model release Related to releasing a new version of Augur tech debt waiting This change is waiting for some other changes to land first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

repo_deps_libyear column name misspelled

3 participants