def _copy_records(destination_table, up_migration=True):
    old = ('volume', '')
    new = ('share', 'spec_')
    data_from, data_to = (old, new) if up_migration else (new, old)
    from_table = table(
        data_from[0] + '_type_extra_specs',
        sa.Column('created_at', sa.DateTime),
        sa.Column('updated_at', sa.DateTime),
        sa.Column('deleted_at', sa.DateTime),
        sa.Column('deleted', sa.Boolean if up_migration else sa.Integer),
        sa.Column('id', sa.Integer, primary_key=True, nullable=False),
        sa.Column(data_from[0] + '_type_id', sa.String(length=36)),
        sa.Column(data_from[1] + 'key', sa.String(length=255)),
        sa.Column(data_from[1] + 'value', sa.String(length=255)))

    extra_specs = []
    for es in op.get_bind().execute(from_table.select()):
        if up_migration:
            deleted = strutils.int_from_bool_as_string(es.deleted)
        else:
            deleted = strutils.bool_from_string(es.deleted, default=True)
        extra_specs.append({
            'created_at': es.created_at,
            'updated_at': es.updated_at,
            'deleted_at': es.deleted_at,
            'deleted': deleted,
            data_to[0] + '_type_id': getattr(es, data_from[0] + '_type_id'),
            data_to[1] + 'key': getattr(es, data_from[1] + 'key'),
            data_to[1] + 'value': getattr(es, data_from[1] + 'value'),
        })
    op.bulk_insert(destination_table, extra_specs)
Example #2
0
def _copy_records(destination_table, up_migration=True):
    old = ('volume', '')
    new = ('share', 'spec_')
    data_from, data_to = (old, new) if up_migration else (new, old)
    from_table = table(
        data_from[0] + '_type_extra_specs',
        sa.Column('created_at', sa.DateTime),
        sa.Column('updated_at', sa.DateTime),
        sa.Column('deleted_at', sa.DateTime),
        sa.Column('deleted', sa.Integer if up_migration else sa.Boolean),
        sa.Column('id', sa.Integer, primary_key=True, nullable=False),
        sa.Column(data_from[0] + '_type_id', sa.String(length=36)),
        sa.Column(data_from[1] + 'key', sa.String(length=255)),
        sa.Column(data_from[1] + 'value', sa.String(length=255)))

    extra_specs = []
    for es in op.get_bind().execute(from_table.select()):
        if up_migration:
            deleted = strutils.int_from_bool_as_string(es.deleted)
        else:
            deleted = strutils.bool_from_string(es.deleted)
        extra_specs.append({
            'created_at': es.created_at,
            'updated_at': es.updated_at,
            'deleted_at': es.deleted_at,
            'deleted': deleted,
            'id': es.id,
            data_to[0] + '_type_id': getattr(es, data_from[0] + '_type_id'),
            data_to[1] + 'key': getattr(es, data_from[1] + 'key'),
            data_to[1] + 'value': getattr(es, data_from[1] + 'value'),
        })
    op.bulk_insert(destination_table, extra_specs)
Example #3
0
 def test_int_from_bool_as_string(self):
     self.assertEqual(1, strutils.int_from_bool_as_string(True))
     self.assertEqual(0, strutils.int_from_bool_as_string(False))
Example #4
0
 def test_int_from_bool_as_string(self):
     self.assertEqual(1, strutils.int_from_bool_as_string(True))
     self.assertEqual(0, strutils.int_from_bool_as_string(False))