Compare commits

..

No commits in common. "98d39bba2e726e6ad3be21f91d3505dc7b8407d1" and "b98eba2ddd1dcd392e7481fc831b2524918e6529" have entirely different histories.

8 changed files with 32 additions and 138 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
from sqlalchemy import Column, Integer, String, TIMESTAMP, UniqueConstraint
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
@ -9,9 +9,9 @@ Base = declarative_base()
class Author(Base):
__tablename__ = 'author'
__table_args__ = (UniqueConstraint('id'),)
id = Column(Integer, primary_key=True)
id = Column(Integer, primary_key=True, autoincrement=True)
first_name = Column(String(50), nullable=False)
last_name = Column(String(50), nullable=False)
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
books = relationship('Book', back_populates='author')

View File

@ -1,6 +1,4 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
@ -10,23 +8,21 @@ from .book_category import BookCategory
Base = declarative_base()
class BookStatusEnum(enum.Enum):
available = 'available'
borrowed = 'borrowed'
reserved = 'reserved'
class Book(Base):
__tablename__ = 'book'
__table_args__ = (UniqueConstraint('isbn'),)
id = Column(Integer, primary_key=True)
author_id = Column(Integer, ForeignKey('author.id'), nullable=False)
id = Column(Integer, primary_key=True, autoincrement=True)
author_id = Column(Integer, ForeignKey(
'author.id'), nullable=False, index=True)
title = Column(String(100), nullable=False)
description = Column(Text, nullable=False)
year_published = Column(String(4), nullable=False)
isbn = Column(String(13), nullable=False, unique=True)
status = Column(Enum(BookStatusEnum), nullable=False, default=BookStatusEnum.available)
created_at = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
status = Column(Enum('available', 'borrowed', 'reserved'),
nullable=False, default='available')
created_at = Column(TIMESTAMP, nullable=True, default="CURRENT_TIMESTAMP")
author = relationship('Author', backref='books')
author = relationship('Author', back_populates='books')
# loans = relationship('Loan', back_populates='book')
categories = relationship(
'BookCategory', secondary='book_category_link', back_populates='books')

View File

@ -1,5 +1,5 @@
from .book import Book
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
@ -8,12 +8,12 @@ Base = declarative_base()
class BookCategory(Base):
__tablename__ = 'book_category'
__table_args__ = (UniqueConstraint('name'),)
id = Column(Integer, primary_key=True)
parent_category_id = Column(Integer, ForeignKey('book_category.id'), nullable=True)
name = Column(String(100), nullable=False)
mature_content = Column(Integer, nullable=False, default=0)
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
id = Column(Integer, primary_key=True, autoincrement=True)
parent_category_id = Column(Integer, ForeignKey(
'book_category.id'), nullable=True, index=True)
name = Column(String(100), nullable=False, unique=True)
parent_category = relationship('BookCategory', remote_side=[id])
books = relationship(
'Book', secondary='book_category_link', back_populates='categories')

View File

@ -1,18 +1,10 @@
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from .book import Book
from .book_category import BookCategory
Base = declarative_base()
class BookCategoryLink(Base):
__tablename__ = 'book_category_link'
book_id = Column(Integer, ForeignKey('book.id'), primary_key=True)
book_category_id = Column(Integer, ForeignKey('book_category.id'), primary_key=True)
book = relationship('Book', backref='categories')
book_category = relationship('BookCategory', backref='books')
book_id = Column(Integer, ForeignKey('book.id'), primary_key=True, index=True)
book_category_id = Column(Integer, ForeignKey('book_category.id'), primary_key=True, index=True)

View File

@ -1,32 +0,0 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class LibrarianStatusEnum(enum.Enum):
active = 'active'
inactive = 'inactive'
class LibrarianRoleEnum(enum.Enum):
staff = 'staff'
admin = 'admin'
class Librarian(Base):
__tablename__ = 'librarian'
__table_args__ = (UniqueConstraint('id'),)
id = Column(Integer, primary_key=True)
first_name = Column(String(50), nullable=False)
last_name = Column(String(50), nullable=False)
email = Column(String(100), nullable=False, unique=True)
phone = Column(String(20), nullable=False)
hire_date = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
status = Column(Enum(LibrarianStatusEnum), nullable=False, default=LibrarianStatusEnum.active)
role = Column(Enum(LibrarianRoleEnum), nullable=False)
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')

View File

@ -1,38 +0,0 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from .book import Book
from .member import Member
from .librarian import Librarian
Base = declarative_base()
class LoanStatusEnum(enum.Enum):
borrowed = 'borrowed'
returned = 'returned'
overdue = 'overdue'
reserved = 'reserved'
class Loan(Base):
__tablename__ = 'loan'
__table_args__ = (UniqueConstraint('id'),)
id = Column(Integer, primary_key=True)
book_id = Column(Integer, ForeignKey('book.id'), nullable=False)
member_id = Column(Integer, ForeignKey('member.id'), nullable=False)
librarian_id = Column(Integer, ForeignKey('librarian.id'), nullable=False)
loan_date = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
due_date = Column(TIMESTAMP, nullable=False)
return_date = Column(TIMESTAMP, nullable=True)
status = Column(Enum(LoanStatusEnum), nullable=False, default=LoanStatusEnum.borrowed)
overdue_fee = Column(Float, nullable=True)
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
book = relationship('Book', backref='loans')
member = relationship('Member', backref='loans')
librarian = relationship('Librarian', backref='loans')

View File

@ -1,24 +0,0 @@
import enum
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
class MemberStatusEnum(enum.Enum):
active = 'active'
inactive = 'inactive'
Base = declarative_base()
class Member(Base):
__tablename__ = 'member'
__table_args__ = (UniqueConstraint('id'),)
id = Column(Integer, primary_key=True)
first_name = Column(String(50), nullable=False)
last_name = Column(String(50), nullable=False)
email = Column(String(100), nullable=False, unique=True)
phone = Column(String(20), nullable=True)
register_date = Column(TIMESTAMP, nullable=True, default='CURRENT_TIMESTAMP()')
status = Column(Enum(MemberStatusEnum), nullable=True, default=MemberStatusEnum.active)
last_updated = Column(TIMESTAMP, nullable=True)