create_database.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from random import randint
  2. from sqlalchemy.orm import sessionmaker
  3. from sqlalchemy import create_engine
  4. from frameworkbenchmarks.models import pg, DBSession, metadata, World, Fortune
  5. if __name__ == "__main__":
  6. """
  7. Initialize database
  8. """
  9. World.__table__.drop(pg, checkfirst=True)
  10. Fortune.__table__.drop(pg, checkfirst=True)
  11. DBSession.commit()
  12. World.__table__.create(pg)
  13. Fortune.__table__.create(pg)
  14. DBSession.commit()
  15. DBSession.execute(
  16. World.__table__.insert([(num, randint(1, 10001)) for num in range(1, 10001)])
  17. )
  18. DBSession.execute(
  19. Fortune.__table__.insert([
  20. ("1", "fortune: No such file or directory"),
  21. ("2", "A computer scientist is someone who fixes things that aren't broken."),
  22. ("3", "After enough decimal places, nobody gives a damn."),
  23. ("4", "A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1"),
  24. ("5", "A computer program does what you tell it to do, not what you want it to do."),
  25. ("6", "Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen"),
  26. ("7", "Any program that runs right is obsolete."),
  27. ("8", "A list is only as strong as its weakest link. — Donald Knuth"),
  28. ("9", "Feature: A bug with seniority."),
  29. ("10", "Computers make very fast, very accurate mistakes."),
  30. ("11", """<script>alert("This should not be displayed in a browser alert box.");</script>"""),
  31. ("12", "フレームワークのベンチマーク"),
  32. ])
  33. )
  34. DBSession.commit()