mirror of https://github.com/stijndcl/didier
				
				
				
			Create database models
							parent
							
								
									9552c38a70
								
							
						
					
					
						commit
						4587a49311
					
				|  | @ -0,0 +1,51 @@ | ||||||
|  | """Initial currency models | ||||||
|  | 
 | ||||||
|  | Revision ID: 5f3a11a80e69 | ||||||
|  | Revises: b2d511552a1f | ||||||
|  | Create Date: 2022-06-30 19:40:02.701336 | ||||||
|  | 
 | ||||||
|  | """ | ||||||
|  | from alembic import op | ||||||
|  | import sqlalchemy as sa | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | # revision identifiers, used by Alembic. | ||||||
|  | revision = '5f3a11a80e69' | ||||||
|  | down_revision = 'b2d511552a1f' | ||||||
|  | branch_labels = None | ||||||
|  | depends_on = None | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def upgrade() -> None: | ||||||
|  |     # ### commands auto generated by Alembic - please adjust! ### | ||||||
|  |     op.create_table('users', | ||||||
|  |     sa.Column('user_id', sa.BigInteger(), nullable=False), | ||||||
|  |     sa.Column('dinks', sa.BigInteger(), nullable=False), | ||||||
|  |     sa.PrimaryKeyConstraint('user_id') | ||||||
|  |     ) | ||||||
|  |     op.create_table('bank', | ||||||
|  |     sa.Column('bank_id', sa.Integer(), nullable=False), | ||||||
|  |     sa.Column('user_id', sa.BigInteger(), nullable=True), | ||||||
|  |     sa.Column('interest_level', sa.Integer(), nullable=False), | ||||||
|  |     sa.Column('capacity_level', sa.Integer(), nullable=False), | ||||||
|  |     sa.Column('rob_level', sa.Integer(), nullable=False), | ||||||
|  |     sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ), | ||||||
|  |     sa.PrimaryKeyConstraint('bank_id') | ||||||
|  |     ) | ||||||
|  |     op.create_table('nightly_data', | ||||||
|  |     sa.Column('nightly_id', sa.Integer(), nullable=False), | ||||||
|  |     sa.Column('user_id', sa.BigInteger(), nullable=True), | ||||||
|  |     sa.Column('last_nightly', sa.DateTime(timezone=True), nullable=True), | ||||||
|  |     sa.Column('count', sa.Integer(), nullable=False), | ||||||
|  |     sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ), | ||||||
|  |     sa.PrimaryKeyConstraint('nightly_id') | ||||||
|  |     ) | ||||||
|  |     # ### end Alembic commands ### | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def downgrade() -> None: | ||||||
|  |     # ### commands auto generated by Alembic - please adjust! ### | ||||||
|  |     op.drop_table('nightly_data') | ||||||
|  |     op.drop_table('bank') | ||||||
|  |     op.drop_table('users') | ||||||
|  |     # ### end Alembic commands ### | ||||||
|  | @ -1,13 +1,34 @@ | ||||||
| from __future__ import annotations | from __future__ import annotations | ||||||
| 
 | 
 | ||||||
| from datetime import datetime | from datetime import datetime | ||||||
|  | from typing import Optional | ||||||
| 
 | 
 | ||||||
| from sqlalchemy import Column, Integer, Text, ForeignKey, Boolean, DateTime | from sqlalchemy import BigInteger, Column, Integer, Text, ForeignKey, Boolean, DateTime | ||||||
| from sqlalchemy.orm import declarative_base, relationship | from sqlalchemy.orm import declarative_base, relationship | ||||||
| 
 | 
 | ||||||
| Base = declarative_base() | Base = declarative_base() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class Bank(Base): | ||||||
|  |     """A user's currency information""" | ||||||
|  | 
 | ||||||
|  |     __tablename__ = "bank" | ||||||
|  | 
 | ||||||
|  |     bank_id: int = Column(Integer, primary_key=True) | ||||||
|  |     user_id: int = Column(BigInteger, ForeignKey("users.user_id")) | ||||||
|  | 
 | ||||||
|  |     # Interest rate | ||||||
|  |     interest_level: int = Column(Integer, default=1, nullable=False) | ||||||
|  | 
 | ||||||
|  |     # Maximum amount that can be stored in the bank | ||||||
|  |     capacity_level: int = Column(Integer, default=1, nullable=False) | ||||||
|  | 
 | ||||||
|  |     # Maximum amount that can be robbed | ||||||
|  |     rob_level: int = Column(Integer, default=1, nullable=False) | ||||||
|  | 
 | ||||||
|  |     user: User = relationship("User", uselist=False, back_populates="bank", lazy="selectin") | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class CustomCommand(Base): | class CustomCommand(Base): | ||||||
|     """Custom commands to fill the hole Dyno couldn't""" |     """Custom commands to fill the hole Dyno couldn't""" | ||||||
| 
 | 
 | ||||||
|  | @ -36,6 +57,19 @@ class CustomCommandAlias(Base): | ||||||
|     command: CustomCommand = relationship("CustomCommand", back_populates="aliases", uselist=False, lazy="selectin") |     command: CustomCommand = relationship("CustomCommand", back_populates="aliases", uselist=False, lazy="selectin") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class NightlyData(Base): | ||||||
|  |     """Data for a user's Nightly stats""" | ||||||
|  | 
 | ||||||
|  |     __tablename__ = "nightly_data" | ||||||
|  | 
 | ||||||
|  |     nightly_id: int = Column(Integer, primary_key=True) | ||||||
|  |     user_id: int = Column(BigInteger, ForeignKey("users.user_id")) | ||||||
|  |     last_nightly: Optional[datetime] = Column(DateTime(timezone=True), nullable=True) | ||||||
|  |     count: int = Column(Integer, default=0, nullable=False) | ||||||
|  | 
 | ||||||
|  |     user: User = relationship("User", back_populates="nightly_data", uselist=False, lazy="selectin") | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class UforaCourse(Base): | class UforaCourse(Base): | ||||||
|     """A course on Ufora""" |     """A course on Ufora""" | ||||||
| 
 | 
 | ||||||
|  | @ -72,8 +106,24 @@ class UforaAnnouncement(Base): | ||||||
| 
 | 
 | ||||||
|     __tablename__ = "ufora_announcements" |     __tablename__ = "ufora_announcements" | ||||||
| 
 | 
 | ||||||
|     announcement_id = Column(Integer, primary_key=True) |     announcement_id: int = Column(Integer, primary_key=True) | ||||||
|     course_id = Column(Integer, ForeignKey("ufora_courses.course_id")) |     course_id: int = Column(Integer, ForeignKey("ufora_courses.course_id")) | ||||||
|     publication_date: datetime = Column(DateTime(timezone=True)) |     publication_date: datetime = Column(DateTime(timezone=True)) | ||||||
| 
 | 
 | ||||||
|     course: UforaCourse = relationship("UforaCourse", back_populates="announcements", uselist=False, lazy="selectin") |     course: UforaCourse = relationship("UforaCourse", back_populates="announcements", uselist=False, lazy="selectin") | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class User(Base): | ||||||
|  |     """A Didier user""" | ||||||
|  | 
 | ||||||
|  |     __tablename__ = "users" | ||||||
|  | 
 | ||||||
|  |     user_id: int = Column(BigInteger, primary_key=True) | ||||||
|  |     dinks: int = Column(BigInteger, default=0, nullable=False) | ||||||
|  | 
 | ||||||
|  |     bank: Bank = relationship( | ||||||
|  |         "Bank", back_populates="user", uselist=False, lazy="selectin", cascade="all, delete-orphan" | ||||||
|  |     ) | ||||||
|  |     nightly_data: NightlyData = relationship( | ||||||
|  |         "NightlyData", back_populates="user", uselist=False, lazy="selectin", cascade="all, delete-orphan" | ||||||
|  |     ) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue