# HG changeset patch # User Mads Kiilerich # Date 2019-07-30 23:55:09 # Node ID d850a58e6d5f68e1089877763489428cccdb6328 # Parent 57421877708614127e677a0a9b849abbf69d951b ssh: add clone_ssh_tmpl setting when migration database for SSH It is slightly dangerous to use the db model in the alembic migration script ... but in this simple case we do it anyway. It is also a bit dirty to modify an existing migration script, but in this case the changes are landing at once and it is only about making the migration process slightly more smooth. diff --git a/kallithea/alembic/versions/b74907136bc1_create_table_for_ssh_keys.py b/kallithea/alembic/versions/b74907136bc1_create_table_for_ssh_keys.py --- a/kallithea/alembic/versions/b74907136bc1_create_table_for_ssh_keys.py +++ b/kallithea/alembic/versions/b74907136bc1_create_table_for_ssh_keys.py @@ -29,6 +29,8 @@ depends_on = None from alembic import op import sqlalchemy as sa +from kallithea.model import db + def upgrade(): op.create_table('user_ssh_keys', @@ -46,6 +48,13 @@ def upgrade(): with op.batch_alter_table('user_ssh_keys', schema=None) as batch_op: batch_op.create_index('usk_fingerprint_idx', ['fingerprint'], unique=False) + session = sa.orm.session.Session(bind=op.get_bind()) + if not session.query(db.Setting).filter(db.Setting.app_settings_name == 'clone_ssh_tmpl').all(): + setting = db.Setting('clone_ssh_tmpl', db.Repository.DEFAULT_CLONE_SSH, 'unicode') + session.add(setting) + session.commit() + + def downgrade(): with op.batch_alter_table('user_ssh_keys', schema=None) as batch_op: batch_op.drop_index('usk_fingerprint_idx')