[main] Updated models and their initialization
This commit is contained in:
parent
1e36c2d966
commit
76465636ee
@ -0,0 +1,7 @@
|
||||
from .author import Author
|
||||
from .book_category import BookCategory
|
||||
from .book import Book
|
||||
from .book_category_link import BookCategoryLink
|
||||
from .member import Member
|
||||
from .librarian import Librarian
|
||||
from .loan import Loan
|
@ -1,9 +1,7 @@
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, UniqueConstraint
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, UniqueConstraint, func
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
from .book import Book
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
@ -11,7 +9,7 @@ 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()')
|
||||
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
|
@ -1,6 +1,6 @@
|
||||
import enum
|
||||
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
@ -19,14 +19,14 @@ class Book(Base):
|
||||
__tablename__ = 'book'
|
||||
__table_args__ = (UniqueConstraint('isbn'),)
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
author_id = Column(Integer, ForeignKey('author.id'), nullable=False)
|
||||
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()')
|
||||
created_at = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
|
||||
author = relationship('Author', backref='books')
|
||||
|
@ -1,5 +1,4 @@
|
||||
from .book import Book
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, ForeignKey, UniqueConstraint, func
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
@ -10,10 +9,10 @@ class BookCategory(Base):
|
||||
__tablename__ = 'book_category'
|
||||
__table_args__ = (UniqueConstraint('name'),)
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
id = Column(Integer, primary_key=True, autoincrement=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()')
|
||||
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
|
||||
parent_category = relationship('BookCategory', remote_side=[id])
|
||||
|
@ -1,6 +1,6 @@
|
||||
import enum
|
||||
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
@ -21,12 +21,12 @@ class Librarian(Base):
|
||||
__tablename__ = 'librarian'
|
||||
__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)
|
||||
email = Column(String(100), nullable=False, unique=True)
|
||||
phone = Column(String(20), nullable=False)
|
||||
hire_date = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
|
||||
hire_date = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
status = Column(Enum(LibrarianStatusEnum), nullable=False, default=LibrarianStatusEnum.active)
|
||||
role = Column(Enum(LibrarianRoleEnum), nullable=False)
|
||||
last_updated = Column(TIMESTAMP, nullable=False, default='CURRENT_TIMESTAMP()')
|
||||
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
|
@ -1,6 +1,6 @@
|
||||
import enum
|
||||
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, Float, func
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
@ -22,16 +22,16 @@ class Loan(Base):
|
||||
__tablename__ = 'loan'
|
||||
__table_args__ = (UniqueConstraint('id'),)
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
id = Column(Integer, primary_key=True, autoincrement=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()')
|
||||
loan_date = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
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()')
|
||||
last_updated = Column(TIMESTAMP, nullable=False, server_default=func.now())
|
||||
|
||||
book = relationship('Book', backref='loans')
|
||||
member = relationship('Member', backref='loans')
|
||||
|
@ -1,6 +1,6 @@
|
||||
import enum
|
||||
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint
|
||||
from sqlalchemy import Column, Integer, String, TIMESTAMP, Text, ForeignKey, Enum, UniqueConstraint, func
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
@ -14,11 +14,11 @@ class Member(Base):
|
||||
__tablename__ = 'member'
|
||||
__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)
|
||||
email = Column(String(100), nullable=False, unique=True)
|
||||
phone = Column(String(20), nullable=True)
|
||||
register_date = Column(TIMESTAMP, nullable=True, default='CURRENT_TIMESTAMP()')
|
||||
register_date = Column(TIMESTAMP, nullable=True, server_default=func.now())
|
||||
status = Column(Enum(MemberStatusEnum), nullable=True, default=MemberStatusEnum.active)
|
||||
last_updated = Column(TIMESTAMP, nullable=True)
|
Loading…
x
Reference in New Issue
Block a user