Skip to content

Commit

Permalink
ref(model): Moved id to base model + added insertion date field to al…
Browse files Browse the repository at this point in the history
…l models
  • Loading branch information
Nickelza committed Aug 19, 2024
1 parent 1229178 commit 8b9f325
Show file tree
Hide file tree
Showing 46 changed files with 10 additions and 107 deletions.
2 changes: 1 addition & 1 deletion src/chat/private/private_chat_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ async def send_system_update_message(
return

# Don't send update if user joined after the update was made
if user.join_date > system_update.date:
if user.date > system_update.date:
return

ot_text = phrases.SYSTEM_UPDATE.format(
Expand Down
2 changes: 1 addition & 1 deletion src/chat/private/screens/screen_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_items(self, page, limit=ListPage.DEFAULT_LIMIT) -> list[Prediction]:
"""
return (
self.get_select_items_statement()
.order_by(Prediction.creation_date.desc(), Prediction.send_date.desc())
.order_by(Prediction.date.desc(), Prediction.send_date.desc())
.paginate(page, limit)
)

Expand Down
3 changes: 3 additions & 0 deletions src/model/BaseModel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from peewee import *

from resources.Database import Database
Expand All @@ -12,6 +14,7 @@ class BaseModel(Model):
"""

id: int | PrimaryKeyField = PrimaryKeyField()
date = DateTimeField(default=datetime.now)

class Meta:
database = db_obj.get_db()
Expand Down
4 changes: 0 additions & 4 deletions src/model/BountyGift.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from peewee import *

from src.model.BaseModel import BaseModel
Expand All @@ -14,7 +12,6 @@ class BountyGift(BaseModel):
BountyGift class
"""

id = PrimaryKeyField()
sender = ForeignKeyField(
User, backref="bounty_gift_senders", on_delete="CASCADE", on_update="CASCADE"
)
Expand All @@ -23,7 +20,6 @@ class BountyGift(BaseModel):
)
amount = BigIntegerField()
tax_percentage = FloatField()
date = DateTimeField(default=datetime.datetime.now)
status = SmallIntegerField(default=BountyGiftStatus.AWAITING_CONFIRMATION)
group_chat = ForeignKeyField(
GroupChat,
Expand Down
3 changes: 1 addition & 2 deletions src/model/BountyLoan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@


class BountyLoan(BaseModel):
id = PrimaryKeyField()
"""
BountyLoan class
"""

loaner = ForeignKeyField(
User, backref="bounty_loaners", on_delete="CASCADE", on_update="CASCADE"
)
Expand All @@ -32,7 +32,6 @@ class BountyLoan(BaseModel):
deadline_date = DateTimeField()
last_payment_date = DateTimeField(null=True)
forgiven_date = DateTimeField(null=True)
date = DateTimeField(default=datetime.now)
status = SmallIntegerField(default=BountyLoanStatus.AWAITING_LOANER_CONFIRMATION)
group_chat = ForeignKeyField(
GroupChat,
Expand Down
2 changes: 0 additions & 2 deletions src/model/Crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class Crew(BaseModel):
Crew class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
name: str | CharField = CharField(max_length=Env.CREW_NAME_MAX_LENGTH.get_int())
creation_date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now)
can_accept_new_members: bool | BooleanField = BooleanField(default=True)
is_active: bool | BooleanField = BooleanField(default=True)
disband_date: datetime.datetime | DateTimeField = DateTimeField(null=True)
Expand Down
4 changes: 0 additions & 4 deletions src/model/CrewAbility.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from peewee import *

from src.model.BaseModel import BaseModel
Expand All @@ -13,13 +11,11 @@ class CrewAbility(BaseModel):
CrewAbility class
"""

id = PrimaryKeyField()
crew = ForeignKeyField(Crew, backref="crew_abilities")
ability_type = SmallIntegerField()
value = SmallIntegerField()
acquired_method = SmallIntegerField()
acquired_user = ForeignKeyField(User, backref="crew_abilities_acquired", null=True)
acquired_date = DateTimeField(default=datetime.datetime.now)
expiration_date = DateTimeField(null=True)
was_removed = BooleanField(default=False)
removed_user = ForeignKeyField(User, backref="crew_abilities_removed", null=True)
Expand Down
4 changes: 0 additions & 4 deletions src/model/CrewChestSpendingRecord.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from peewee import *

from src.model.BaseModel import BaseModel
Expand All @@ -12,11 +10,9 @@ class CrewChestSpendingRecord(BaseModel):
CrewChestSpendingRecord class
"""

id = PrimaryKeyField()
crew = ForeignKeyField(Crew, backref="crew_chest_spending_records")
amount = BigIntegerField()
reason = CharField()
date = DateTimeField(default=datetime.datetime.now)
by_user = ForeignKeyField(User, backref="crew_chest_spending_records")
to_user = ForeignKeyField(User, backref="crew_chest_spending_records", null=True)

Expand Down
2 changes: 0 additions & 2 deletions src/model/CrewJoinRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ class CrewJoinRequest(BaseModel):
CrewJoinRequest class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
user: User | ForeignKeyField = ForeignKeyField(User, backref="crew_join_requests")
crew: Crew | ForeignKeyField = ForeignKeyField(Crew, backref="crew_join_requests")
date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now)
status: CrewJoinRequestStatus | SmallIntegerField = SmallIntegerField(
default=CrewJoinRequestStatus.PENDING
)
Expand Down
1 change: 0 additions & 1 deletion src/model/CrewMemberChestContribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class CrewMemberChestContribution(BaseModel):
CrewMemberChestContribution class
"""

id = PrimaryKeyField()
crew = ForeignKeyField(Crew, backref="crew_member_chest_contributions")
user = ForeignKeyField(User, backref="crew_member_chest_contributions")
amount = BigIntegerField(default=0)
Expand Down
2 changes: 0 additions & 2 deletions src/model/DailyReward.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class DailyReward(BaseModel):
DailyReward class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
user: User | ForeignKeyField = ForeignKeyField(User, backref="daily_bonuses")
date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now)
base_amount: int | BigIntegerField = BigIntegerField()
bonus_list: str | TextField = TextField()
total_amount: int | BigIntegerField = BigIntegerField()
Expand Down
2 changes: 0 additions & 2 deletions src/model/DavyBackFight.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class DavyBackFight(BaseModel):
DavyBackFight class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
challenger_crew: Crew | ForeignKeyField = ForeignKeyField(
Crew, backref="davy_back_fights_challengers"
)
Expand All @@ -30,7 +29,6 @@ class DavyBackFight(BaseModel):
participants_count: int | IntegerField = IntegerField()
duration_hours: int | IntegerField = IntegerField()
penalty_days = IntegerField()
date = DateTimeField(default=datetime.datetime.now)
status: int | SmallIntegerField = SmallIntegerField(
default=GameStatus.AWAITING_OPPONENT_CONFIRMATION
)
Expand Down
4 changes: 0 additions & 4 deletions src/model/DavyBackFightParticipant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from datetime import datetime

from peewee import *

from src.model.BaseModel import BaseModel
Expand All @@ -13,14 +11,12 @@ class DavyBackFightParticipant(BaseModel):
DavyBackFightParticipant class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
davy_back_fight: DavyBackFight | ForeignKeyField = ForeignKeyField(
DavyBackFight, backref="davy_back_fight_participants", on_delete="CASCADE"
)
user: User | ForeignKeyField = ForeignKeyField(User, backref="davy_back_fight_participants")
crew: Crew | ForeignKeyField = ForeignKeyField(Crew, backref="davy_back_fight_participants")
contribution: int | BigIntegerField = BigIntegerField(default=0)
date = DateTimeField(default=datetime.now)
win_amount: int | BigIntegerField = BigIntegerField(null=True)

class Meta:
Expand Down
1 change: 0 additions & 1 deletion src/model/DevilFruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class DevilFruit(BaseModel):
DevilFruit class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
category: int | DevilFruitCategory = SmallIntegerField()
name: str | CharField = CharField(max_length=50)
model: str | CharField = CharField(max_length=50, null=True, unique=True)
Expand Down
1 change: 0 additions & 1 deletion src/model/DevilFruitAbility.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class DevilFruitAbility(BaseModel):
Devil Fruit Ability class
"""

id = PrimaryKeyField()
devil_fruit = ForeignKeyField(
DevilFruit, backref="devil_fruit_abilities", on_delete="CASCADE", on_update="CASCADE"
)
Expand Down
2 changes: 0 additions & 2 deletions src/model/DevilFruitTrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class DevilFruitTrade(BaseModel):
Devil Fruit Trade class
"""

id = PrimaryKeyField()
devil_fruit: DevilFruit | ForeignKeyField = ForeignKeyField(
DevilFruit,
null=True,
Expand All @@ -42,7 +41,6 @@ class DevilFruitTrade(BaseModel):
price: int | BigIntegerField = BigIntegerField(null=True)
tax_percentage: float | FloatField = FloatField(null=True)
reason: str | CharField = CharField(max_length=100, null=True)
date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now)
date_sold: datetime.datetime | DateTimeField = DateTimeField(null=True)
status: DevilFruitTradeStatus | SmallIntegerField = SmallIntegerField(
default=DevilFruitTradeStatus.PENDING
Expand Down
1 change: 0 additions & 1 deletion src/model/DisabledNotification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class DisabledNotification(BaseModel):
DisabledNotification class
"""

id = PrimaryKeyField()
user = ForeignKeyField(
User, backref="disabled_notification_users", on_delete="CASCADE", on_update="CASCADE"
)
Expand Down
4 changes: 0 additions & 4 deletions src/model/DocQGame.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from peewee import *

import constants as c
Expand All @@ -14,11 +12,9 @@ class DocQGame(BaseModel):
Doc Q Game class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
user: User | ForeignKeyField = ForeignKeyField(
User, backref="doc_q_game_users", on_delete="CASCADE", on_update="CASCADE"
)
date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now)
status: GameStatus | SmallIntegerField = SmallIntegerField(default=GameStatus.IN_PROGRESS)
correct_choices_index: str | CharField = CharField(max_length=99, null=True)
group_chat: GroupChat | ForeignKeyField = ForeignKeyField(
Expand Down
1 change: 0 additions & 1 deletion src/model/Fight.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Fight(BaseModel):
Fight class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
challenger: User | ForeignKeyField = ForeignKeyField(
User, backref="fight_challengers", on_delete="CASCADE", on_update="CASCADE"
)
Expand Down
2 changes: 0 additions & 2 deletions src/model/Game.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Game(BaseModel):
Game class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
challenger: User | ForeignKeyField = ForeignKeyField(
User, backref="game_challengers", on_delete="CASCADE", on_update="CASCADE"
)
Expand All @@ -34,7 +33,6 @@ class Game(BaseModel):
type: GameType | SmallIntegerField = SmallIntegerField(null=True)
board: str | CharField = CharField(max_length=9999, null=True)
opponent_board: str | CharField = CharField(max_length=9999, null=True)
date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now)
status: GameStatus | SmallIntegerField = SmallIntegerField(
default=GameStatus.AWAITING_SELECTION
)
Expand Down
2 changes: 0 additions & 2 deletions src/model/Group.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ class Group(BaseModel):
Group class
"""

id = PrimaryKeyField()
tg_group_id = CharField(unique=True)
tg_group_name = CharField()
tg_group_username = CharField(null=True)
is_forum = BooleanField(default=False)
added_date = DateTimeField(default=datetime.datetime.now)
last_message_date = DateTimeField(default=datetime.datetime.now)
last_error_date = DateTimeField(null=True)
last_error_message = CharField(null=True)
Expand Down
1 change: 0 additions & 1 deletion src/model/GroupChat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class GroupChat(BaseModel):
Group Chat class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
group: Group | ForeignKeyField = ForeignKeyField(
Group, backref="group_chats", on_delete="CASCADE", on_update="CASCADE"
)
Expand Down
2 changes: 0 additions & 2 deletions src/model/GroupChatAutoDelete.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ class GroupChatAutoDelete(BaseModel):
Group Chat Auto Delete class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
group_chat: GroupChat | ForeignKeyField = ForeignKeyField(
GroupChat, backref="auto_delete", on_delete="CASCADE"
)
message_id: int | IntegerField = IntegerField()
date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now)
delete_date: datetime.datetime | DateTimeField = DateTimeField()

class Meta:
Expand Down
1 change: 0 additions & 1 deletion src/model/GroupChatEnabledDisabledFeature.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class GroupChatEnabledDisabledFeature(BaseModel):
GroupChat Enabled/Disabled Feature class
"""

id = PrimaryKeyField()
group_chat = ForeignKeyField(
GroupChat, backref="enabled_disabled_features", on_delete="CASCADE", on_update="CASCADE"
)
Expand Down
1 change: 0 additions & 1 deletion src/model/GroupChatEnabledFeaturePin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class GroupChatEnabledFeaturePin(BaseModel):
GroupChat Enabled Feature Pin class
"""

id = PrimaryKeyField()
group_chat = ForeignKeyField(
GroupChat, backref="enabled_features_pin", on_delete="CASCADE", on_update="CASCADE"
)
Expand Down
4 changes: 0 additions & 4 deletions src/model/GroupChatFeaturePinMessage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from datetime import datetime

from peewee import *

from src.model.BaseModel import BaseModel
Expand All @@ -11,7 +9,6 @@ class GroupChatFeaturePinMessage(BaseModel):
GroupChat Enabled Feature Pin class
"""

id = PrimaryKeyField()
group_chat = ForeignKeyField(
GroupChat,
backref="enabled_features_pin_messages",
Expand All @@ -20,7 +17,6 @@ class GroupChatFeaturePinMessage(BaseModel):
)
feature = SmallIntegerField()
message_id = BigIntegerField()
pin_date = DateTimeField(default=datetime.now)

class Meta:
db_table = "group_chat_feature_pin_message"
Expand Down
1 change: 0 additions & 1 deletion src/model/GroupUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class GroupUser(BaseModel):
Group User class
"""

id = PrimaryKeyField()
group = ForeignKeyField(Group, backref="groups", on_delete="RESTRICT", on_update="CASCADE")
user = ForeignKeyField(User, backref="users", on_delete="RESTRICT", on_update="CASCADE")
last_message_date = DateTimeField(default=datetime.datetime.now)
Expand Down
2 changes: 0 additions & 2 deletions src/model/ImpelDownLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ class ImpelDownLog(BaseModel):
Impel Down Log class
"""

id = PrimaryKeyField()
user = ForeignKeyField(
User, backref="impel_down_users", on_delete="CASCADE", on_update="CASCADE"
)
sentence_type = CharField(max_length=99, null=True)
source = CharField(max_length=10, null=True)
date_time = DateTimeField(default=datetime.now)
release_date_time = DateTimeField(null=True)
is_permanent = BooleanField(default=False)
bounty_action = CharField(max_length=99, null=True)
Expand Down
4 changes: 0 additions & 4 deletions src/model/IncomeTaxEvent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from peewee import *

from src.model.BaseModel import BaseModel
Expand All @@ -15,11 +13,9 @@ class IncomeTaxEvent(BaseModel):
IncomeTaxEvent class
"""

id = PrimaryKeyField()
user = ForeignKeyField(User, backref="income_tax_events")
event_id = IntegerField()
event_type = CharField()
date = DateTimeField(default=datetime.datetime.now)
starting_amount = BigIntegerField()
amount = BigIntegerField()
breakdown_list = TextField()
Expand Down
1 change: 0 additions & 1 deletion src/model/Leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Leaderboard(BaseModel):
Leaderboard class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
year: int | SmallIntegerField = SmallIntegerField()
week: int | SmallIntegerField = SmallIntegerField()
group: Group | ForeignKeyField = ForeignKeyField(Group, null=True, backref="leaderboards")
Expand Down
1 change: 0 additions & 1 deletion src/model/LeaderboardCrew.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class LeaderboardCrew(BaseModel):
Leaderboard class
"""

id: int | PrimaryKeyField = PrimaryKeyField()
leaderboard: Leaderboard | ForeignKeyField = ForeignKeyField(
Leaderboard, backref="leaderboard_crews", on_delete="CASCADE", on_update="CASCADE"
)
Expand Down
Loading

0 comments on commit 8b9f325

Please sign in to comment.