Migrate contracts
This commit is contained in:
@ -9,9 +9,9 @@ import csv
|
||||
|
||||
|
||||
TABLES = ['branch', 'wb_gl', 'wb_kg', 'wb_rd', 'wine_attribute', 'wine_cultivation',
|
||||
'member', 'member_billing_address', 'contract', 'area_commitment',
|
||||
'season', 'modifier', 'delivery', 'delivery_part', 'delivery_part_modifier',
|
||||
'payment_variant', 'delivery_payment', 'member_payment']
|
||||
'member', 'member_billing_address', 'contract', 'area_commitment', ]
|
||||
# 'season', 'modifier', 'delivery', 'delivery_part', 'delivery_part_modifier',
|
||||
# 'payment_variant', 'delivery_payment', 'member_payment']
|
||||
|
||||
|
||||
def get_sql_files() -> List[str]:
|
||||
@ -51,6 +51,7 @@ def import_csv(cur: sqlite3.Cursor, table_name: str) -> None:
|
||||
sql = f'INSERT INTO {table_name} ({", ".join(names)}) VALUES ({", ".join(["?"] * len(names))})'
|
||||
print(sql)
|
||||
cur.executemany(sql, values)
|
||||
print(f'{len(values)} inserts')
|
||||
|
||||
cur.close()
|
||||
|
||||
@ -81,8 +82,15 @@ if __name__ == '__main__':
|
||||
DB_CNX.executescript(sql_file.read())
|
||||
|
||||
try:
|
||||
DB_CNX.isolation_level = None
|
||||
DB_CNX.execute("PRAGMA foreign_keys = OFF")
|
||||
DB_CNX.execute("BEGIN")
|
||||
for table in TABLES:
|
||||
import_csv(DB_CNX.cursor(), table)
|
||||
DB_CNX.commit()
|
||||
DB_CNX.execute("COMMIT")
|
||||
except Exception as err:
|
||||
DB_CNX.execute("ROLLBACK")
|
||||
raise err
|
||||
finally:
|
||||
DB_CNX.execute("PRAGMA foreign_keys = ON")
|
||||
DB_CNX.close()
|
||||
|
Reference in New Issue
Block a user