feat: add Alembic migrations and category seed data
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
e483d1127a
commit
c1f7ed44c1
@@ -0,0 +1,98 @@
|
||||
from db import get_engine, get_session_factory, init_db
|
||||
from models.category import Category, CategoryWord
|
||||
|
||||
SEED_DATA = {
|
||||
"animals": [
|
||||
"TIGER",
|
||||
"DOLPHIN",
|
||||
"EAGLE",
|
||||
"WOLF",
|
||||
"BEAR",
|
||||
"LION",
|
||||
"HAWK",
|
||||
"DEER",
|
||||
"FROG",
|
||||
"SHARK",
|
||||
"SNAKE",
|
||||
"WHALE",
|
||||
"ZEBRA",
|
||||
"PANDA",
|
||||
"OTTER",
|
||||
"FALCON",
|
||||
"BISON",
|
||||
"CRANE",
|
||||
"MOOSE",
|
||||
"RAVEN",
|
||||
],
|
||||
"colors": [
|
||||
"CRIMSON",
|
||||
"VIOLET",
|
||||
"AMBER",
|
||||
"SCARLET",
|
||||
"INDIGO",
|
||||
"MAROON",
|
||||
"CORAL",
|
||||
"IVORY",
|
||||
"SILVER",
|
||||
"GOLDEN",
|
||||
"BRONZE",
|
||||
"TEAL",
|
||||
"OLIVE",
|
||||
"PLUM",
|
||||
"RUST",
|
||||
"SAGE",
|
||||
"NAVY",
|
||||
"JADE",
|
||||
"CYAN",
|
||||
"MAUVE",
|
||||
],
|
||||
"food": [
|
||||
"PIZZA",
|
||||
"SUSHI",
|
||||
"MANGO",
|
||||
"PASTA",
|
||||
"TACO",
|
||||
"BREAD",
|
||||
"STEAK",
|
||||
"GRAPE",
|
||||
"MELON",
|
||||
"PEACH",
|
||||
"OLIVE",
|
||||
"LEMON",
|
||||
"BACON",
|
||||
"WAFFLE",
|
||||
"CREPE",
|
||||
"DONUT",
|
||||
"SALAD",
|
||||
"CURRY",
|
||||
"BAGEL",
|
||||
"FUDGE",
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def seed():
|
||||
engine = get_engine()
|
||||
init_db(engine)
|
||||
Session = get_session_factory(engine)
|
||||
session = Session()
|
||||
|
||||
for cat_name, words in SEED_DATA.items():
|
||||
existing = session.query(Category).filter_by(name=cat_name).first()
|
||||
if existing:
|
||||
print(f"Category '{cat_name}' already exists, skipping.")
|
||||
continue
|
||||
cat = Category(name=cat_name)
|
||||
session.add(cat)
|
||||
session.flush()
|
||||
for w in words:
|
||||
session.add(CategoryWord(category_id=cat.id, word=w))
|
||||
print(f"Seeded category '{cat_name}' with {len(words)} words.")
|
||||
|
||||
session.commit()
|
||||
session.close()
|
||||
print("Done.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
seed()
|
||||
Reference in New Issue
Block a user