sqlalchemy / sqlalchemy/alembic
option to print autogenerated revision to stdout
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 375
- PR merge metrics
- No merged PRs in 30d
Description
Migrated issue, originally created by dradetsky (@dradetsky)
Usage would be something like alembic revision --autogenerate --print. The result would be to output the generated python to stdout, rather than creating a revision file. It would probably be a good idea if it supported printing the generated sql, although I never use sql.
There are two reasons this would be desirable:
-
I often work for a while, then generate a revision, forgetting exactly what db changes I've made, so I don't know what I want to put in the message field. So I generate a revision, look it over, delete it, and generate another with
-m. This is annoying. -
I and others I work with sometimes forget to create migrations for db changes we've made. It'd be nice to be able to quickly check if there are unmigrated changes to the model code.
It'd be especially nice if there was some further flag that just prints 'yes' or 'no' (or something like that ; exit 1 maybe?) if there are detected changes to the schema, so it could be made into a commit hook.
As far as I can tell, the right way to do this is to add an arg to _generate_args which would be passed into command.revision and used to set a flag in the ScriptDirectory instance so that the subsequent call to generate_revision uses stdout, but I'm not yet too familiar with the code.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Trace the proposed _generate_args path into command.revision, then inspect how ScriptDirectory and generate_revision create revision files. Define how generated Python, optional SQL, and a change-status result should be exposed without creating a revision file. Done means the CLI behavior and commit-hook check are specified and covered by the relevant tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sql, sqlalchemy
- Domain
- cli, database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100