Skip to content

Commit e9b0715

Browse files
committed
generated file: db/models/__init__.py
1 parent f9d5c80 commit e9b0715

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

db/models/__init__.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from sqlalchemy import Column, Integer, String, ForeignKey, Boolean, DateTime
2+
from sqlalchemy.orm import relationship
3+
from sqlalchemy.ext.declarative import declarative_base
4+
from datetime import datetime
5+
6+
from .schemas import UserSchema
7+
8+
Base = declarative_base()
9+
10+
class User(Base):
11+
__tablename__ = "users"
12+
13+
id = Column(Integer, primary_key=True, index=True)
14+
username = Column(String, unique=True, index=True)
15+
password = Column(String)
16+
api_key = Column(String, unique=True, index=True)
17+
18+
def __repr__(self):
19+
return f"<User(id={self.id}, username='{self.username}')>"
20+
21+
class APIKey(Base):
22+
__tablename__ = "api_keys"
23+
24+
id = Column(Integer, primary_key=True, index=True)
25+
user_id = Column(Integer, ForeignKey("users.id"))
26+
api_key = Column(String, unique=True, index=True)
27+
is_active = Column(Boolean, default=True)
28+
created_at = Column(DateTime, default=datetime.utcnow)
29+
30+
user = relationship("User", backref="api_keys")
31+
32+
def __repr__(self):
33+
return f"<APIKey(id={self.id}, user_id={self.user_id}, api_key='{self.api_key}', is_active={self.is_active})>"

0 commit comments

Comments
 (0)