From 8b9f3253278617ac6409b8c2f021f85f734a121e Mon Sep 17 00:00:00 2001 From: Nickelza Date: Tue, 20 Aug 2024 00:32:19 +0200 Subject: [PATCH] ref(model): Moved id to base model + added insertion date field to all models --- src/chat/private/private_chat_manager.py | 2 +- src/chat/private/screens/screen_prediction.py | 2 +- src/model/BaseModel.py | 3 +++ src/model/BountyGift.py | 4 ---- src/model/BountyLoan.py | 3 +-- src/model/Crew.py | 2 -- src/model/CrewAbility.py | 4 ---- src/model/CrewChestSpendingRecord.py | 4 ---- src/model/CrewJoinRequest.py | 2 -- src/model/CrewMemberChestContribution.py | 1 - src/model/DailyReward.py | 2 -- src/model/DavyBackFight.py | 2 -- src/model/DavyBackFightParticipant.py | 4 ---- src/model/DevilFruit.py | 1 - src/model/DevilFruitAbility.py | 1 - src/model/DevilFruitTrade.py | 2 -- src/model/DisabledNotification.py | 1 - src/model/DocQGame.py | 4 ---- src/model/Fight.py | 1 - src/model/Game.py | 2 -- src/model/Group.py | 2 -- src/model/GroupChat.py | 1 - src/model/GroupChatAutoDelete.py | 2 -- src/model/GroupChatEnabledDisabledFeature.py | 1 - src/model/GroupChatEnabledFeaturePin.py | 1 - src/model/GroupChatFeaturePinMessage.py | 4 ---- src/model/GroupUser.py | 1 - src/model/ImpelDownLog.py | 2 -- src/model/IncomeTaxEvent.py | 4 ---- src/model/Leaderboard.py | 1 - src/model/LeaderboardCrew.py | 1 - src/model/LeaderboardUser.py | 1 - src/model/LegendaryPirate.py | 4 ---- src/model/Plunder.py | 4 ---- src/model/Prediction.py | 4 ---- src/model/PredictionGroupChatMessage.py | 3 +-- src/model/PredictionOption.py | 1 - src/model/PredictionOptionUser.py | 4 ---- src/model/RedditGroupPost.py | 4 ---- src/model/SystemUpdate.py | 4 ---- src/model/SystemUpdateUser.py | 4 ---- src/model/UnmutedUser.py | 4 ---- src/model/User.py | 2 -- src/model/Warlord.py | 2 -- src/model/enums/Notification.py | 4 +--- src/service/crew_service.py | 5 ++--- 46 files changed, 10 insertions(+), 107 deletions(-) diff --git a/src/chat/private/private_chat_manager.py b/src/chat/private/private_chat_manager.py index a27f2bdf..45b70aec 100644 --- a/src/chat/private/private_chat_manager.py +++ b/src/chat/private/private_chat_manager.py @@ -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( diff --git a/src/chat/private/screens/screen_prediction.py b/src/chat/private/screens/screen_prediction.py index a8f16c0e..925ab329 100644 --- a/src/chat/private/screens/screen_prediction.py +++ b/src/chat/private/screens/screen_prediction.py @@ -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) ) diff --git a/src/model/BaseModel.py b/src/model/BaseModel.py index e1d6bc90..15ecc050 100644 --- a/src/model/BaseModel.py +++ b/src/model/BaseModel.py @@ -1,3 +1,5 @@ +from datetime import datetime + from peewee import * from resources.Database import Database @@ -12,6 +14,7 @@ class BaseModel(Model): """ id: int | PrimaryKeyField = PrimaryKeyField() + date = DateTimeField(default=datetime.now) class Meta: database = db_obj.get_db() diff --git a/src/model/BountyGift.py b/src/model/BountyGift.py index 6f7e97f7..b797e428 100644 --- a/src/model/BountyGift.py +++ b/src/model/BountyGift.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -14,7 +12,6 @@ class BountyGift(BaseModel): BountyGift class """ - id = PrimaryKeyField() sender = ForeignKeyField( User, backref="bounty_gift_senders", on_delete="CASCADE", on_update="CASCADE" ) @@ -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, diff --git a/src/model/BountyLoan.py b/src/model/BountyLoan.py index 5f639244..f327a649 100644 --- a/src/model/BountyLoan.py +++ b/src/model/BountyLoan.py @@ -14,10 +14,10 @@ class BountyLoan(BaseModel): - id = PrimaryKeyField() """ BountyLoan class """ + loaner = ForeignKeyField( User, backref="bounty_loaners", on_delete="CASCADE", on_update="CASCADE" ) @@ -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, diff --git a/src/model/Crew.py b/src/model/Crew.py index d61a68fd..c6356af6 100644 --- a/src/model/Crew.py +++ b/src/model/Crew.py @@ -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) diff --git a/src/model/CrewAbility.py b/src/model/CrewAbility.py index f3eb8d8b..99e2cbe2 100644 --- a/src/model/CrewAbility.py +++ b/src/model/CrewAbility.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -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) diff --git a/src/model/CrewChestSpendingRecord.py b/src/model/CrewChestSpendingRecord.py index 04b2f773..fb658e1e 100644 --- a/src/model/CrewChestSpendingRecord.py +++ b/src/model/CrewChestSpendingRecord.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -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) diff --git a/src/model/CrewJoinRequest.py b/src/model/CrewJoinRequest.py index 8d27646e..9189da5f 100644 --- a/src/model/CrewJoinRequest.py +++ b/src/model/CrewJoinRequest.py @@ -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 ) diff --git a/src/model/CrewMemberChestContribution.py b/src/model/CrewMemberChestContribution.py index 657bfc4a..e7a47836 100644 --- a/src/model/CrewMemberChestContribution.py +++ b/src/model/CrewMemberChestContribution.py @@ -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) diff --git a/src/model/DailyReward.py b/src/model/DailyReward.py index 4af88490..f85d798d 100644 --- a/src/model/DailyReward.py +++ b/src/model/DailyReward.py @@ -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() diff --git a/src/model/DavyBackFight.py b/src/model/DavyBackFight.py index 6f2b7ec6..48c48d34 100644 --- a/src/model/DavyBackFight.py +++ b/src/model/DavyBackFight.py @@ -18,7 +18,6 @@ class DavyBackFight(BaseModel): DavyBackFight class """ - id: int | PrimaryKeyField = PrimaryKeyField() challenger_crew: Crew | ForeignKeyField = ForeignKeyField( Crew, backref="davy_back_fights_challengers" ) @@ -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 ) diff --git a/src/model/DavyBackFightParticipant.py b/src/model/DavyBackFightParticipant.py index 9567062d..5eeefc01 100644 --- a/src/model/DavyBackFightParticipant.py +++ b/src/model/DavyBackFightParticipant.py @@ -1,5 +1,3 @@ -from datetime import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -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: diff --git a/src/model/DevilFruit.py b/src/model/DevilFruit.py index 3537cd7e..8c29018c 100644 --- a/src/model/DevilFruit.py +++ b/src/model/DevilFruit.py @@ -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) diff --git a/src/model/DevilFruitAbility.py b/src/model/DevilFruitAbility.py index b3139712..bebbfe31 100644 --- a/src/model/DevilFruitAbility.py +++ b/src/model/DevilFruitAbility.py @@ -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" ) diff --git a/src/model/DevilFruitTrade.py b/src/model/DevilFruitTrade.py index ef20d04d..d9c8ca71 100644 --- a/src/model/DevilFruitTrade.py +++ b/src/model/DevilFruitTrade.py @@ -16,7 +16,6 @@ class DevilFruitTrade(BaseModel): Devil Fruit Trade class """ - id = PrimaryKeyField() devil_fruit: DevilFruit | ForeignKeyField = ForeignKeyField( DevilFruit, null=True, @@ -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 diff --git a/src/model/DisabledNotification.py b/src/model/DisabledNotification.py index c5de72bf..786622ee 100644 --- a/src/model/DisabledNotification.py +++ b/src/model/DisabledNotification.py @@ -9,7 +9,6 @@ class DisabledNotification(BaseModel): DisabledNotification class """ - id = PrimaryKeyField() user = ForeignKeyField( User, backref="disabled_notification_users", on_delete="CASCADE", on_update="CASCADE" ) diff --git a/src/model/DocQGame.py b/src/model/DocQGame.py index 93444656..76c30a5b 100644 --- a/src/model/DocQGame.py +++ b/src/model/DocQGame.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * import constants as c @@ -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( diff --git a/src/model/Fight.py b/src/model/Fight.py index a7456c24..94e690b9 100644 --- a/src/model/Fight.py +++ b/src/model/Fight.py @@ -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" ) diff --git a/src/model/Game.py b/src/model/Game.py index ecfa6170..bf5849a6 100644 --- a/src/model/Game.py +++ b/src/model/Game.py @@ -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" ) @@ -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 ) diff --git a/src/model/Group.py b/src/model/Group.py index 57bb0ea2..0838f498 100644 --- a/src/model/Group.py +++ b/src/model/Group.py @@ -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) diff --git a/src/model/GroupChat.py b/src/model/GroupChat.py index faa52868..ef88ff52 100644 --- a/src/model/GroupChat.py +++ b/src/model/GroupChat.py @@ -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" ) diff --git a/src/model/GroupChatAutoDelete.py b/src/model/GroupChatAutoDelete.py index 3698fcda..eb55cafc 100644 --- a/src/model/GroupChatAutoDelete.py +++ b/src/model/GroupChatAutoDelete.py @@ -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: diff --git a/src/model/GroupChatEnabledDisabledFeature.py b/src/model/GroupChatEnabledDisabledFeature.py index fc387230..0d792705 100644 --- a/src/model/GroupChatEnabledDisabledFeature.py +++ b/src/model/GroupChatEnabledDisabledFeature.py @@ -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" ) diff --git a/src/model/GroupChatEnabledFeaturePin.py b/src/model/GroupChatEnabledFeaturePin.py index b9498366..a6b725db 100644 --- a/src/model/GroupChatEnabledFeaturePin.py +++ b/src/model/GroupChatEnabledFeaturePin.py @@ -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" ) diff --git a/src/model/GroupChatFeaturePinMessage.py b/src/model/GroupChatFeaturePinMessage.py index 0994a2e5..60dbca60 100644 --- a/src/model/GroupChatFeaturePinMessage.py +++ b/src/model/GroupChatFeaturePinMessage.py @@ -1,5 +1,3 @@ -from datetime import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -11,7 +9,6 @@ class GroupChatFeaturePinMessage(BaseModel): GroupChat Enabled Feature Pin class """ - id = PrimaryKeyField() group_chat = ForeignKeyField( GroupChat, backref="enabled_features_pin_messages", @@ -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" diff --git a/src/model/GroupUser.py b/src/model/GroupUser.py index 914142e4..e7bf9b67 100644 --- a/src/model/GroupUser.py +++ b/src/model/GroupUser.py @@ -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) diff --git a/src/model/ImpelDownLog.py b/src/model/ImpelDownLog.py index 670a321d..6d1c84ed 100644 --- a/src/model/ImpelDownLog.py +++ b/src/model/ImpelDownLog.py @@ -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) diff --git a/src/model/IncomeTaxEvent.py b/src/model/IncomeTaxEvent.py index 0fa8e650..c0d113cd 100644 --- a/src/model/IncomeTaxEvent.py +++ b/src/model/IncomeTaxEvent.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -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() diff --git a/src/model/Leaderboard.py b/src/model/Leaderboard.py index fa3e61e2..4715eada 100644 --- a/src/model/Leaderboard.py +++ b/src/model/Leaderboard.py @@ -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") diff --git a/src/model/LeaderboardCrew.py b/src/model/LeaderboardCrew.py index 6efde08a..df4948aa 100644 --- a/src/model/LeaderboardCrew.py +++ b/src/model/LeaderboardCrew.py @@ -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" ) diff --git a/src/model/LeaderboardUser.py b/src/model/LeaderboardUser.py index 125470c9..d53366f9 100644 --- a/src/model/LeaderboardUser.py +++ b/src/model/LeaderboardUser.py @@ -10,7 +10,6 @@ class LeaderboardUser(BaseModel): Leaderboard class """ - id: int | PrimaryKeyField = PrimaryKeyField() leaderboard = ForeignKeyField( Leaderboard, backref="leaderboard_users", on_delete="CASCADE", on_update="CASCADE" ) diff --git a/src/model/LegendaryPirate.py b/src/model/LegendaryPirate.py index 0ee27445..7beb1550 100644 --- a/src/model/LegendaryPirate.py +++ b/src/model/LegendaryPirate.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -11,13 +9,11 @@ class LegendaryPirate(BaseModel): Legendary Pirate class """ - id = PrimaryKeyField() user = ForeignKeyField( User, backref="legendary_pirates", on_delete="CASCADE", on_update="CASCADE" ) epithet = CharField(max_length=99, null=True) reason = CharField(max_length=999, null=True) - date = DateTimeField(default=datetime.datetime.now) class Meta: db_table = "legendary_pirate" diff --git a/src/model/Plunder.py b/src/model/Plunder.py index c4f80879..99907e45 100644 --- a/src/model/Plunder.py +++ b/src/model/Plunder.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * import resources.Environment as Env @@ -21,7 +19,6 @@ class Plunder(BaseModel): Plunder class """ - id: int | PrimaryKeyField = PrimaryKeyField() challenger: User | ForeignKeyField = ForeignKeyField( User, backref="plunder_challengers", on_delete="CASCADE", on_update="CASCADE" ) @@ -29,7 +26,6 @@ class Plunder(BaseModel): User, backref="plunder_opponents", on_delete="CASCADE", on_update="CASCADE" ) win_probability: float | FloatField = FloatField() - date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now) status: bool | SmallIntegerField = SmallIntegerField(default=GameStatus.IN_PROGRESS) group_chat: GroupChat | ForeignKeyField = ForeignKeyField( GroupChat, diff --git a/src/model/Prediction.py b/src/model/Prediction.py index 0bb3f352..36b07033 100644 --- a/src/model/Prediction.py +++ b/src/model/Prediction.py @@ -1,5 +1,3 @@ -from datetime import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -12,11 +10,9 @@ class Prediction(BaseModel): Prediction class """ - id = PrimaryKeyField() type = CharField(max_length=20, null=False) status = SmallIntegerField(default=PredictionStatus.NEW) question = CharField(max_length=999) - creation_date = DateTimeField(default=datetime.now) send_date = DateTimeField(null=True) end_date = DateTimeField(null=True) cut_off_date = DateTimeField(null=True) diff --git a/src/model/PredictionGroupChatMessage.py b/src/model/PredictionGroupChatMessage.py index 49448690..344e2a38 100644 --- a/src/model/PredictionGroupChatMessage.py +++ b/src/model/PredictionGroupChatMessage.py @@ -12,7 +12,6 @@ class PredictionGroupChatMessage(BaseModel): Prediction group chat message class """ - id = PrimaryKeyField() prediction = ForeignKeyField( Prediction, backref="prediction_group_chat_messages", @@ -26,7 +25,7 @@ class PredictionGroupChatMessage(BaseModel): on_update="CASCADE", ) message_id = BigIntegerField() - sent_date = DateTimeField(default=datetime.now) + date = DateTimeField(default=datetime.now) class Meta: db_table = "prediction_group_chat_message" diff --git a/src/model/PredictionOption.py b/src/model/PredictionOption.py index c73e0454..f3a57084 100644 --- a/src/model/PredictionOption.py +++ b/src/model/PredictionOption.py @@ -9,7 +9,6 @@ class PredictionOption(BaseModel): Prediction option class """ - id = PrimaryKeyField() prediction = ForeignKeyField( Prediction, backref="prediction_options", on_delete="CASCADE", on_update="CASCADE" ) diff --git a/src/model/PredictionOptionUser.py b/src/model/PredictionOptionUser.py index 42784dc0..7809905a 100644 --- a/src/model/PredictionOptionUser.py +++ b/src/model/PredictionOptionUser.py @@ -1,5 +1,3 @@ -from datetime import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -14,7 +12,6 @@ class PredictionOptionUser(BaseModel): Prediction option user class """ - id = PrimaryKeyField() prediction = ForeignKeyField( Prediction, backref="prediction_options_users", on_delete="RESTRICT", on_update="RESTRICT" ) @@ -29,7 +26,6 @@ class PredictionOptionUser(BaseModel): ) wager = BigIntegerField() max_refund_wager_boost = IntegerField(default=0) - date = DateTimeField(default=datetime.now) prediction_group_chat_message = ForeignKeyField( PredictionGroupChatMessage, null=True, diff --git a/src/model/RedditGroupPost.py b/src/model/RedditGroupPost.py index 73862318..276c92c3 100644 --- a/src/model/RedditGroupPost.py +++ b/src/model/RedditGroupPost.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -10,9 +8,7 @@ class RedditGroupPost(BaseModel): RedditGroupPost class """ - id = PrimaryKeyField() short_link = CharField(max_length=99, unique=True) - date = DateTimeField(default=datetime.datetime.now) message_id = BigIntegerField() class Meta: diff --git a/src/model/SystemUpdate.py b/src/model/SystemUpdate.py index 8b87b4f4..ba4287ff 100644 --- a/src/model/SystemUpdate.py +++ b/src/model/SystemUpdate.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -10,10 +8,8 @@ class SystemUpdate(BaseModel): SystemUpdate class """ - id = PrimaryKeyField() title = CharField() description = CharField(max_length=999) - date = DateTimeField(default=datetime.datetime.now) chat_id = CharField() message_id = BigIntegerField() diff --git a/src/model/SystemUpdateUser.py b/src/model/SystemUpdateUser.py index 9a6314f8..a5e1d22c 100644 --- a/src/model/SystemUpdateUser.py +++ b/src/model/SystemUpdateUser.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -12,10 +10,8 @@ class SystemUpdateUser(BaseModel): SystemUpdateUser class """ - id = PrimaryKeyField() system_update = ForeignKeyField(SystemUpdate, backref="system_update") user = ForeignKeyField(User, backref="system_update") - date = DateTimeField(default=datetime.datetime.now) error = CharField(null=True) class Meta: diff --git a/src/model/UnmutedUser.py b/src/model/UnmutedUser.py index f9c55973..0ee0481a 100644 --- a/src/model/UnmutedUser.py +++ b/src/model/UnmutedUser.py @@ -1,5 +1,3 @@ -import datetime - from peewee import * from src.model.BaseModel import BaseModel @@ -12,7 +10,6 @@ class UnmutedUser(BaseModel): Unmuted user class """ - id = PrimaryKeyField() user = ForeignKeyField(User, backref="unmuted_users", on_delete="CASCADE", on_update="CASCADE") group_chat = ForeignKeyField( GroupChat, @@ -21,7 +18,6 @@ class UnmutedUser(BaseModel): on_delete="CASCADE", on_update="CASCADE", ) - date = DateTimeField(default=datetime.datetime.now) class Meta: db_table = "unmuted_user" diff --git a/src/model/User.py b/src/model/User.py index 5627c16d..fa8991e7 100644 --- a/src/model/User.py +++ b/src/model/User.py @@ -35,12 +35,10 @@ class User(BaseModel): User class """ - id: int | PrimaryKeyField = PrimaryKeyField() tg_user_id: str | CharField = CharField(max_length=99, unique=True) tg_first_name: str | CharField = CharField(max_length=99) tg_last_name: str | CharField = CharField(max_length=99) tg_username: str | CharField = CharField(max_length=99) - join_date: datetime.datetime | DateTimeField = DateTimeField(default=datetime.datetime.now) bounty: int | BigIntegerField = BigIntegerField(default=0) total_gained_bounty: int | BigIntegerField = BigIntegerField( default=0, constraints=[Check("total_gained_bounty >= 0")] diff --git a/src/model/Warlord.py b/src/model/Warlord.py index cb0d12fc..7094743f 100644 --- a/src/model/Warlord.py +++ b/src/model/Warlord.py @@ -11,11 +11,9 @@ class Warlord(BaseModel): Warlord class """ - id = PrimaryKeyField() user = ForeignKeyField(User, backref="warlords", on_delete="CASCADE", on_update="CASCADE") epithet = CharField(max_length=99, null=True) reason = CharField(max_length=999, null=True) - date = DateTimeField(default=datetime.datetime.now) end_date = DateTimeField() original_end_date = DateTimeField() # In case it was ended early revoke_reason = CharField(max_length=999, null=True) diff --git a/src/model/enums/Notification.py b/src/model/enums/Notification.py index d3687afd..f5324a65 100644 --- a/src/model/enums/Notification.py +++ b/src/model/enums/Notification.py @@ -1023,9 +1023,7 @@ def build(self) -> str: return self.text.format( escape_valid_markdown_chars(self.crew_ability.get_description()), self.crew_ability.get_value_with_sign(), - get_remaining_duration( - self.crew_ability.expiration_date, self.crew_ability.acquired_date - ), + get_remaining_duration(self.crew_ability.expiration_date, self.crew_ability.date), ) diff --git a/src/service/crew_service.py b/src/service/crew_service.py index fe665721..56532e4d 100644 --- a/src/service/crew_service.py +++ b/src/service/crew_service.py @@ -411,7 +411,6 @@ async def add_crew_ability( ability.value = ability_value ability.acquired_method = acquired_method ability.acquired_user = acquired_user - ability.acquired_date = now ability.expiration_date = get_datetime_in_future_days( Env.CREW_ABILITY_DURATION_DAYS.get_int(), start_time=now ) @@ -549,8 +548,8 @@ def get_crew_overview_text(crew: Crew, user: User, from_search: bool = True) -> ), captain.get_markdown_mention(), first_mate_text, - user.get_date_formatted(crew.creation_date), - get_elapsed_duration(crew.creation_date), + user.get_date_formatted(crew.date), + get_elapsed_duration(crew.date), len(crew.get_members()), crew.max_members, active_abilities_count_text,