initializedb.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. import os
  3. import sys
  4. import transaction
  5. from pyramid.paster import (
  6. get_appsettings,
  7. setup_logging,
  8. )
  9. from pyramid.scripts.common import parse_vars
  10. from tracim.command import AppContextCommand
  11. from tracim.models.meta import DeclarativeBase
  12. from tracim.models import (
  13. get_engine,
  14. get_session_factory,
  15. get_tm_session,
  16. )
  17. class InitializeDBCommand(AppContextCommand):
  18. auto_setup_context = False
  19. def get_description(self):
  20. return "Initialize DB"
  21. def get_epilog(self):
  22. return "################"
  23. def get_parser(self, prog_name):
  24. parser = super().get_parser(prog_name)
  25. return parser
  26. def take_action(self, parsed_args):
  27. super(InitializeDBCommand, self).take_action(parsed_args)
  28. config_uri = parsed_args.config_file
  29. setup_logging(config_uri)
  30. settings = get_appsettings(config_uri)
  31. engine = get_engine(settings)
  32. DeclarativeBase.metadata.create_all(engine)
  33. session_factory = get_session_factory(engine)
  34. with transaction.manager:
  35. pass
  36. # dbsession = get_tm_session(session_factory, transaction.manager)
  37. # model = MyModel(name='one', value=1)
  38. # dbsession.add(model)
  39. # Add global manager data, just for test