refactor: use batch insert for SQLite as well
This commit is contained in:
parent
ac751bacf0
commit
ef3a382669
1 changed files with 8 additions and 18 deletions
|
|
@ -97,23 +97,13 @@ def upgrade() -> None:
|
||||||
|
|
||||||
# Insert into user_tenants table
|
# Insert into user_tenants table
|
||||||
if user_data:
|
if user_data:
|
||||||
if op.get_context().dialect.name == "sqlite":
|
op.bulk_insert(
|
||||||
insert_stmt = user_tenants.insert().values(
|
user_tenants,
|
||||||
[
|
[
|
||||||
{"user_id": user_id, "tenant_id": tenant_id, "created_at": _now()}
|
{"user_id": user_id, "tenant_id": tenant_id, "created_at": _now()}
|
||||||
for user_id, tenant_id in user_data
|
for user_id, tenant_id in user_data
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
conn.execute(insert_stmt)
|
|
||||||
conn.commit()
|
|
||||||
else:
|
|
||||||
op.bulk_insert(
|
|
||||||
user_tenants,
|
|
||||||
[
|
|
||||||
{"user_id": user_id, "tenant_id": tenant_id, "created_at": _now()}
|
|
||||||
for user_id, tenant_id in user_data
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
tenant_id_column = _get_column(insp, "datasets", "tenant_id")
|
tenant_id_column = _get_column(insp, "datasets", "tenant_id")
|
||||||
if not tenant_id_column:
|
if not tenant_id_column:
|
||||||
|
|
@ -141,7 +131,7 @@ def upgrade() -> None:
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table("user_tenants")
|
||||||
op.drop_index(op.f("ix_datasets_tenant_id"), table_name="datasets")
|
op.drop_index(op.f("ix_datasets_tenant_id"), table_name="datasets")
|
||||||
op.drop_column("datasets", "tenant_id")
|
op.drop_column("datasets", "tenant_id")
|
||||||
op.drop_table("user_tenants")
|
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue