Repository: rucio/rucio
Issue: missing dot in schema in alembic scripts

Motivation
----------
Some alembic scripts on next branch are not working in the new dev environment, because of a missing dot in the schema identifier


Modification
------------
In all the alembic files 
`schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''`
should be 
`schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''`
where schema is used in a string



Changed files:
lib/rucio/db/sqla/migrate_repo/versions/1d96f484df21_asynchronous_rules_and_rule_approval.py
lib/rucio/db/sqla/migrate_repo/versions/1c45d9730ca6_increase_identity_length.py
lib/rucio/db/sqla/migrate_repo/versions/b96a1c7e1cc4_new_bad_pfns_table_and_bad_replicas_.py
lib/rucio/db/sqla/migrate_repo/versions/3152492b110b_added_staging_area_column.py
lib/rucio/db/sqla/migrate_repo/versions/7ec22226cdbf_new_replica_state_for_temporary_.py

diff --git a/lib/rucio/db/sqla/migrate_repo/versions/1c45d9730ca6_increase_identity_length.py b/lib/rucio/db/sqla/migrate_repo/versions/1c45d9730ca6_increase_identity_length.py
index 473261d1e..c19cbb5da 100644
--- a/lib/rucio/db/sqla/migrate_repo/versions/1c45d9730ca6_increase_identity_length.py
+++ b/lib/rucio/db/sqla/migrate_repo/versions/1c45d9730ca6_increase_identity_length.py
@@ -27,8 +27,6 @@ from alembic.op import alter_column, create_check_constraint, create_foreign_key
 revision = '1c45d9730ca6'
 down_revision = 'b4293a99f344'
 
-schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
-
 
 def upgrade():
     '''
@@ -36,6 +34,7 @@ def upgrade():
     '''
 
     if context.get_context().dialect.name in ['oracle', 'postgresql']:
+        schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
         alter_column('tokens', 'identity', existing_type=sa.String(255), type_=sa.String(2048), schema=schema)
         alter_column('identities', 'identity', existing_type=sa.String(255), type_=sa.String(2048), schema=schema)
         alter_column('account_map', 'identity', existing_type=sa.String(255), type_=sa.String(2048), schema=schema)
@@ -97,6 +96,8 @@ def downgrade():
         alter_column('identities', 'identity', existing_type=sa.String(2048), type_=sa.String(255))
 
     elif context.get_context().dialect.name == 'postgresql':
+        schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
+
         execute("DELETE FROM " + schema + "account_map WHERE identity_type='SSH'")  # pylint: disable=no-member
         execute("DELETE FROM " + schema + "identities WHERE identity_type='SSH'")  # pylint: disable=no-member
 
diff --git a/lib/rucio/db/sqla/migrate_repo/versions/1d96f484df21_asynchronous_rules_and_rule_approval.py b/lib/rucio/db/sqla/migrate_repo/versions/1d96f484df21_asynchronous_rules_and_rule_approval.py
index 61528bbb2..afd8beca0 100644
--- a/lib/rucio/db/sqla/migrate_repo/versions/1d96f484df21_asynchronous_rules_and_rule_approval.py
+++ b/lib/rucio/db/sqla/migrate_repo/versions/1d96f484df21_asynchronous_rules_and_rule_approval.py
@@ -30,8 +30,6 @@ from alembic.op import (add_column, create_check_constraint,
 revision = '1d96f484df21'
 down_revision = '3d9813fab443'
 
-schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
-
 
 def upgrade():
     '''
@@ -44,6 +42,7 @@ def upgrade():
         create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')")
 
     elif context.get_context().dialect.name == 'postgresql':
+        schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
         add_column('rules', sa.Column('ignore_account_limit', sa.Boolean(name='RULES_IGNORE_ACCOUNT_LIMIT_CHK'), default=False), schema=schema)
         drop_constraint('RULES_STATE_CHK', 'rules')
         create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O', 'W', 'I')")
@@ -59,6 +58,7 @@ def downgrade():
         create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')")
 
     elif context.get_context().dialect.name == 'postgresql':
+        schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
         drop_column('rules', 'ignore_account_limit', schema=schema[:-1])
         op.execute('ALTER TABLE ' + schema + 'rules DROP CONSTRAINT IF EXISTS "RULES_STATE_CHK", ALTER COLUMN state TYPE CHAR')  # pylint: disable=no-member
         create_check_constraint('RULES_STATE_CHK', 'rules', "state IN ('S', 'R', 'U', 'O')")
diff --git a/lib/rucio/db/sqla/migrate_repo/versions/3152492b110b_added_staging_area_column.py b/lib/rucio/db/sqla/migrate_repo/versions/3152492b110b_added_staging_area_column.py
index 8e523eb66..bd6667912 100644
--- a/lib/rucio/db/sqla/migrate_repo/versions/3152492b110b_added_staging_area_column.py
+++ b/lib/rucio/db/sqla/migrate_repo/versions/3152492b110b_added_staging_area_column.py
@@ -30,8 +30,6 @@ from alembic.op import add_column, create_check_constraint, drop_constraint, dro
 revision = '3152492b110b'
 down_revision = '22cf51430c78'
 
-schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
-
 
 def upgrade():
     '''
@@ -45,6 +43,7 @@ def upgrade():
                                 condition="request_type in ('U', 'D', 'T', 'I', '0')")
 
     elif context.get_context().dialect.name == 'postgresql':
+        schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
         add_column('rses', sa.Column('staging_area', sa.Boolean(name='RSE_STAGING_AREA_CHK'), default=False), schema=schema)
         drop_constraint('REQUESTS_TYPE_CHK', 'requests', type_='check')
         create_check_constraint(constraint_name='REQUESTS_TYPE_CHK', table_name='requests',
@@ -64,6 +63,8 @@ def downgrade():
         drop_column('rses', 'staging_area')
 
     elif context.get_context().dialect.name == 'postgresql':
+        schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
+
         op.execute('ALTER TABLE ' + schema + 'requests DROP CONSTRAINT IF EXISTS "REQUESTS_TYPE_CHK", ALTER COLUMN request_type TYPE CHAR')  # pylint: disable=no-member
         create_check_constraint(constraint_name='REQUESTS_TYPE_CHK', table_name='requests',
                                 condition="request_type in ('U', 'D', 'T')")
diff --git a/lib/rucio/db/sqla/migrate_repo/versions/7ec22226cdbf_new_replica_state_for_temporary_.py b/lib/rucio/db/sqla/migrate_repo/versions/7ec22226cdbf_new_replica_state_for_temporary_.py
index 172a1cf46..39ca33d27 100644
--- a/lib/rucio/db/sqla/migrate_repo/versions/7ec22226cdbf_new_replica_state_for_temporary_.py
+++ b/lib/rucio/db/sqla/migrate_repo/versions/7ec22226cdbf_new_replica_state_for_temporary_.py
@@ -27,8 +27,6 @@ from alembic.op import create_check_constraint, drop_constraint
 revision = '7ec22226cdbf'
 down_revision = '3345511706b8'
 
-schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
-
 
 def upgrade():
     '''
@@ -52,6 +50,7 @@ def downgrade():
                                 condition="state in ('A', 'U', 'C', 'B', 'D', 'S')")
 
     elif context.get_context().dialect.name == 'postgresql':
+        schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
         op.execute('ALTER TABLE ' + schema + 'replicas DROP CONSTRAINT IF EXISTS "REPLICAS_STATE_CHK", ALTER COLUMN state TYPE CHAR')  # pylint: disable=no-member
         create_check_constraint(constraint_name='REPLICAS_STATE_CHK', table_name='replicas',
                                 condition="state in ('A', 'U', 'C', 'B', 'D', 'S')")
diff --git a/lib/rucio/db/sqla/migrate_repo/versions/b96a1c7e1cc4_new_bad_pfns_table_and_bad_replicas_.py b/lib/rucio/db/sqla/migrate_repo/versions/b96a1c7e1cc4_new_bad_pfns_table_and_bad_replicas_.py
index 2d5d3b955..86c0f225b 100644
--- a/lib/rucio/db/sqla/migrate_repo/versions/b96a1c7e1cc4_new_bad_pfns_table_and_bad_replicas_.py
+++ b/lib/rucio/db/sqla/migrate_repo/versions/b96a1c7e1cc4_new_bad_pfns_table_and_bad_replicas_.py
@@ -36,8 +36,6 @@ from rucio.db.sqla.constants import BadPFNStatus
 revision = 'b96a1c7e1cc4'
 down_revision = '1f46c5f240ac'
 
-schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
-
 
 def upgrade():
     '''
@@ -45,6 +43,7 @@ def upgrade():
     '''
 
     if context.get_context().dialect.name in ['oracle', 'postgresql', 'mysql']:
+        schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
         # Create new bad_pfns table
         create_table('bad_pfns',
                      sa.Column('path', sa.String(2048)),
@@ -91,6 +90,8 @@ def downgrade():
         create_primary_key('BAD_REPLICAS_STATE_PK', 'bad_replicas', ['scope', 'name', 'rse_id', 'created_at'])
 
     elif context.get_context().dialect.name == 'postgresql':
+        schema = context.get_context().version_table_schema + '.' if context.get_context().version_table_schema else ''
+
         drop_table('bad_pfns')
         drop_index('BAD_REPLICAS_EXPIRES_AT_IDX', 'bad_replicas')