keystone/keystone/common/sql
Stephen Finucane 06b47cbc8d sql: Remove 'get_init_version'
Initializing and synchronizing the database are done using the same
'keystone-manage' command, 'db_sync'. The bulk of this command is
implemented via '_sync_repo' in 'keystone.common.sql.upgrades'. This
calls two functions in 'oslo_db.sqlalchemy.migration':
'db_version_control', which would attempt to mark a database as version
controlled (by creating the 'migrate_version' table in said database),
followed by 'db_sync'. We are passing an 'init_version' argument to the
latter, and this value is cleverly calculated (in the 'get_init_version'
helper) by retrieving the lowest version found in a migration repository.
All of this seems well and good, but upon attempting to raise the
initial version (as part of the upcoming database migration squashing)
we start seeing errors like this:

  oslo_db.exception.DBMigrationError: "Database schema file with version
  1 doesn't exist."

It turns out that the 'init_version' argument here is effectively
useless. The value in providing this argument to the oslo.db's
'db_sync' function is to allow it to optionally mark the database as
version controlled if necessary [1][2], or do what 'db_version_control'
is doing. However, none of the code to do this was being executed
because we were already calling 'db_version_control' manually.

The minimal solution here would be pass an 'init_version' argument to
'db_version_control' instead, ensuring things are initialized with the
correct initial version. However, since we 'db_sync' will do this for
us, we choose instead to remove our invocation of 'db_version_control'
entirely and let 'db_sync' manage everything. We also go a step further
and remove 'get_init_version'. It's clever, but we won't be creating any
new SQLAlchemy-Migrate-based migrations so a simple constant would be
more than okay.

Change-Id: Iad41407e6ad1f9e2f33d228da914a302d4123ecc
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2022-01-19 16:58:16 +00:00
..
contract_repo sql: Rename initial migrations 2022-01-10 18:31:09 +00:00
data_migration_repo sql: Rename initial migrations 2022-01-10 18:31:09 +00:00
expand_repo Add generate schemas tool 2022-01-11 12:21:50 +00:00
__init__.py Safer noqa handling 2014-03-27 18:52:07 -05:00
core.py docs: Fix failing build 2021-07-06 16:22:10 +01:00
upgrades.py sql: Remove 'get_init_version' 2022-01-19 16:58:16 +00:00