alembic: Fix enum creation for dtls_fingerprint
authorGeorge Joseph <gjoseph@digium.com>
Wed, 6 Sep 2017 12:54:00 +0000 (06:54 -0600)
committerGeorge Joseph <gjoseph@digium.com>
Wed, 6 Sep 2017 12:57:31 +0000 (07:57 -0500)
Change-Id: Ic061c5066a146616a68376881c7e4cf6d6e7e7db

contrib/ast-db-manage/config/versions/b83645976fdd_add_dtls_fingerprint_to_ps_endpoints.py

index 0efefa2..3d4f74d 100644 (file)
@@ -14,10 +14,25 @@ from alembic import op
 import sqlalchemy as sa
 from sqlalchemy.dialects.postgresql import ENUM
 
+SHA_HASH_NAME = 'sha_hash_values'
 SHA_HASH_VALUES = ['SHA-1', 'SHA-256']
 
 def upgrade():
-    op.add_column('ps_endpoints', sa.Column('dtls_fingerprint', sa.Enum(*SHA_HASH_VALUES, name='sha_hash_values')))
+    context = op.get_context()
+
+    if context.bind.dialect.name == 'postgresql':
+        enum = ENUM(*SHA_HASH_VALUES, name=SHA_HASH_NAME)
+        enum.create(op.get_bind(), checkfirst=False)
+
+    op.add_column('ps_endpoints',
+             sa.Column('dtls_fingerprint', ENUM(*SHA_HASH_VALUES,
+                 name=SHA_HASH_NAME, create_type=False)))
 
 def downgrade():
+    context = op.get_context()
+
     op.drop_column('ps_endpoints', 'dtls_fingerprint')
+
+    if context.bind.dialect.name == 'postgresql':
+        enum = ENUM(*SHA_HASH_VALUES, name=SHA_HASH_NAME)
+        enum.drop(op.get_bind(), checkfirst=False)