def do_upgrade():
    """ Implement your upgrades here  """
    conn = db.engine.connect()

    # Alter tables
    conn.execute("ALTER TABLE pid ADD COLUMN object_type varchar(3) AFTER pid")
    conn.execute(
        "ALTER TABLE pid ADD COLUMN object_id varchar(255) AFTER object_type")
    conn.execute(
        "ALTER TABLE pid ADD INDEX idx_object_type_id (object_type, object_id)"
    )

    # Migrate content
    m = db.MetaData(bind=db.engine)
    m.reflect()

    t = m.tables['pid']
    r = m.tables['pidREGISTRY']

    for otype, oid, pid in db.session.query(r).all():
        stmt = t.update().where(t.c.id == pid).values(object_type=otype,
                                                      object_id=oid)
        conn.execute(stmt)

    # Drop old table
    r.drop()
Beispiel #2
0
def do_upgrade():
    """Upgrade recipe.

    Adds two new columns (password_salt and password_scheme) and migrates
    emails to password salt.
    """
    op.add_column(
        'user', db.Column('password_salt',
                          db.String(length=255),
                          nullable=True))
    op.add_column(
        'user',
        db.Column('password_scheme', db.String(length=50), nullable=False))

    # Temporary column needed for data migration
    op.add_column('user', db.Column('new_password', db.String(length=255)))

    # Migrate emails to password_salt
    m = db.MetaData(bind=db.engine)
    m.reflect()
    u = m.tables['user']

    conn = db.engine.connect()
    conn.execute(
        u.update().values(password_salt=u.c.email,
                          password_scheme='invenio_aes_encrypted_email'))

    # Migrate password blob to password varchar.
    for row in conn.execute(select([u])):
        # NOTE: Empty string passwords were stored as empty strings
        # instead of a hashed version, hence they must be treated differently.
        legacy_pw = row[u.c.password] or mysql_aes_encrypt(row[u.c.email], "")

        stmt = u.update().where(u.c.id == row[u.c.id]).values(
            new_password=hashlib.sha256(legacy_pw).hexdigest())
        conn.execute(stmt)

    # Create index
    op.create_index(op.f('ix_user_password_scheme'),
                    'user', ['password_scheme'],
                    unique=False)

    # Drop old database column and rename new.
    op.drop_column('user', 'password')
    op.alter_column(
        'user',
        'new_password',
        new_column_name='password',
        existing_type=mysql.VARCHAR(255),
        existing_nullable=True,
    )
def do_upgrade():
    """ Implement your upgrades here  """
    m = db.MetaData(bind=db.engine)
    m.reflect()

    tpid = db.Table(
        'pid',
        m,
        db.Column('id', db.Integer(15, unsigned=True), primary_key=True, nullable=False),
        db.Column('type', db.String(length=6), nullable=False),
        db.Column('pid', db.String(length=255), nullable=False),
        db.Column('status', db.Char(length=1), nullable=False),
        db.Column('created', db.DateTime(), nullable=False),
        db.Column('last_modified', db.DateTime(), nullable=False),
        db.Index('uidx_type_pid', 'type', 'pid', unique=True),
        db.Index('idx_status', 'status'),
        mysql_engine='MyISAM',
    )

    tpidlog = db.Table(
        'pidLOG',
        m,
        db.Column('id', db.Integer(15, unsigned=True), primary_key=True, nullable=False),
        db.Column('id_pid', db.Integer(15, unsigned=True), ForeignKey('pid.id')),
        db.Column('timestamp', DateTime(), nullable=False),
        db.Column('action', db.String(length=10), nullable=False),
        db.Column('message', Text(), nullable=False),
        db.Index('idx_action', 'action'),
        mysql_engine='MyISAM',
    )

    tpidregistry = db.Table(
        'pidREGISTRY',
        m,
        db.Column('object_type', db.String(length=3), primary_key=True, nullable=False),
        db.Column('object_id', db.String(length=255), nullable=False),
        db.Column('id_pid', db.Integer(15, unsigned=True), ForeignKey('pid.id'), primary_key=True, nullable=False),
        db.Index('idx_type_id', 'object_type', 'object_id'),
        mysql_engine='MyISAM',
    )

    tpid.create()
    tpidlog.create()
    tpidregistry.create()
Beispiel #4
0
def do_upgrade():
    """Implement your upgrades here."""
    m = db.MetaData(bind=db.engine)
    m.reflect()
    u = m.tables['user']

    conn = db.engine.connect()
    conn.execute(u.update().where(
        u.c.family_name.is_(None)).values(family_name=''))
    conn.execute(u.update().where(
        u.c.given_names.is_(None)).values(given_names=''))

    op.alter_column('user',
                    'family_name',
                    existing_type=mysql.VARCHAR(length=255),
                    nullable=False,
                    server_default='')
    op.alter_column('user',
                    'given_names',
                    existing_type=mysql.VARCHAR(length=255),
                    nullable=False,
                    server_default='')
def do_upgrade():
    """ Implement your upgrades here  """
    m = db.MetaData(bind=db.engine)
    m.reflect()
    t = db.Table(
        'userCOLLECTION',
        m,
        db.Column('id',
                  db.String(length=100),
                  primary_key=True,
                  nullable=False),
        db.Column('id_user',
                  db.Integer(15, unsigned=True),
                  db.ForeignKey('user.id'),
                  nullable=False),
        db.Column('id_collection',
                  db.MediumInteger(9, unsigned=True),
                  db.ForeignKey('collection.id'),
                  nullable=True),
        db.Column('id_collection_provisional',
                  db.MediumInteger(9, unsigned=True),
                  db.ForeignKey('collection.id'),
                  nullable=True),
        db.Column('id_oairepository',
                  db.MediumInteger(9, unsigned=True),
                  db.ForeignKey('oaiREPOSITORY.id'),
                  nullable=True),
        db.Column('title', db.String(length=255), nullable=False),
        db.Column('description', db.Text(), nullable=False),
        db.Column('page', db.Text(), nullable=False),
        db.Column('curation_policy', db.Text(), nullable=False),
        db.Column('has_logo', db.Boolean(), nullable=False),
        db.Column('created', db.DateTime(), nullable=False),
        db.Column('last_modified', db.DateTime(), nullable=False),
        mysql_engine='MyISAM',
    )
    t.create()