Running alembic check in cicd.

This commit is contained in:
Roland 2025-11-29 09:14:32 -07:00
parent 4fae4ae1b4
commit 0181f08bec
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
15 changed files with 174 additions and 43 deletions

10
main.py
View file

@ -32,7 +32,7 @@ logger = logger.getChild('wrolpi-main')
def db_main(args):
"""
Handle database migrations. This uses Alembic, supported commands are "upgrade" and "downgrade".
Handle database migrations. This uses Alembic, supported commands are "upgrade", "downgrade", and "check".
"""
from alembic.config import Config
from alembic import command
@ -48,6 +48,11 @@ def db_main(args):
command.upgrade(config, 'head')
elif args.command == 'downgrade':
command.downgrade(config, '-1')
elif args.command == 'check':
command.check(config)
elif args.command == 'revision':
message = getattr(args, 'message', None) or 'auto migration'
command.revision(config, message=message, autogenerate=True)
else:
print(f'Unknown DB command: {args.command}')
return 2
@ -100,7 +105,8 @@ def main():
# DB Parser for running Alembic migrations
db_parser = sub_commands.add_parser('db')
db_parser.add_argument('command', help='Supported commands: upgrade, downgrade')
db_parser.add_argument('command', help='Supported commands: upgrade, downgrade, check, revision')
db_parser.add_argument('-m', '--message', help='Migration message (for revision command)')
args = parser.parse_args()