mirror of
https://github.com/a-mayb3/Kanban_clone_backend.git
synced 2026-03-21 18:15:37 +01:00
Defined tables for sqlite db
This commit is contained in:
parent
19ad5e97cd
commit
41ca480363
1 changed files with 39 additions and 0 deletions
39
models.py
Normal file
39
models.py
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
from sqlalchemy import Column, ForeignKey, String, Integer, Table
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
from database import Base
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
|
project_user = Table(
|
||||||
|
"project_user",
|
||||||
|
Base.metadata,
|
||||||
|
Column("project_id", Integer, ForeignKey("projects.id"), primary_key=True),
|
||||||
|
Column("user_id", Integer, ForeignKey("users.id"), primary_key=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
class User(Base):
|
||||||
|
__tablename__ = "users"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
name = Column(String, index=True)
|
||||||
|
email = Column(String, unique=True, index=True)
|
||||||
|
projects = relationship("Project", secondary=project_user, back_populates="users")
|
||||||
|
|
||||||
|
class Project(Base):
|
||||||
|
__tablename__ = "projects"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
name = Column(String, index=True)
|
||||||
|
description = Column(String)
|
||||||
|
users = relationship("User", secondary=project_user, back_populates="projects")
|
||||||
|
tasks = relationship("Task", back_populates="project")
|
||||||
|
|
||||||
|
class Task(Base):
|
||||||
|
__tablename__ = "tasks"
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
title = Column(String, index=True)
|
||||||
|
description = Column(String)
|
||||||
|
status = Column(String, default="pending")
|
||||||
|
project_id = Column(Integer, ForeignKey("projects.id"))
|
||||||
|
project = relationship("Project", back_populates="tasks")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue