-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscripts.py
44 lines (33 loc) · 1011 Bytes
/
scripts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from src.database import Base, engine, models, SessionLocal, schemas
from sqlalchemy.orm import Session
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
def recreate_database():
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
fake_user_1 = {
"email": "[email protected]",
"password": "fastapiPASS",
"full_name": "fastapi ipatsaf",
"disabled": False,
"username": "apiFAST",
}
fake_user_2 = {
"email": "[email protected]",
"password": "boilerPASS",
"full_name": "boiler reliob",
"disabled": True,
"username": "plateBOILER",
}
def create_fake_data():
insert_params = f"{tuple(fake_user_1.values())}, {tuple(fake_user_2.values())}"
query = f"INSERT INTO users (email, hashed_password, full_name, disabled, username) VALUES {insert_params}"
with engine.connect() as conn:
res = conn.execute(query)
def make_fake_db():
recreate_database()
create_fake_data()