Skip to content

Conversation

@janbritz
Copy link
Member

@janbritz janbritz commented Dec 4, 2025

Basiert auf questionpy-org/questionpy-server#195

Migrations können folgendermaßen erstellt werden:

from questionpy import Migration, SideMigration


class V1(Migration):
    def upgrade(self):
        self.options["question"] = self.options["old_question"]
        del self.options["old_question"]

        self.state["state"] = "x"


class X(SideMigration, for_namespace="qpy", for_short_name="test", for_state_version=7):
    def sidegrade(self):
        self.options["question"] = self.options["old_question"]
        del self.options["old_question"]

Diese müssen in einem Python-Package mit dem Namen migrations definiert werden. Migrations werden nach dem Namen der Python-Datei, in welcher sie definiert wurden, sortiert. Es können auch mehrere Migrations in einer Datei leben, da zusätzlich auch nach dem Klassen-Name (genauer __qualname__) sortiert wird.

Beim Paketieren wird die state_version basierend auf der Anzahl der Migrations berechnet.

@janbritz janbritz force-pushed the feat/migrations branch 7 times, most recently from 96c78aa to 0190efe Compare December 9, 2025 15:11
@janbritz janbritz marked this pull request as ready for review December 9, 2025 15:17
Copy link
Contributor

@MartinGauk MartinGauk left a comment

Choose a reason for hiding this comment

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

Welchen Vorteil hat es, die einzelnen Migrations in Klassen zu stecken, die nur aus einer Methode bestehen?

# TODO: Log (?) the full exception for further investigations.
raise PackageBuildError(msg) from e

self._manifest.state_version = len(migrations.package)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hier wäre es besser statt nach der Anzahl nach dem höchsten/max Integer zu sehen. Falls man doch alte Migrations mal löscht, sollte das nichts durcheinander bringen.

Copy link
Member Author

Choose a reason for hiding this comment

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

Was genau meinst du mit "höchsten/max Integer"? Ich hatte das damals im Meeting angesprochen, dass wir es erlauben sollten, Migrations zu löschen (Digital Waste / Übersichtlichkeit) - wir sind dann aber zum Schluss gekommen, dass wir das nicht wollen. Mit der jetztigen Implementierung könnten auch alle alten Migrations in einer Datei "versteckt" werden.

except Exception as e:
raise SpecificMigrationFailedError(
e, migration_state.state_version, migration_state.state_version + 1, step
) from e
Copy link
Contributor

Choose a reason for hiding this comment

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

Hier muss es dem Paket möglich sein, eigene Fehlermeldungen zurückzugeben.

Copy link
Member Author

@janbritz janbritz Dec 18, 2025

Choose a reason for hiding this comment

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

Das ist möglich wenn die Exception e vom Typ MigrationNotPossible ist (siehe).

Mir fällt gerade auf das hier SpecificMigrationError besser als SpecificMigrationFailedError passt.

@janbritz janbritz requested a review from MartinGauk December 18, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants