Starting from specific base branch, run single branch #983
Replies: 3 comments 18 replies
-
IIUC the merge point has both base1 and base2 as dependencies, so what version would you want it to be on if not the merge point ? |
Beta Was this translation helpful? Give feedback.
-
Heya, just to follow up, this is the code I finally wrote for the automated migration I required (see aiidateam/aiida-core#5330), any feedback would be appreciated 😄 : def migrate(self, debug=False) -> None:
"""Migrate the storage for this profile to the head version.
:raises: :class:`~aiida.common.exceptions.UnreachableStorage` if the storage cannot be accessed
"""
from aiida.cmdline.utils import echo
# the database can be in one of a few states:
# 1. Completely empty -> we can simply initialise it with the current ORM schema
# 2. Legacy django database -> we transfer the version to alembic, migrate to the head of the django branch,
# reset the revision as one on the main branch, and then migrate to the head of the main branch
# 3. Legacy sqlalchemy database -> we migrate to the head of the sqlalchemy branch,
# reset the revision as one on the main branch, and then migrate to the head of the main branch
# 4. Already on the main branch -> we migrate to the head of the main branch
with self._connection_context() as connection:
if not inspect(connection).has_table(self.alembic_version_table):
if not inspect(connection).has_table(self.django_version_table):
# the database is assumed to be empty, so we need to initialise it
echo.echo_report('initialising empty storage schema')
self.initialise(debug=debug)
return
# the database is a legacy django one,
# so we need to copy the version from the 'django_migrations' table to the 'alembic_version' one
legacy_version = self.get_schema_version_profile(connection, check_legacy=True)
# the version should be of the format '00XX_description'
assert legacy_version is not None
assert legacy_version[:4].startswith('00')
version = f'django_{legacy_version[:4]}'
with self._migration_context(connection) as context:
context.stamp(context.script, version)
connection.commit()
# now we can continue with the migration as normal
else:
version = self.get_schema_version_profile(connection)
# find what branch the current version is on
branches = self._alembic_script().revision_map.get_revision(version).branch_labels
if 'django' in branches or 'sqlalchemy' in branches:
# migrate up to the top of the respective legacy branches
if 'django' in branches:
echo.echo_report('Migrating to the head of the legacy django branch')
self.migrate_up('django@head')
elif 'sqlalchemy' in branches:
echo.echo_report('Migrating to the head of the legacy sqlalchemy branch')
self.migrate_up('sqlalchemy@head')
# now re-stamp with the comparable revision on the main branch
with self._connection_context() as connection:
with self._migration_context(connection) as context:
context._ensure_version_table(purge=True) # pylint: disable=protected-access
context.stamp(context.script, 'main_0001')
connection.commit()
# finally migrate to the main head revision
echo.echo_report('Migrating to the head of the main branch')
self.migrate_up('main@head') |
Beta Was this translation helpful? Give feedback.
-
Hi, basically my base(2) and base(n) are squashed versions but i can't get rid of the original base(1) yet as some of my users are still on that route i was wondering if there is some flag or some other concept that could allow me to tell alembic to don't do mergepoint behaviour just traverse the DAG from a given node. i went through this but couldn't find if i can achieve same, https://alembic.sqlalchemy.org/en/latest/branches.html#working-with-multiple-bases
|
Beta Was this translation helpful? Give feedback.
-
Heya, due to legacy reasons, I have two branches (starting from an empty database) that I want to merge into a single main branch going forward:
I added
branch_labels
to the first revision of each branch and, before adding the merge, could run e.g.alembic upgrade base1@head
, to migrate from an empty database up to the head of that branch.After the merge,
base1@head
appears to try to run all the migrations on both branches (firstbase1->head
thenbase2->head
).Am I missing something; how can I tell it to only follow a single branch?
Beta Was this translation helpful? Give feedback.
All reactions