Details:
When application is running by IDE generated quick run play button:
It automatically sets working directory to beebot/initiator sub-directory of the repository, because such entry point is located in that directory. At the same time, when yoyo reads migrations:
migrations = read_migrations("migrations")
it does use relative to the working directory path, however, even if such path does not exist, the library silently returns empty MigrationList:
which leads to missing schema and fails later in the code path that accesses the entity.
This approach fails fast preventing application from running on the unexpected working directory.
Alternative approach would be to resolve migrations directory relative to database_models.py:
migrations_dir = "migrations"
models_dir = os.path.dirname(__file__)
migrations = Path(models_dir).parent.parent.resolve().joinpath(migrations_dir).absolute()
if not migrations.exists():
raise FileNotFoundError(f"\"{migrations_dir}\" directory not found. ")
migrations_dir = str(migrations)
migrations = read_migrations(migrations_dir)
With this approach the part responsible for migrations will successfully locate migrations in regardless of working directory:
At the same time, the code becomes coupled to the database_models.py and migrations locations and also does not fix possibility for other places in code to rely on the repository layout.
Best practice in general would be to locate migrations within source code module, so it can be referenced from the source code root as python modules do right now.
Please let me know if this simple fail fast solution enough or you prefer anything else.
tl;dr; Mitigates the issue: https://github.com/AutoPackAI/beebot/issues/17
Details: When application is running by IDE generated quick run play button:
It automatically sets working directory to
beebot/initiator
sub-directory of the repository, because such entry point is located in that directory. At the same time, whenyoyo
reads migrations:it does use relative to the working directory path, however, even if such path does not exist, the library silently returns empty MigrationList: which leads to missing schema and fails later in the code path that accesses the entity.
This approach fails fast preventing application from running on the unexpected working directory.
Alternative approach would be to resolve migrations directory relative to
database_models.py
:With this approach the part responsible for migrations will successfully locate migrations in regardless of working directory: At the same time, the code becomes coupled to the
database_models.py
andmigrations
locations and also does not fix possibility for other places in code to rely on the repository layout.Best practice in general would be to locate migrations within source code module, so it can be referenced from the source code root as python modules do right now.
Please let me know if this simple fail fast solution enough or you prefer anything else.