-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdb2.py
More file actions
34 lines (29 loc) · 887 Bytes
/
db2.py
File metadata and controls
34 lines (29 loc) · 887 Bytes
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
#Tests large number of albums
from app.db.database import Base, engine, SessionLocal
from app.models.album import Album
from app.models.rating import Rating
from app.models.user import User
from sqlalchemy import func
# Drop all tables (wipes existing data)
Base.metadata.drop_all(bind=engine)
# Recreate tables with updated schema (including id field)
Base.metadata.create_all(bind=engine)
print("Tables dropped and recreated.")
def generate_test_albums(n=1000):
return [
Album(
id=i + 1,
title=f"Test Album #{i + 1}",
artist=f"Test Artist #{i + 1}",
year=1990,
cover_url="https://evek.one/4432-large_default/test.jpg"
)
for i in range(n)
]
db = SessionLocal()
try:
db.add_all(generate_test_albums())
db.commit()
print("Sample albums seeded with IDs.")
finally:
db.close()