~olly/yoyo#93: 
Dependencies between sources

Is there a way for a migration to depend on a migration from a different folder?

I'm trying to structure a project in a way that makes sense to my mental model.

I have a folder structure something like the following:

src/
  db/
    main/
      0000__create_schema.sql
      0001__create_some_tables.sql
    cool_feature/
      0000__create_some_cool_feature.sql
      0001__alter_some_cool_feature.sql

Migrations in cool_feature depend on the fundamental stuff from main. I can get yoyo to apply migrations from both, by specifying multiple sources, or by globbing, but I can't seem to get cross-source dependencies to work.

Alternatively, if you think I'm doing something incredibly silly, I'm all ears. Any suggestions on a different project structure, I'm all ears. Because I can't for the life of me find anything on this, on how to make a purely-PostgreSQL project comprehensible from a structural standpoint! ;_;

Status
REPORTED
Submitter
~aksel
Assigned to
No-one
Submitted
1 year, 6 months ago
Updated
1 year, 1 month ago
Labels
No labels applied.

~tiendil 1 year, 1 month ago

I can apply migrations from multiple catalogues specified like this:

sources = %(here)s/src/*/migrations

But can not create new migrations when there is a migration with dependencies in other catalogues.

For example:

yoyo new -m "example-migrations" ./src/some_module/migrations/

Traceback (most recent call last):
  File "/usr/local/bin/yoyo", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/yoyo/scripts/main.py", line 310, in main
    exitcode = args.func(args, config)
  File "/usr/local/lib/python3.10/site-packages/yoyo/scripts/newmigration.py", line 101, in new_migration
    depends = sorted(heads(migrations), key=lambda m: m.id)
  File "/usr/local/lib/python3.10/site-packages/yoyo/migrations.py", line 717, in heads
    heads -= m.depends
  File "/usr/local/lib/python3.10/site-packages/yoyo/migrations.py", line 163, in depends
    self.load()
  File "/usr/local/lib/python3.10/site-packages/yoyo/migrations.py", line 232, in load
    raise exceptions.BadMigration(
yoyo.exceptions.BadMigration: Could not resolve dependencies in ./src/some_module/migrations/20230131_01_SfNSF-order-migration.py

As I understand it is because of how implemented newmigration.py: it does not expect migrations in multiple folders.

Register here or Log in to comment, or comment via email.