Refactor database initialization and migrations to SQLAlchemy#2
Merged
edgeinfinity1 merged 1 commit intoJul 10, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Description
maica/initializer/init_db.pyto create MySQL databases via a server-level async engine and to create tables usingSqlBaseAuth.metadata.create_allandSqlBaseData.metadata.create_allthrough SQLAlchemy async engines instead ofConnUtilsraw queries.migration_1.py..migration_4.pyto useDatabaseUtils.engine_data/DatabaseUtils.engine_authwithtext()execution and SQLAlchemy inspection, removingConnUtilsquery_modifycalls and handling MySQL/SQLite syntax differences appropriately.migration_2.pythemv_metatable is created via the ORM table metadata (SqlMvMeta.__table__.create(checkfirst=True)) and MySQL-only ALTERs are executed withtext()when needed.migration_3.pythe presence ofsuspended_untilis detected with SQLAlchemyinspectand the column is added with anALTER TABLEexecuted via the SQLAlchemy connection when missing.migration_4.pyadded helperasync def _create_index_if_missingusing SQLAlchemyinspect(...).get_indexesto avoid duplicate index creation, and applied table ALTERs / index creation through the async engine, preserving MySQL vs SQLite differences.maica/maica_utils/database_models.pyto declare explicit types and constraints (String,Text,Boolean,DateTime), add__table_args__unique constraint forms_cache.hash, and otherwise match the adjusted initializer/migration expectations.Testing
python -m compileall maica/initializer/init_db.py maica/initializer/migrations/migration_1.py maica/initializer/migrations/migration_2.py maica/initializer/migrations/migration_3.py maica/initializer/migrations/migration_4.py maica/maica_utils/database_models.py, which completed successfully.Codex Task