diff --git a/fill_db.py b/fill_db.py index d794e88..3aa9f34 100644 --- a/fill_db.py +++ b/fill_db.py @@ -1,7 +1,7 @@ import random from uuid import uuid4 from sqlmodel import Session -from main import AUTH_DB_ENGINE, TgAgent, Ref, Sale, Transaction, Account +from main import AUTH_DB_ENGINE, TgAgent, Ref, Sale, Transaction, Account, Company from sqlalchemy import text from datetime import datetime, timedelta from hashlib import sha256 @@ -80,23 +80,34 @@ def fill_db(): session.execute(text("DELETE FROM ref")) session.execute(text("DELETE FROM tgagent")) session.execute(text("DELETE FROM account")) + session.execute(text('DELETE FROM "transaction"')) + session.execute(text("DELETE FROM company")) session.commit() - # 0. Accounts + # 0. Company + company = Company( + name="RE: Premium", + commission=10.0, + key="re-premium-key", + ) + session.add(company) + session.commit() + session.refresh(company) + # 1. Accounts accounts = [] for i in range(4): acc = Account( login=f"user{i+1}", - password_hash=get_password_hash("password123"), # теперь храним хеш + password_hash=get_password_hash("password123"), name=NAMES[i % len(NAMES)], email=f"user{i+1}@example.com", - balance=round(random.uniform(1000, 10000), 2) + company_id=company.id ) session.add(acc) accounts.append(acc) session.commit() for acc in accounts: session.refresh(acc) - # 1. TgAgents + # 2. TgAgents tg_agents = [] for i, tg_agent_id in enumerate(USER_IDS): dt = random.choice(date_list) @@ -107,6 +118,7 @@ def fill_db(): phone=PHONES[i % len(PHONES)], name=NAMES[i % len(NAMES)], login=LOGINS[i % len(LOGINS)], + company_id=company.id, create_dttm=dt, update_dttm=dt, hash=hash_value @@ -116,8 +128,7 @@ def fill_db(): session.commit() for tg_agent in tg_agents: session.refresh(tg_agent) - - # 2. Refs (минимум 22 на агента) + # 3. Refs (минимум 22 на агента) refs = [] desc_count = len(ALL_DESCRIPTIONS) for tg_agent in tg_agents: @@ -138,8 +149,7 @@ def fill_db(): session.commit() for ref in refs: session.refresh(ref) - - # 3. Sales (минимум 20 на каждый ref) + # 4. Sales (минимум 20 на каждый ref) for ref in refs: sale_count = random.randint(20, int(20 * 1.25)) # от 20 до 25 for _ in range(sale_count): @@ -151,13 +161,13 @@ def fill_db(): crediting=crediting, ref=ref.id, sale_id=str(uuid4()), + company_id=company.id, create_dttm=dt, update_dttm=dt ) session.add(sale) session.commit() - - # 4. Transactions (только withdrawal на агента) + # 5. Transactions (только withdrawal на агента) TRANSACTION_STATUSES = ['process', 'done', 'error', 'waiting'] for tg_agent in tg_agents: withdrawal_count = random.randint(5, int(5 * 1.25)) # от 5 до 6 @@ -175,6 +185,7 @@ def fill_db(): sum=round(random.uniform(200, 3000), 2), tg_agent_id=tg_agent.id, status=status, + company_id=company.id, create_dttm=dt, update_dttm=dt )