create_db.py 635 B

1234567891011121314151617181920212223242526
  1. from sqlalchemy import create_engine
  2. from sqlalchemy.orm import sessionmaker
  3. from time_recoder.time_recoder_config import 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:///" + PATH + DATABASE_NAME, echo=False, future=True)
  7. Session = sessionmaker(bind=ENGINE)
  8. def main():
  9. BASE.metadata.create_all(ENGINE)
  10. def create_root_task():
  11. session = Session()
  12. root_task = Task(parent_task_id=-1, name='root')
  13. session.add(root_task)
  14. session.commit()
  15. session.close()
  16. if __name__ == "__main__":
  17. main()