57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""Seed-Skript.
|
|
|
|
Legt das erste Team (CheckPoint) mit seinen Brand-Tokens und den zwei festen
|
|
Kanälen (ankuendigungen, team) an. Idempotent: mehrfaches Ausführen erzeugt
|
|
keine Duplikate.
|
|
|
|
Aufruf (pyenv-Umgebung):
|
|
python seed.py
|
|
"""
|
|
|
|
from app import create_app, db
|
|
from app.models import Kanal, Team
|
|
|
|
CHECKPOINT_NAME = "CheckPoint"
|
|
CHECKPOINT_SLUG = "checkpoint"
|
|
|
|
|
|
def seed():
|
|
app = create_app()
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
team = Team.query.filter_by(name=CHECKPOINT_NAME).first()
|
|
if team is None:
|
|
team = Team(
|
|
name=CHECKPOINT_NAME,
|
|
slug=CHECKPOINT_SLUG,
|
|
brand_primary="#21a8ad",
|
|
brand_primary_strong="#147f84",
|
|
brand_accent="#ef1823",
|
|
brand_accent_strong="#bd0f18",
|
|
brand_font='"DM Sans", Arial, Helvetica, sans-serif',
|
|
)
|
|
db.session.add(team)
|
|
db.session.flush() # team.id verfügbar machen
|
|
print(f"Team angelegt: {team.name} (id {team.id})")
|
|
else:
|
|
if not team.slug:
|
|
team.slug = CHECKPOINT_SLUG
|
|
print(f"Team-Kürzel nachgetragen: {team.slug}")
|
|
print(f"Team existiert bereits: {team.name} (id {team.id})")
|
|
|
|
# Die zwei festen Kanäle sicherstellen.
|
|
for art in (Kanal.ART_ANKUENDIGUNGEN, Kanal.ART_TEAM):
|
|
vorhanden = Kanal.query.filter_by(team_id=team.id, art=art).first()
|
|
if vorhanden is None:
|
|
db.session.add(Kanal(team_id=team.id, art=art))
|
|
print(f"Kanal angelegt: {art}")
|
|
else:
|
|
print(f"Kanal existiert bereits: {art}")
|
|
|
|
db.session.commit()
|
|
print("Seed fertig.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
seed()
|