Skip to content

Commit

Permalink
Merge pull request #213 from HSF/dev
Browse files Browse the repository at this point in the history
update contents index to avoid too long name
  • Loading branch information
wguanicedew authored Sep 27, 2023
2 parents 70334ec + 26e596b commit e9cd98a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
4 changes: 4 additions & 0 deletions main/etc/sql/postgresql_update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ alter table health add column status INTEGER;
alter table contents_update add column content_metadata VARCHAR(100);
alter table contents_update add column fetch_status INTEGER DEFAULT 0;


-- 2023.09.26
-- update slac idds database, without updating the idds models
alter table contents alter column name type varchar(8000);
2 changes: 1 addition & 1 deletion main/lib/idds/agents/common/plugins/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get_connection(self, destination):
if not conn.is_connected():
# conn.start()
conn.connect(username, password, wait=True)
return conn, queue_dest, destination
return conn, queue_dest, destination
elif self.conns[destination] is None:
return None, None, destination
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0OA
#
# Authors:
# - Wen Guan, <[email protected]>, 2023

"""using hash on contents long name
Revision ID: 1bc6e82e8514
Revises: b0ec813021d6
Create Date: 2023-09-27 09:28:37.068476+00:00
"""
from alembic import op
from alembic import context
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1bc6e82e8514'
down_revision = 'b0ec813021d6'
branch_labels = None
depends_on = None


def upgrade() -> None:
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
try:
op.drop_constraint(constraint_name="CONTENT_ID_UQ", table_name="contents", schema=schema)
except Exception as ex:
print(ex)
try:
op.drop_index(index_name="CONTENTS_ID_NAME_IDX", table_name="contents", schema=schema)
except Exception as ex:
print(ex)

op.create_unique_constraint('CONTENT_ID_UQ', 'contents',
['transform_id', 'coll_id', 'map_id', 'sub_map_id', 'dep_sub_map_id', 'content_relation_type', sa.func.adler32('name'), sa.func.md5('name'), sa.func.hash('name'), 'min_id', 'max_id'],
schema=schema)
op.create_index('CONTENTS_ID_NAME_IDX', 'contents', ['coll_id', 'scope', sa.func.hash('name'), 'status'], schema=schema)


def downgrade() -> None:
if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']:
schema = context.get_context().version_table_schema if context.get_context().version_table_schema else ''
try:
op.drop_constraint(constraint_name="CONTENT_ID_UQ", table_name="contents", schema=schema)
except Exception as ex:
print(ex)
try:
op.drop_index(index_name="CONTENTS_ID_NAME_IDX", table_name="contents", schema=schema)
except Exception as ex:
print(ex)
op.create_unique_constraint('CONTENT_ID_UQ', 'contents', ['transform_id', 'coll_id', 'map_id', 'sub_map_id', 'dep_sub_map_id', 'content_relation_type', 'name', 'min_id', 'max_id'], schema=schema)
op.create_index('CONTENTS_ID_NAME_IDX', 'contents', ['coll_id', 'scope', 'name', 'status'], schema=schema)

0 comments on commit e9cd98a

Please sign in to comment.