Replaced SQLAlchemy 1.x-style bulk_insert_mappings(model, data) with SQLAlchemy 2.x-style execute(insert(model), data).
This commit is contained in:
parent
1e56403b35
commit
40be3fb664
@ -20,6 +20,7 @@
|
|||||||
import csv
|
import csv
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import sqlalchemy as sa
|
||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
|
|
||||||
from accounting import data_dir
|
from accounting import data_dir
|
||||||
@ -45,7 +46,7 @@ def init_base_accounts_command() -> None:
|
|||||||
"locale": y,
|
"locale": y,
|
||||||
"title": x[f"l10n-{y}"]}
|
"title": x[f"l10n-{y}"]}
|
||||||
for x in data for y in locales]
|
for x in data for y in locales]
|
||||||
db.session.bulk_insert_mappings(BaseAccount, account_data)
|
db.session.execute(sa.insert(BaseAccount), account_data)
|
||||||
db.session.bulk_insert_mappings(BaseAccountL10n, l10n_data)
|
db.session.execute(sa.insert(BaseAccountL10n), l10n_data)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
click.echo("Base accounts initialized.")
|
click.echo("Base accounts initialized.")
|
||||||
|
@ -22,6 +22,7 @@ import os
|
|||||||
import typing as t
|
import typing as t
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import sqlalchemy as sa
|
||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
|
|
||||||
from accounting import db, data_dir
|
from accounting import db, data_dir
|
||||||
@ -77,8 +78,8 @@ def init_currencies_command(username: str) -> None:
|
|||||||
"locale": y,
|
"locale": y,
|
||||||
"name": x[f"l10n-{y}"]}
|
"name": x[f"l10n-{y}"]}
|
||||||
for x in to_add for y in locales]
|
for x in to_add for y in locales]
|
||||||
db.session.bulk_insert_mappings(Currency, currency_data)
|
db.session.execute(sa.insert(Currency), currency_data)
|
||||||
db.session.bulk_insert_mappings(CurrencyL10n, l10n_data)
|
db.session.execute(sa.insert(CurrencyL10n), l10n_data)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
click.echo(F"{len(to_add)} added. Currencies initialized.")
|
click.echo(F"{len(to_add)} added. Currencies initialized.")
|
||||||
|
Loading…
Reference in New Issue
Block a user