stress test applied
This commit is contained in:
7
runner/app/models/__init__.py
Normal file
7
runner/app/models/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
"""
|
||||
Models package initialization
|
||||
"""
|
||||
from app.models.user import User
|
||||
from app.models.post import Post
|
||||
|
||||
__all__ = ['User', 'Post']
|
||||
25
runner/app/models/post.py
Normal file
25
runner/app/models/post.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""
|
||||
Post model for the PostgreSQL database
|
||||
"""
|
||||
from sqlalchemy import Column, String, Text, Boolean, DateTime, ForeignKey, func, UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
import uuid
|
||||
from app import Base
|
||||
|
||||
class Post(Base):
|
||||
"""Post model representing a blog post or article in the system"""
|
||||
__tablename__ = 'posts'
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
user_id = Column(UUID(as_uuid=True), ForeignKey('users.id', ondelete='CASCADE'), nullable=False, index=True)
|
||||
title = Column(String(200), nullable=False)
|
||||
content = Column(Text)
|
||||
is_published = Column(Boolean, default=False)
|
||||
created_at = Column(DateTime, default=func.now())
|
||||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
||||
|
||||
# Relationships
|
||||
user = relationship("User", back_populates="posts")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Post(title='{self.title}', user_id='{self.user_id}')>"
|
||||
27
runner/app/models/user.py
Normal file
27
runner/app/models/user.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""
|
||||
User model for the PostgreSQL database
|
||||
"""
|
||||
from sqlalchemy import Column, String, Boolean, DateTime, func, UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
import uuid
|
||||
from app import Base
|
||||
|
||||
class User(Base):
|
||||
"""User model representing a user in the system"""
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
username = Column(String(50), unique=True, nullable=False, index=True)
|
||||
email = Column(String(100), unique=True, nullable=False, index=True)
|
||||
password_hash = Column(String(100), nullable=False)
|
||||
first_name = Column(String(50))
|
||||
last_name = Column(String(50))
|
||||
is_active = Column(Boolean, default=True)
|
||||
created_at = Column(DateTime, default=func.now())
|
||||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
||||
|
||||
# Relationships
|
||||
posts = relationship("Post", back_populates="user", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<User(username='{self.username}', email='{self.email}')>"
|
||||
Reference in New Issue
Block a user