view sat/memory/migration/versions/4b002773cf92_add_origin_id_column_to_history_and_.py @ 3914:4cb38c8312a1

plugin XEP-0384, xml_tools: avoid `getItems` timeout + fix empty node crash + parsing: - use `max_items` in `getItems` calls for bundles, as otherwise some pubsub service may return full nodes, which may be huge is `max_items=1` is not set on the node, possibly resulting in timeouts. - the plugin was crashing when TWOMEMO devices list node has no items at all. This is not the case anymore. - a naive parsing method has been implemented in `xml_tools` to replace the serialisation/deserialisation method. This should be more efficient and will avoid annoying `ns0:` prefixes in XML logs.
author Goffi <goffi@goffi.org>
date Sat, 24 Sep 2022 16:37:46 +0200
parents 24c1c06c865b
children
line wrap: on
line source

"""add origin_id column to history and adapt constraints

Revision ID: 4b002773cf92
Revises: 79e5f3313fa4
Create Date: 2022-06-13 16:10:39.711634

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '4b002773cf92'
down_revision = '79e5f3313fa4'
branch_labels = None
depends_on = None


def upgrade():
    with op.batch_alter_table('history', schema=None) as batch_op:
        batch_op.add_column(sa.Column('origin_id', sa.Text(), nullable=True))
        batch_op.create_unique_constraint('uq_origin_id', ['profile_id', 'origin_id', 'source'])

    with op.batch_alter_table('message', schema=None) as batch_op:
        batch_op.alter_column('history_uid',
               existing_type=sa.TEXT(),
               nullable=False)
        batch_op.alter_column('message',
               existing_type=sa.TEXT(),
               nullable=False)

    with op.batch_alter_table('subject', schema=None) as batch_op:
        batch_op.alter_column('history_uid',
               existing_type=sa.TEXT(),
               nullable=False)
        batch_op.alter_column('subject',
               existing_type=sa.TEXT(),
               nullable=False)


def downgrade():
    with op.batch_alter_table('subject', schema=None) as batch_op:
        batch_op.alter_column('subject',
               existing_type=sa.TEXT(),
               nullable=True)
        batch_op.alter_column('history_uid',
               existing_type=sa.TEXT(),
               nullable=True)

    with op.batch_alter_table('message', schema=None) as batch_op:
        batch_op.alter_column('message',
               existing_type=sa.TEXT(),
               nullable=True)
        batch_op.alter_column('history_uid',
               existing_type=sa.TEXT(),
               nullable=True)

    with op.batch_alter_table('history', schema=None) as batch_op:
        batch_op.drop_constraint('uq_origin_id', type_='unique')
        batch_op.drop_column('origin_id')