61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
import asyncio
|
|
|
|
import aiosqlite
|
|
|
|
|
|
async def connect(path="./data/doof.sqlite") -> aiosqlite.Connection:
|
|
return await aiosqlite.connect(path)
|
|
|
|
|
|
async def create(conn: aiosqlite.Connection):
|
|
import products.repository as product_db
|
|
|
|
await product_db.create(conn)
|
|
|
|
import ingredients.repository as ingredient_db
|
|
|
|
await ingredient_db.create(conn)
|
|
|
|
import recipes.repository as recipe_db
|
|
|
|
await recipe_db.create(conn)
|
|
|
|
# New v2 domain tables (users/households). Keep persons for compatibility during migration.
|
|
try:
|
|
import users.repository as users_db
|
|
await users_db.create(conn)
|
|
except Exception:
|
|
# Be tolerant if table already exists or module missing in some setups
|
|
pass
|
|
|
|
try:
|
|
import households.repository as households_db
|
|
await households_db.create(conn)
|
|
except Exception:
|
|
pass
|
|
|
|
import persons.repository as person_db
|
|
|
|
await person_db.create(conn)
|
|
|
|
import meals.repository as meals_db
|
|
|
|
await meals_db.create(conn)
|
|
|
|
import shopping.repository as shopping_db
|
|
|
|
await shopping_db.create(conn)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from tests.test_data import create_test_data
|
|
|
|
async def main():
|
|
conn = await connect()
|
|
await create(conn)
|
|
await conn.commit()
|
|
await create_test_data(conn)
|
|
await conn.commit()
|
|
await conn.close()
|
|
|
|
asyncio.run(main())
|