def do_upgrade():
    """Implement your upgrades here."""
    if exists_id_column():
        warnings.warn(
            """Upgrade skipped. """
            """Column 'id' already exists on accROLE_accACTION_accARGUMENT.""")
        return
    if op.impl.dialect.name != 'mysql':
        warnings.warn("""This upgrade supports only MySQL.""")
        return

    # table accROLE_accACTION_accARGUMENT

    # - drop primary key
    # - add "id" column int(15) unsigned
    # - set "id" as primary key, autoincrement
    # - column id_accROLE, id_accACTION, id_accARGUMENT, argumentlistid server
    #   default = None
    op.execute(
        """
        SET SESSION sql_mode = ANSI_QUOTES;
        ALTER TABLE "accROLE_accACTION_accARGUMENT"
        CHANGE COLUMN "id_accROLE" "id_accROLE" INT(15) UNSIGNED NULL ,
        CHANGE COLUMN "id_accACTION" "id_accACTION" INT(15) UNSIGNED NULL ,
        CHANGE COLUMN "id_accARGUMENT" "id_accARGUMENT" INT(15) NULL ,
        CHANGE COLUMN "argumentlistid" "argumentlistid" MEDIUMINT(8) NULL ,
        ADD COLUMN "id" INT(15) UNSIGNED NOT NULL AUTO_INCREMENT,
        DROP PRIMARY KEY,
        ADD PRIMARY KEY ("id");
        """)
def do_upgrade():
    """Implement your upgrades here."""
    if exists_id_column():
        warnings.warn(
            """Upgrade skipped. """
            """Column 'id' already exists on accROLE_accACTION_accARGUMENT.""")
        return
    if op.impl.dialect.name != 'mysql':
        warnings.warn("""This upgrade supports only MySQL.""")
        return

    # table accROLE_accACTION_accARGUMENT

    # - drop primary key
    # - add "id" column int(15) unsigned
    # - set "id" as primary key, autoincrement
    # - column id_accROLE, id_accACTION, id_accARGUMENT, argumentlistid server
    #   default = None
    op.execute("""
        SET SESSION sql_mode = ANSI_QUOTES;
        ALTER TABLE "accROLE_accACTION_accARGUMENT"
        CHANGE COLUMN "id_accROLE" "id_accROLE" INT(15) UNSIGNED NULL ,
        CHANGE COLUMN "id_accACTION" "id_accACTION" INT(15) UNSIGNED NULL ,
        CHANGE COLUMN "id_accARGUMENT" "id_accARGUMENT" INT(15) NULL ,
        CHANGE COLUMN "argumentlistid" "argumentlistid" MEDIUMINT(8) NULL ,
        ADD COLUMN "id" INT(15) UNSIGNED NOT NULL AUTO_INCREMENT,
        DROP PRIMARY KEY,
        ADD PRIMARY KEY ("id");
        """)
コード例 #3
0
def do_upgrade():
    import invenio
    import sys
    import types

    class CoolDict(dict):
        pass

    class CoolList(list):
        pass

    # Fake old non-existing module
    m = types.ModuleType('invenio.bibfield_utils')
    m.CoolDict = CoolDict
    m.CoolList = CoolList
    sys.modules['invenio.bibfield_utils'] = m
    invenio.bibfield_utils = m

    # Minimal table definitions
    bwlobject = table(
        'bwlOBJECT',
        column('id', db.Integer(primary_key=True)),
        column('extra_data', db.MutableDict.as_mutable(db.PickleType)),
        column('_extra_data', db.LargeBinary()),
        column('_data', db.LargeBinary()),
    )

    bwlworkflow = table(
        'bwlWORKFLOW',
        column('uuid', db.String(36)),
        column('extra_data', db.MutableDict.as_mutable(db.PickleType)),
        column('_extra_data', db.LargeBinary()),
    )

    bwlobjectlogging = table(
        'bwlOBJECTLOGGING',
        column('id_object', db.Integer()),
        column('id_bibworkflowobject', db.Integer()),
    )

    bwlworkflowlogging = table(
        'bwlWORKFLOWLOGGING',
        column('id_object', db.String()),
        column('id_workflow', db.String()),
    )

    conn = op.get_bind()

    # Object table
    op.add_column('bwlOBJECT', db.Column(
                  '_extra_data', db.LargeBinary(), nullable=False))

    query = select(columns=['id', 'extra_data', '_data'], from_obj=bwlobject)
    for r in conn.execute(query):
        # Decode and re-encode old value
        value = base64.b64encode(cPickle.dumps(cPickle.loads(r.extra_data)))
        # Ensure data value can be read
        data_value = base64.b64encode(cPickle.dumps(
            transform_data(cPickle.loads(base64.b64decode(r._data)))
        ))

        # Update value in table.
        op.execute(
            bwlobject.update().where(bwlobject.c.id == r.id).values(
                _extra_data=value,
                _data=data_value,
            )
        )

    op.drop_column('bwlOBJECT', u'extra_data')
    op.alter_column('bwlOBJECT', 'data_type',
                    existing_type=mysql.VARCHAR(length=50),
                    nullable=True)
    op.alter_column('bwlOBJECT', 'id_workflow',
                    existing_type=mysql.VARCHAR(length=36),
                    nullable=True)

    # Workflow table
    op.add_column('bwlWORKFLOW', db.Column(
        '_extra_data', db.LargeBinary(), nullable=False))
    query = select(columns=['uuid', 'extra_data'], from_obj=bwlworkflow)
    for r in conn.execute(query):
        # Decode and re-encode old value
        value = base64.b64encode(cPickle.dumps(cPickle.loads(r.extra_data)))
        # Update value in table.
        op.execute(
            bwlworkflow.update().where(bwlworkflow.c.uuid == r.uuid).values(
                _extra_data=value
            )
        )
    op.drop_column('bwlWORKFLOW', u'extra_data')

    # Object logging
    op.add_column('bwlOBJECTLOGGING', db.Column(
        'id_object', mysql.INTEGER(display_width=255), nullable=False))
    op.execute(
        bwlobjectlogging.update().values({
            bwlobjectlogging.c.id_object:
            bwlobjectlogging.c.id_bibworkflowobject
        })
    )
    op.drop_column('bwlOBJECTLOGGING', u'id_bibworkflowobject')
    op.drop_column('bwlOBJECTLOGGING', u'extra_data')
    op.drop_column('bwlOBJECTLOGGING', u'error_msg')

    # Workflow logging
    op.add_column('bwlWORKFLOWLOGGING', db.Column(
        'id_object', db.String(length=255), nullable=False))
    op.execute(
        bwlworkflowlogging.update().values({
            bwlworkflowlogging.c.id_object:
            bwlworkflowlogging.c.id_workflow
        })
    )
    op.drop_column('bwlWORKFLOWLOGGING', u'id_workflow')
    op.drop_column('bwlWORKFLOWLOGGING', u'extra_data')
    op.drop_column('bwlWORKFLOWLOGGING', u'error_msg')
コード例 #4
0
def do_upgrade():
    import invenio
    import sys
    import types

    class CoolDict(dict):
        pass

    class CoolList(list):
        pass

    # Fake old non-existing module
    m = types.ModuleType('invenio.bibfield_utils')
    m.CoolDict = CoolDict
    m.CoolList = CoolList
    sys.modules['invenio.bibfield_utils'] = m
    invenio.bibfield_utils = m

    # Minimal table definitions
    bwlobject = table(
        'bwlOBJECT',
        column('id', db.Integer(primary_key=True)),
        column('extra_data', db.MutableDict.as_mutable(db.PickleType)),
        column('_extra_data', db.LargeBinary()),
        column('_data', db.LargeBinary()),
    )

    bwlworkflow = table(
        'bwlWORKFLOW',
        column('uuid', db.String(36)),
        column('extra_data', db.MutableDict.as_mutable(db.PickleType)),
        column('_extra_data', db.LargeBinary()),
    )

    bwlobjectlogging = table(
        'bwlOBJECTLOGGING',
        column('id_object', db.Integer()),
        column('id_bibworkflowobject', db.Integer()),
    )

    bwlworkflowlogging = table(
        'bwlWORKFLOWLOGGING',
        column('id_object', db.String()),
        column('id_workflow', db.String()),
    )

    conn = op.get_bind()

    # Object table
    op.add_column('bwlOBJECT',
                  db.Column('_extra_data', db.LargeBinary(), nullable=False))

    query = select(columns=['id', 'extra_data', '_data'], from_obj=bwlobject)
    for r in conn.execute(query):
        # Decode and re-encode old value
        value = base64.b64encode(cPickle.dumps(cPickle.loads(r.extra_data)))
        # Ensure data value can be read
        data_value = base64.b64encode(
            cPickle.dumps(
                transform_data(cPickle.loads(base64.b64decode(r._data)))))

        # Update value in table.
        op.execute(bwlobject.update().where(bwlobject.c.id == r.id).values(
            _extra_data=value,
            _data=data_value,
        ))

    op.drop_column('bwlOBJECT', u'extra_data')
    op.alter_column('bwlOBJECT',
                    'data_type',
                    existing_type=mysql.VARCHAR(length=50),
                    nullable=True)
    op.alter_column('bwlOBJECT',
                    'id_workflow',
                    existing_type=mysql.VARCHAR(length=36),
                    nullable=True)

    # Workflow table
    op.add_column('bwlWORKFLOW',
                  db.Column('_extra_data', db.LargeBinary(), nullable=False))
    query = select(columns=['uuid', 'extra_data'], from_obj=bwlworkflow)
    for r in conn.execute(query):
        # Decode and re-encode old value
        value = base64.b64encode(cPickle.dumps(cPickle.loads(r.extra_data)))
        # Update value in table.
        op.execute(bwlworkflow.update().where(
            bwlworkflow.c.uuid == r.uuid).values(_extra_data=value))
    op.drop_column('bwlWORKFLOW', u'extra_data')

    # Object logging
    op.add_column(
        'bwlOBJECTLOGGING',
        db.Column('id_object',
                  mysql.INTEGER(display_width=255),
                  nullable=False))
    op.execute(bwlobjectlogging.update().values({
        bwlobjectlogging.c.id_object:
        bwlobjectlogging.c.id_bibworkflowobject
    }))
    op.drop_column('bwlOBJECTLOGGING', u'id_bibworkflowobject')
    op.drop_column('bwlOBJECTLOGGING', u'extra_data')
    op.drop_column('bwlOBJECTLOGGING', u'error_msg')

    # Workflow logging
    op.add_column(
        'bwlWORKFLOWLOGGING',
        db.Column('id_object', db.String(length=255), nullable=False))
    op.execute(bwlworkflowlogging.update().values(
        {bwlworkflowlogging.c.id_object: bwlworkflowlogging.c.id_workflow}))
    op.drop_column('bwlWORKFLOWLOGGING', u'id_workflow')
    op.drop_column('bwlWORKFLOWLOGGING', u'extra_data')
    op.drop_column('bwlWORKFLOWLOGGING', u'error_msg')