Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "recursive_version_locations = [false|true]" alembic.ini config #760

Closed
PMLP-novo opened this issue Nov 27, 2020 · 8 comments
Closed
Labels
feature migration environment motivated volunteers requested a feature that has noone to implement; can reopen a 'wontfix'

Comments

@PMLP-novo
Copy link

PMLP-novo commented Nov 27, 2020

Describe your question
I have an applications where the number of migrations we have done goes past 50. So I would like to organize the migrations into a subfolder system inside the alembic versions. When I try to just move the files into subfolders it does not work out of the box any suggestions on how to do this or is this a feature request?

Example of a folder structure

alembic/versions
└───version_0
│ └───relaease_1
│ │ 439873242343_feature_bla_bla.py
│ │ 43987324fwaer_feature_blu_blu.py
└───version_1
│ └───relaease_2
│ │ 439873243243_feature_bi_foo.py
│ │ 43987324ewraer_feature_we_br.py

@PMLP-novo PMLP-novo added the requires triage New issue that requires categorization label Nov 27, 2020
@zzzeek zzzeek added question usage and API questions and removed requires triage New issue that requires categorization labels Nov 27, 2020
@zzzeek
Copy link
Member

zzzeek commented Nov 27, 2020

multiple directories can be set in the config file by naming them separated by a space with the version_locations directive:

https://alembic.sqlalchemy.org/en/latest/branches.html#setting-up-multiple-version-directories

alembic.ini

version_locations  = %(here)/alembic/versions/version_0/release_1  %(here)/alembic/versions/version_1/release/2

when you do this, the "alembic revision" command when asked to create a new file will now require that you also specify --version-path otherwise it won't know where to put the file.

in order to make the above scheme dynamic you would need to build a custom front-end that calls into the Alembic commands with a customized config object: https://alembic.sqlalchemy.org/en/latest/api/commands.html

@PMLP-novo
Copy link
Author

Thank you very much for the answer. It make sense just wondered if it could be a potential feature to be able to specify an option in the alembic.ini
recursivly_search_for_versions=true
So that when set to true. You would search all subfolders for versions. I don't know if it is difficult to make or how much value it would give others. But atleast in my mind it seems like a prettier and easier to maintain solution than the suggested solution.

@zzzeek
Copy link
Member

zzzeek commented Dec 2, 2020

where would the file go when one says "alembic revision" ?

@PMLP-novo
Copy link
Author

PMLP-novo commented Dec 11, 2020

Either just add it to alembic_versions and then people could just move it manually. Or alternatively you could specify alembic revision -m "version_0/release_1/my new feature" or as a new argument alembic revision -m "my new feature" -sub-dir "version_0/release_1" but I don't know if it is posible or fits best in the current api.

@zzzeek zzzeek changed the title How can I make subfolders inside alembic/versions? add "recursive_version_locations = [false|true]" alembic.ini config Dec 11, 2020
@zzzeek zzzeek added feature migration environment motivated volunteers requested a feature that has noone to implement; can reopen a 'wontfix' and removed question usage and API questions labels Dec 11, 2020
@zzzeek
Copy link
Member

zzzeek commented Dec 11, 2020

new files will just go into the folder as they do now. the option indicates to read the directories recursively and that's it.

@sqla-tester
Copy link
Collaborator

ostr00000 has proposed a fix for this issue in the main branch:

add recursive_version_locations option for searching revision files https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4457

@TurnrDev
Copy link

A better solution for this problem would have been to add support for squashing migrations

@CaselIT
Copy link
Member

CaselIT commented Mar 24, 2023

I don't think they are equivalent, especially if transaction_per_migration is used https://alembic.sqlalchemy.org/en/latest/api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure.params.transaction_per_migration

also the normal order resolution apply, so each folder is not run in order

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature migration environment motivated volunteers requested a feature that has noone to implement; can reopen a 'wontfix'
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants