create_db.py 670 B

123456789101112131415161718192021222324252627
  1. from sqlalchemy import create_engine
  2. from sqlalchemy.orm import sessionmaker
  3. from time_recoder.time_recoder_config import DB_PATH
  4. from time_recoder.time_recorder_database.db_models import BASE, Task
  5. DATABASE_NAME = "time_recorder_database.db"
  6. ENGINE = create_engine("sqlite+pysqlite:///" + DB_PATH + "/" + DATABASE_NAME, echo=False, future=True)
  7. Session = sessionmaker(bind=ENGINE)
  8. def main():
  9. BASE.metadata.create_all(ENGINE)
  10. create_root_task()
  11. def create_root_task():
  12. session = Session()
  13. root_task = Task(parent_task_id=-1, name='root')
  14. session.add(root_task)
  15. session.commit()
  16. session.close()
  17. if __name__ == "__main__":
  18. main()