Changeset - d850a58e6d5f
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2019-07-30 23:55:09
mads@kiilerich.com
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.
1 file changed with 9 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/alembic/versions/b74907136bc1_create_table_for_ssh_keys.py
Show inline comments
 
@@ -26,12 +26,14 @@ down_revision = 'ad357ccd9521'
 
branch_labels = None
 
depends_on = None
 

	
 
from alembic import op
 
import sqlalchemy as sa
 

	
 
from kallithea.model import db
 

	
 

	
 
def upgrade():
 
    op.create_table('user_ssh_keys',
 
        sa.Column('user_ssh_key_id', sa.Integer(), nullable=False),
 
        sa.Column('user_id', sa.Integer(), nullable=False),
 
        sa.Column('public_key', sa.UnicodeText(), nullable=False),
 
@@ -43,10 +45,17 @@ def upgrade():
 
        sa.PrimaryKeyConstraint('user_ssh_key_id', name=op.f('pk_user_ssh_keys')),
 
        sa.UniqueConstraint('fingerprint', name=op.f('uq_user_ssh_keys_fingerprint')),
 
    )
 
    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')
 
    op.drop_table('user_ssh_keys')
0 comments (0 inline, 0 general)