Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/lvestats/utils/dbmigrator/versions/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/lvestats/utils/dbmigrator/versions/54d3ae3043dd_snapshot_changes.py

# coding=utf-8
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

from __future__ import absolute_import
import os
import logging
import sqlalchemy as sa
from sqlalchemy.exc import OperationalError
from alembic import op

from lvestats.orm.const import LVE_STATS_2_TABLENAME_PREFIX, SERVER_ID_LENGTH

"""snapshot changes

Revision ID: 54d3ae3043dd
Revises: 15fed017ca0b
Create Date: 2016-08-17 06:13:24.019719

"""

# revision identifiers, used by Alembic.
revision = '54d3ae3043dd'
down_revision = '15fed017ca0b'
branch_labels = None
depends_on = None

INCIDENT_TABLE = LVE_STATS_2_TABLENAME_PREFIX + 'incident'
SNAPSHOT_TABLE = LVE_STATS_2_TABLENAME_PREFIX + 'snapshot'

logger = logging.getLogger('alembic.script.%s' % os.path.basename(__name__))


def upgrade():
    # Lets clean up old data, we will not migrate it on upgrade or downgrade
    op.execute("delete from " + INCIDENT_TABLE)

    op.add_column(INCIDENT_TABLE, sa.Column('dump_time', sa.Integer(), nullable=True))
    op.add_column(INCIDENT_TABLE, sa.Column('snapshot_count', sa.Integer(), nullable=True))
    op.drop_table(SNAPSHOT_TABLE)


def downgrade():
    # due to sqlite not supporting drop column... lets re-create it
    # we wanted to remove data anyway

    op.drop_table(INCIDENT_TABLE)
    op.create_table(INCIDENT_TABLE,
                    sa.Column('uid', sa.INTEGER(), index=True, primary_key=True, autoincrement=False),
                    sa.Column('server_id', sa.VARCHAR(length=SERVER_ID_LENGTH), index=True, primary_key=True),
                    sa.Column('incident_start_time', sa.INTEGER(), index=True, primary_key=True, autoincrement=False),
                    sa.Column('incident_end_time', sa.INTEGER(), index=True)
                    )
    try:
        op.create_table(SNAPSHOT_TABLE,
                        sa.Column('uid', sa.INTEGER(), nullable=False),
                        sa.Column('server_id', sa.VARCHAR(length=255), nullable=False),
                        sa.Column('incident_start_time', sa.INTEGER(), nullable=False),
                        sa.Column('dump_time', sa.INTEGER(), nullable=False),
                        sa.Column('snap_proc', sa.TEXT(), nullable=True),
                        sa.Column('snap_sql', sa.TEXT(), nullable=True),
                        sa.Column('snap_http', sa.TEXT(), nullable=True),
                        sa.Column('snap_faults', sa.TEXT(), nullable=True),
                        sa.PrimaryKeyConstraint('uid', 'server_id', 'incident_start_time', 'dump_time')
                        )
    except OperationalError as ex:
        # for backward compatibility with old lve-create-db (lve-stats <= 2.3-x)
        if 'table {} already exists'.format(SNAPSHOT_TABLE) in ex.message:  # pylint: disable=exception-message-attribute
            logger.warning(str(ex))
        else:
            raise

Hacked By AnonymousFox1.0, Coded By AnonymousFox