本文整理汇总了Python中alembic.op.bulk_insert方法的典型用法代码示例。如果您正苦于以下问题:Python op.bulk_insert方法的具体用法?Python op.bulk_insert怎么用?Python op.bulk_insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.op
的用法示例。
在下文中一共展示了op.bulk_insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
periodic_table = op.create_table(
'opendaylight_periodic_task',
sa.Column('state', sa.Enum(odl_const.PENDING, odl_const.PROCESSING,
name='state'),
nullable=False),
sa.Column('processing_operation', sa.String(70)),
sa.Column('task', sa.String(70), primary_key=True),
sa.Column('lock_updated', sa.TIMESTAMP, nullable=False,
server_default=sa.func.now(),
onupdate=sa.func.now())
)
op.bulk_insert(periodic_table,
[{'task': 'maintenance',
'state': odl_const.PENDING},
{'task': 'hostconfig',
'state': odl_const.PENDING}])
开发者ID:openstack,项目名称:networking-odl,代码行数:19,代码来源:6f7dfb241354_create_opendaylight_preiodic_task_table.py
示例2: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
# Add collumn redirect_prefix
op.add_column(
u'l7policy',
sa.Column(u'redirect_prefix', sa.String(255), nullable=True)
)
insert_table = sql.table(
u'l7policy_action',
sql.column(u'name', sa.String),
sql.column(u'description', sa.String)
)
op.bulk_insert(
insert_table,
[
{'name': 'REDIRECT_PREFIX'}
]
)
示例3: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
# create basic vars
whiskies = Whisky.query.all()
correlations = list()
data = list()
# loop twice to compare all whiskies
for reference in whiskies:
for whisky in whiskies:
# add correlation if it does not already exists
item = (whisky.id, reference.id)
if item not in correlations and whisky.id != reference.id:
data.append(reference.get_correlation(whisky))
correlations.append(item)
# bulk insert
op.bulk_insert(Correlation.__table__, data)
示例4: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
conn = op.get_bind()
temp_log_table = op.create_table(
'temp_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('result_id', sa.Integer(), nullable=True),
sa.Column('data', sa.LargeBinary(length=2048), nullable=True),
sa.ForeignKeyConstraint(['result_id'], ['result.id'], ),
sa.PrimaryKeyConstraint('id'))
res = conn.execute('SELECT id, result_id, data FROM log')
results = res.fetchall()
if len(results) > 0:
modified_logs = [{
'id': r[0],
'result_id': r[1],
'data': msgpack.packb(json.loads(r[2]), use_bin_type=True)}
for r in results]
op.bulk_insert(temp_log_table, modified_logs)
op.drop_table('log')
op.rename_table('temp_log', 'log')
示例5: downgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def downgrade():
conn = op.get_bind()
temp_log_table = op.create_table(
'temp_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('result_id', sa.Integer(), nullable=True),
sa.Column('data', sa.String(length=1024), nullable=True),
sa.ForeignKeyConstraint(['result_id'], ['result.id'], ),
sa.PrimaryKeyConstraint('id'))
res = conn.execute('SELECT id, result_id, data FROM log')
results = res.fetchall()
if len(results) > 0:
modified_logs = [{
'id': r[0],
'result_id': r[1],
'data': json.dumps(msgpack.unpackb(r[2], raw=False))}
for r in results]
op.bulk_insert(temp_log_table, modified_logs)
op.drop_table('log')
op.rename_table('temp_log', 'log')
示例6: test_bulk_insert_from_new_table
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def test_bulk_insert_from_new_table(self):
context = op_fixture("postgresql", True)
t1 = op.create_table(
"ins_table",
Column("id", Integer),
Column("v1", String()),
Column("v2", String()),
)
op.bulk_insert(
t1,
[
{"id": 1, "v1": "row v1", "v2": "row v5"},
{"id": 2, "v1": "row v2", "v2": "row v6"},
],
)
context.assert_(
"CREATE TABLE ins_table (id INTEGER, v1 VARCHAR, v2 VARCHAR)",
"INSERT INTO ins_table (id, v1, v2) VALUES "
"(1, 'row v1', 'row v5')",
"INSERT INTO ins_table (id, v1, v2) VALUES "
"(2, 'row v2', 'row v6')",
)
示例7: test_bulk_insert_inline_literal
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def test_bulk_insert_inline_literal(self):
class MyType(TypeEngine):
pass
t1 = table("foo", column("id", Integer), column("data", MyType()))
self.op.bulk_insert(
t1,
[
{"id": 1, "data": self.op.inline_literal("d1")},
{"id": 2, "data": self.op.inline_literal("d2")},
],
multiinsert=False,
)
eq_(
self.conn.execute(text("select id, data from foo")).fetchall(),
[(1, "d1"), (2, "d2")],
)
示例8: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
maint_table = op.create_table(
'opendaylight_maintenance',
sa.Column('id', sa.String(36), primary_key=True),
sa.Column('state', sa.Enum(odl_const.PENDING, odl_const.PROCESSING,
name='state'),
nullable=False),
sa.Column('processing_operation', sa.String(70)),
sa.Column('lock_updated', sa.TIMESTAMP, nullable=False,
server_default=sa.func.now(),
onupdate=sa.func.now())
)
# Insert the only row here that is used to synchronize the lock between
# different Neutron processes.
op.bulk_insert(maint_table,
[{'id': uuidutils.generate_uuid(),
'state': odl_const.PENDING}])
示例9: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
# all old rates are going in the bin
conn = op.get_bind()
conn.execute(text("UPDATE letter_rates SET end_date = :start WHERE end_date IS NULL"), start=CHANGEOVER_DATE)
base_prices = {
'second': 30,
'first': 56,
}
op.bulk_insert(LetterRate.__table__, [
{
'id': uuid.uuid4(),
'start_date': CHANGEOVER_DATE,
'end_date': None,
'sheet_count': sheet_count,
'rate': (base_prices[post_class] + (5 * sheet_count)) / 100.0,
'crown': crown,
'post_class': post_class,
}
for sheet_count, crown, post_class in itertools.product(
range(1, 6),
[True, False],
['first', 'second']
)
])
示例10: collect_existing_az_from_services_table
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def collect_existing_az_from_services_table(connection, services_table,
az_table):
az_name_to_id_mapping = dict()
existing_az = []
for service in connection.execute(services_table.select()):
if service.availability_zone in az_name_to_id_mapping:
continue
az_id = uuidutils.generate_uuid()
az_name_to_id_mapping[service.availability_zone] = az_id
existing_az.append({
'created_at': timeutils.utcnow(),
'id': az_id,
'name': service.availability_zone
})
op.bulk_insert(az_table, existing_az)
return az_name_to_id_mapping
示例11: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
### commands auto generated by Alembic - please adjust! ###
role_table = sa.table('role',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(length=80), nullable=False),
sa.Column('description', sa.String(length=255), nullable=True),
sa.Column('parent_id', sa.Integer(), nullable=True),
)
res = op.get_bind().execute('SELECT max(id)+1 FROM role')
cm = 46
for r in res.fetchall():
cm = r[0]
op.bulk_insert(role_table, [
{'id': cm, 'name': 'import_store_data', 'description': u'导入店铺运营数据', 'parent_id': None},
], multiinsert=False)
from sqlalchemy.sql import text
op.get_bind().execute(text("ALTER SEQUENCE role_id_seq RESTART WITH " + str(cm + 1) + ";"))
### end Alembic commands ###
示例12: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
### Caution: Only works in online mode!!!
op.create_table('lecture_assistants',
sa.Column('lecture', sa.Integer(), nullable=False),
sa.Column('assistant', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['assistant'], ['users.id'], ),
sa.ForeignKeyConstraint(['lecture'], ['lectures.id'], ),
sa.PrimaryKeyConstraint('lecture', 'assistant')
)
lectures = sa.sql.table('lectures',
sa.Column('id', sa.Integer),
sa.Column('assistant', sa.Integer)
)
connection = op.get_bind()
results = connection.execute(lectures.select())
ins = []
for res in results:
if res.assistant!=None:
ins.append({'lecture': res.id, 'assistant': res.assistant})
lecture_assistants = sa.sql.table('lecture_assistants',
sa.Column('lecture', sa.Integer(), nullable=False),
sa.Column('assistant', sa.Integer(), nullable=False)
)
if ins:
op.bulk_insert(lecture_assistants,ins)
示例13: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
"""
Performs upgrade of database
"""
comic = table('comic',
sa.Column('name', sa.Text),
sa.Column('type', sa.Text),
sa.Column('channelgid', sa.Text),
sa.Column('lastchecked', sa.Text),
sa.Column('url', sa.Text),
sa.Column('imgxpath', sa.Text),
sa.Column('txtxpath', sa.Text)
)
op.bulk_insert(
comic,
[
{'name': 'garfield', 'type': 'url', 'channelgid': '-1001105187138',
'lastchecked': '1981/01/24',
'url': 'https://s3.amazonaws.com/static.garfield.com/comics/garfield/#year#/#year#-#month#-#day#.gif',
'imgxpath': 'False',
'txtxpath': 'False'}
]
)
示例14: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
"""
Performs upgrade of database
"""
comic = table('comic',
sa.Column('name', sa.Text),
sa.Column('type', sa.Text),
sa.Column('channelgid', sa.Text),
sa.Column('lastchecked', sa.Text),
sa.Column('url', sa.Text)
)
op.bulk_insert(
comic,
[
{'name': 'obichero', 'type': 'rss', 'channelgid': '-1001069507044',
'lastchecked': '1981/01/24',
'url': 'http://obichero.blogspot.com/feeds/posts/default'}
]
)
示例15: upgrade
# 需要导入模块: from alembic import op [as 别名]
# 或者: from alembic.op import bulk_insert [as 别名]
def upgrade():
"""
Performs upgrade of database
"""
comic = table('comic',
sa.Column('name', sa.Text),
sa.Column('type', sa.Text),
sa.Column('channelgid', sa.Text),
sa.Column('lastchecked', sa.Text),
sa.Column('url', sa.Text)
)
op.bulk_insert(
comic,
[
{'name': 'mel', 'type': 'rss', 'channelgid': '-1001105187138',
'lastchecked': '1981/01/24', 'url': 'http://elchistedemel.blogspot.com/feeds/posts/default'}
]
)