changeset 7782:d850a58e6d5f

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.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 30 Jul 2019 23:55:09 +0200
parents 574218777086
children e4f27ab7cbea
files kallithea/alembic/versions/b74907136bc1_create_table_for_ssh_keys.py
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/alembic/versions/b74907136bc1_create_table_for_ssh_keys.py	Wed Sep 27 22:45:28 2017 +0200
+++ b/kallithea/alembic/versions/b74907136bc1_create_table_for_ssh_keys.py	Tue Jul 30 23:55:09 2019 +0200
@@ -29,6 +29,8 @@
 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 @@
     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')