chore(quality): apply ruff autofixes and formatting (8 fixes, 18 files reformatted)
This commit is contained in:
@@ -1,18 +1,31 @@
|
||||
"""Attachment model."""
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import String, DateTime, ForeignKey, Integer, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Attachment(Base):
|
||||
"""Attachment model."""
|
||||
__tablename__ = "attachments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
filename = Column(String(255), nullable=False)
|
||||
filepath = Column(String(500), nullable=False)
|
||||
file_size = Column(Integer)
|
||||
mime_type = Column(String(100))
|
||||
record_id = Column(Integer, nullable=True)
|
||||
uploaded_by = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
record_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("records.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
column_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("columns.id", ondelete="CASCADE"), nullable=True
|
||||
)
|
||||
filename: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
file_path: Mapped[str] = mapped_column(String(500), nullable=False)
|
||||
file_size: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
||||
mime_type: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
||||
uploaded_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
|
||||
# Relationships
|
||||
record = relationship("Record", back_populates="attachments")
|
||||
column = relationship("Column", back_populates="attachments")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Attachment(id={self.id}, filename={self.filename})>"
|
||||
|
||||
@@ -1,19 +1,38 @@
|
||||
"""Column model."""
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import String, DateTime, Boolean, ForeignKey, Integer, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy import JSON
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Column(Base):
|
||||
"""Column model."""
|
||||
__tablename__ = "columns"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
field_type = Column(String(50), nullable=False) # text, number, date, select, etc.
|
||||
table_id = Column(Integer, ForeignKey("tables.id"), nullable=False)
|
||||
position = Column(Integer, default=0)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
table_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("tables.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
type: Mapped[str] = mapped_column(
|
||||
String(50), nullable=False
|
||||
) # text, number, date, select, etc.
|
||||
required: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
default_value: Mapped[Optional[str]] = mapped_column(String, nullable=True)
|
||||
position: Mapped[int] = mapped_column(Integer, default=0)
|
||||
options: Mapped[Optional[dict]] = mapped_column(
|
||||
JSON, nullable=True
|
||||
) # For select type: {"options": ["a", "b"]}
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
|
||||
# Relationships
|
||||
table = relationship("Table", back_populates="columns")
|
||||
records = relationship("Record", back_populates="column")
|
||||
cell_values = relationship(
|
||||
"CellValue", back_populates="column", cascade="all, delete-orphan"
|
||||
)
|
||||
attachments = relationship("Attachment", back_populates="column")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Column(id={self.id}, name={self.name}, type={self.type})>"
|
||||
|
||||
@@ -1,19 +1,30 @@
|
||||
"""Comment model."""
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import String, DateTime, ForeignKey, func, Index
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Comment(Base):
|
||||
"""Comment model."""
|
||||
__tablename__ = "comments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
content = Column(Text, nullable=False)
|
||||
author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
table_id = Column(Integer, ForeignKey("tables.id"), nullable=True)
|
||||
record_id = Column(Integer, nullable=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
record_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("records.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||
content: Mapped[str] = mapped_column(String, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
author = relationship("User", back_populates="comments")
|
||||
# Relationships
|
||||
record = relationship("Record", back_populates="comments")
|
||||
user = relationship("User", back_populates="comments")
|
||||
|
||||
__table_args__ = (Index("idx_comments_record", "record_id"),)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Comment(id={self.id}, record_id={self.record_id})>"
|
||||
|
||||
@@ -1,18 +1,73 @@
|
||||
"""Record model."""
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import String, DateTime, ForeignKey, func, Index
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Record(Base):
|
||||
"""Record model."""
|
||||
__tablename__ = "records"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
column_id = Column(Integer, ForeignKey("columns.id"), nullable=False)
|
||||
row_id = Column(Integer, nullable=False)
|
||||
value = Column(Text)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
table_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("tables.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||
updated_by: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
column = relationship("Column", back_populates="records")
|
||||
# Relationships
|
||||
table = relationship("Table", back_populates="records")
|
||||
created_by_user = relationship(
|
||||
"User", back_populates="created_records", foreign_keys=[created_by]
|
||||
)
|
||||
updated_by_user = relationship(
|
||||
"User", back_populates="updated_records", foreign_keys=[updated_by]
|
||||
)
|
||||
cell_values = relationship(
|
||||
"CellValue", back_populates="record", cascade="all, delete-orphan"
|
||||
)
|
||||
comments = relationship(
|
||||
"Comment", back_populates="record", cascade="all, delete-orphan"
|
||||
)
|
||||
attachments = relationship(
|
||||
"Attachment", back_populates="record", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
__table_args__ = (Index("idx_records_table", "table_id"),)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Record(id={self.id}, table_id={self.table_id})>"
|
||||
|
||||
|
||||
class CellValue(Base):
|
||||
__tablename__ = "cell_values"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
record_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("records.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
column_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("columns.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
value: Mapped[Optional[str]] = mapped_column(String, nullable=True)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
# Relationships
|
||||
record = relationship("Record", back_populates="cell_values")
|
||||
column = relationship("Column", back_populates="cell_values")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_cell_values_record", "record_id"),
|
||||
Index("idx_cell_values_column", "column_id"),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<CellValue(record_id={self.record_id}, column_id={self.column_id})>"
|
||||
|
||||
+29
-12
@@ -1,20 +1,37 @@
|
||||
"""Table model."""
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import String, DateTime, ForeignKey, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Table(Base):
|
||||
"""Table model."""
|
||||
__tablename__ = "tables"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
description = Column(Text)
|
||||
workspace_id = Column(Integer, ForeignKey("workspaces.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
workspace_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("workspaces.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
description: Mapped[str] = mapped_column(String, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
# Relationships
|
||||
workspace = relationship("Workspace", back_populates="tables")
|
||||
columns = relationship("Column", back_populates="table", cascade="all, delete-orphan")
|
||||
views = relationship("View", back_populates="table")
|
||||
columns = relationship(
|
||||
"Column",
|
||||
back_populates="table",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="Column.position",
|
||||
)
|
||||
records = relationship(
|
||||
"Record", back_populates="table", cascade="all, delete-orphan"
|
||||
)
|
||||
views = relationship("View", back_populates="table", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Table(id={self.id}, name={self.name})>"
|
||||
|
||||
+30
-14
@@ -1,21 +1,37 @@
|
||||
"""User model."""
|
||||
from sqlalchemy import Column, Integer, String, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import String, DateTime, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
"""User model."""
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
email = Column(String(255), unique=True, index=True, nullable=False)
|
||||
username = Column(String(100), unique=True, index=True, nullable=False)
|
||||
hashed_password = Column(String(255), nullable=False)
|
||||
full_name = Column(String(255))
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
is_active = Column(Integer, default=1)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
email: Mapped[str] = mapped_column(
|
||||
String(255), unique=True, nullable=False, index=True
|
||||
)
|
||||
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
role: Mapped[str] = mapped_column(String(50), default="member")
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
workspaces = relationship("Workspace", back_populates="owner")
|
||||
comments = relationship("Comment", back_populates="author")
|
||||
# Relationships
|
||||
owned_workspaces = relationship("Workspace", back_populates="owner")
|
||||
workspace_memberships = relationship("WorkspaceMember", back_populates="user")
|
||||
created_records = relationship(
|
||||
"Record", back_populates="created_by_user", foreign_keys="Record.created_by"
|
||||
)
|
||||
updated_records = relationship(
|
||||
"Record", back_populates="updated_by_user", foreign_keys="Record.updated_by"
|
||||
)
|
||||
comments = relationship("Comment", back_populates="user")
|
||||
views = relationship("View", back_populates="created_by_user")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<User(id={self.id}, email={self.email}, role={self.role})>"
|
||||
|
||||
+24
-11
@@ -1,19 +1,32 @@
|
||||
"""View model."""
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import String, DateTime, Boolean, ForeignKey, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy import JSON
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class View(Base):
|
||||
"""View model."""
|
||||
__tablename__ = "views"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
view_type = Column(String(50), default="grid") # grid, gallery, form
|
||||
table_id = Column(Integer, ForeignKey("tables.id"), nullable=False)
|
||||
config = Column(Text) # JSON config for view settings
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
table_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("tables.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
type: Mapped[str] = mapped_column(String(50), default="grid") # grid, gallery, form
|
||||
config: Mapped[Optional[dict]] = mapped_column(
|
||||
JSON, nullable=True
|
||||
) # filter, sort, columns
|
||||
is_default: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
|
||||
# Relationships
|
||||
table = relationship("Table", back_populates="views")
|
||||
created_by_user = relationship("User", back_populates="views")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<View(id={self.id}, name={self.name}, type={self.type})>"
|
||||
|
||||
@@ -1,19 +1,52 @@
|
||||
"""Workspace model."""
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import String, DateTime, Boolean, ForeignKey, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Workspace(Base):
|
||||
"""Workspace model."""
|
||||
__tablename__ = "workspaces"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
description = Column(Text)
|
||||
owner_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
description: Mapped[str] = mapped_column(String, nullable=True)
|
||||
owner_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
|
||||
is_private: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
owner = relationship("User", back_populates="workspaces")
|
||||
tables = relationship("Table", back_populates="workspace")
|
||||
# Relationships
|
||||
owner = relationship("User", back_populates="owned_workspaces")
|
||||
members = relationship(
|
||||
"WorkspaceMember", back_populates="workspace", cascade="all, delete-orphan"
|
||||
)
|
||||
tables = relationship(
|
||||
"Table", back_populates="workspace", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Workspace(id={self.id}, name={self.name})>"
|
||||
|
||||
|
||||
class WorkspaceMember(Base):
|
||||
__tablename__ = "workspace_members"
|
||||
|
||||
workspace_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("workspaces.id", ondelete="CASCADE"), primary_key=True
|
||||
)
|
||||
user_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="CASCADE"), primary_key=True
|
||||
)
|
||||
role: Mapped[str] = mapped_column(String(50), default="member")
|
||||
joined_at: Mapped[datetime] = mapped_column(DateTime, default=func.now())
|
||||
|
||||
# Relationships
|
||||
workspace = relationship("Workspace", back_populates="members")
|
||||
user = relationship("User", back_populates="workspace_memberships")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<WorkspaceMember(workspace_id={self.workspace_id}, user_id={self.user_id}, role={self.role})>"
|
||||
|
||||
Reference in New Issue
Block a user