From 97f8569178efe58c323b58f8e0cac5fc4be73808 Mon Sep 17 00:00:00 2001 From: Eccentric Date: Sun, 4 Feb 2024 02:05:31 +0000 Subject: [PATCH] Small tables rework --- person/attribute.go | 6 ++--- person/gift.go | 2 +- person/item.go | 6 ++--- person/person.go | 2 +- person/profile.go | 2 +- storage/postgres.go | 22 +++++++++--------- storage/storage.go | 8 +++---- storage/tables.go | 54 +++++++++++++++++++++++++++++++++------------ 8 files changed, 65 insertions(+), 37 deletions(-) diff --git a/person/attribute.go b/person/attribute.go index 25b5ed8..1f8250a 100644 --- a/person/attribute.go +++ b/person/attribute.go @@ -25,7 +25,7 @@ func NewAttribute(key string, value interface{}) *Attribute { } } -func FromDatabaseAttribute(db *storage.DB_PAttribute) *Attribute { +func FromDatabaseAttribute(db *storage.DB_Attribute) *Attribute { return &Attribute{ ID: db.ID, ProfileID: db.ProfileID, @@ -35,8 +35,8 @@ func FromDatabaseAttribute(db *storage.DB_PAttribute) *Attribute { } } -func (a *Attribute) ToDatabase(profileId string) *storage.DB_PAttribute { - return &storage.DB_PAttribute{ +func (a *Attribute) ToDatabase(profileId string) *storage.DB_Attribute { + return &storage.DB_Attribute{ ID: a.ID, ProfileID: profileId, Key: a.Key, diff --git a/person/gift.go b/person/gift.go index 5739558..a5ef365 100644 --- a/person/gift.go +++ b/person/gift.go @@ -96,7 +96,7 @@ func (g *Gift) Delete() { } func (g *Gift) ToDatabase(profileId string) *storage.DB_Gift { - profileLoot := []storage.DB_Loot{} + profileLoot := []storage.DB_GiftLoot{} for _, item := range g.Loot { profileLoot = append(profileLoot, *item.ToLootDatabase(g.ID)) diff --git a/person/item.go b/person/item.go index 0d5177b..488808d 100644 --- a/person/item.go +++ b/person/item.go @@ -58,7 +58,7 @@ func FromDatabaseItem(item *storage.DB_Item) *Item { } } -func FromDatabaseLoot(item *storage.DB_Loot) *Item { +func FromDatabaseLoot(item *storage.DB_GiftLoot) *Item { return &Item{ ID: item.ID, TemplateID: item.TemplateID, @@ -202,8 +202,8 @@ func (i *Item) Save() { storage.Repo.SaveItem(i.ToDatabase(i.ProfileID)) } -func (i *Item) ToLootDatabase(giftId string) *storage.DB_Loot { - return &storage.DB_Loot{ +func (i *Item) ToLootDatabase(giftId string) *storage.DB_GiftLoot { + return &storage.DB_GiftLoot{ GiftID: giftId, ProfileType: i.ProfileType, ID: i.ID, diff --git a/person/person.go b/person/person.go index d98926f..2743225 100644 --- a/person/person.go +++ b/person/person.go @@ -330,7 +330,7 @@ func (p *Person) ToDatabase() *storage.DB_Person { Gifts: []storage.DB_Gift{}, Quests: []storage.DB_Quest{}, Loadouts: []storage.DB_Loadout{}, - Attributes: []storage.DB_PAttribute{}, + Attributes: []storage.DB_Attribute{}, Revision: profile.Revision, } diff --git a/person/profile.go b/person/profile.go index c0b4fe1..aed3475 100644 --- a/person/profile.go +++ b/person/profile.go @@ -437,7 +437,7 @@ func (p *Profile) ToDatabase() *storage.DB_Profile { Gifts: []storage.DB_Gift{}, Quests: []storage.DB_Quest{}, Loadouts: []storage.DB_Loadout{}, - Attributes: []storage.DB_PAttribute{}, + Attributes: []storage.DB_Attribute{}, Revision: p.Revision, } diff --git a/storage/postgres.go b/storage/postgres.go index 029d77a..04922d7 100644 --- a/storage/postgres.go +++ b/storage/postgres.go @@ -35,17 +35,19 @@ func (s *PostgresStorage) Migrate(table interface{}, tableName string) { func (s *PostgresStorage) MigrateAll() { s.Migrate(&DB_Person{}, "Persons") + s.Migrate(&DB_Relationship{}, "Relationships") s.Migrate(&DB_Profile{}, "Profiles") - s.Migrate(&DB_Item{}, "Items") - s.Migrate(&DB_Gift{}, "Gifts") - s.Migrate(&DB_Quest{}, "Quests") + s.Migrate(&DB_Attribute{}, "Attributes") s.Migrate(&DB_Loadout{}, "Loadouts") - s.Migrate(&DB_Loot{}, "Loot") + s.Migrate(&DB_Item{}, "Items") + s.Migrate(&DB_Purchase{}, "Purchases") + s.Migrate(&DB_PurchaseLoot{}, "PurchaseLoot") s.Migrate(&DB_VariantChannel{}, "Variants") - s.Migrate(&DB_PAttribute{}, "Attributes") + s.Migrate(&DB_Quest{}, "Quests") + s.Migrate(&DB_Gift{}, "Gifts") + s.Migrate(&DB_GiftLoot{}, "GiftLoot") s.Migrate(&DB_DiscordPerson{}, "Discords") s.Migrate(&DB_SeasonStat{}, "Stats") - s.Migrate(&DB_Relationship{}, "Relationships") } func (s *PostgresStorage) DropTables() { @@ -242,12 +244,12 @@ func (s *PostgresStorage) DeleteQuest(questId string) { s.Postgres.Delete(&DB_Quest{}, "id = ?", questId) } -func (s *PostgresStorage) SaveLoot(loot *DB_Loot) { +func (s *PostgresStorage) SaveLoot(loot *DB_GiftLoot) { s.Postgres.Save(loot) } func (s *PostgresStorage) DeleteLoot(lootId string) { - s.Postgres.Delete(&DB_Loot{}, "id = ?", lootId) + s.Postgres.Delete(&DB_GiftLoot{}, "id = ?", lootId) } func (s *PostgresStorage) SaveGift(gift *DB_Gift) { @@ -258,12 +260,12 @@ func (s *PostgresStorage) DeleteGift(giftId string) { s.Postgres.Delete(&DB_Gift{}, "id = ?", giftId) } -func (s *PostgresStorage) SaveAttribute(attribute *DB_PAttribute) { +func (s *PostgresStorage) SaveAttribute(attribute *DB_Attribute) { s.Postgres.Save(attribute) } func (s *PostgresStorage) DeleteAttribute(attributeId string) { - s.Postgres.Delete(&DB_PAttribute{}, "id = ?", attributeId) + s.Postgres.Delete(&DB_Attribute{}, "id = ?", attributeId) } func (s *PostgresStorage) SaveLoadout(loadout *DB_Loadout) { diff --git a/storage/storage.go b/storage/storage.go index e416d2d..7d7f938 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -37,13 +37,13 @@ type Storage interface { SaveQuest(quest *DB_Quest) DeleteQuest(questId string) - SaveLoot(loot *DB_Loot) + SaveLoot(loot *DB_GiftLoot) DeleteLoot(lootId string) SaveGift(gift *DB_Gift) DeleteGift(giftId string) - SaveAttribute(attribute *DB_PAttribute) + SaveAttribute(attribute *DB_Attribute) DeleteAttribute(attributeId string) SaveLoadout(loadout *DB_Loadout) @@ -175,7 +175,7 @@ func (r *Repository) DeleteQuest(questId string) { r.Storage.DeleteQuest(questId) } -func (r *Repository) SaveLoot(loot *DB_Loot) { +func (r *Repository) SaveLoot(loot *DB_GiftLoot) { r.Storage.SaveLoot(loot) } @@ -191,7 +191,7 @@ func (r *Repository) DeleteGift(giftId string) { r.Storage.DeleteGift(giftId) } -func (r *Repository) SaveAttribute(attribute *DB_PAttribute) { +func (r *Repository) SaveAttribute(attribute *DB_Attribute) { r.Storage.SaveAttribute(attribute) } diff --git a/storage/tables.go b/storage/tables.go index f1d9c13..4751053 100644 --- a/storage/tables.go +++ b/storage/tables.go @@ -36,7 +36,7 @@ type DB_Profile struct { Items []DB_Item `gorm:"foreignkey:ProfileID"` Gifts []DB_Gift `gorm:"foreignkey:ProfileID"` Quests []DB_Quest `gorm:"foreignkey:ProfileID"` - Attributes []DB_PAttribute `gorm:"foreignkey:ProfileID"` + Attributes []DB_Attribute `gorm:"foreignkey:ProfileID"` Loadouts []DB_Loadout `gorm:"foreignkey:ProfileID"` Type string Revision int @@ -46,7 +46,7 @@ func (DB_Profile) TableName() string { return "Profiles" } -type DB_PAttribute struct { +type DB_Attribute struct { ID string `gorm:"primary_key"` ProfileID string Key string @@ -54,7 +54,7 @@ type DB_PAttribute struct { Type string } -func (DB_PAttribute) TableName() string { +func (DB_Attribute) TableName() string { return "Attributes" } @@ -94,6 +94,34 @@ func (DB_Item) TableName() string { return "Items" } +type DB_Purchase struct { + ID string `gorm:"primary_key"` + ProfileID string `gorm:"index"` + Loot []DB_PurchaseLoot `gorm:"foreignkey:PurchaseID"` + OfferID string + PurchaseDate int64 + FreeRefundExpiry int64 + RefundExpiry int64 + Refundable bool + Refunded bool +} + +func (DB_Purchase) TableName() string { + return "Purchases" +} + +type DB_PurchaseLoot struct { + ID string `gorm:"primary_key"` + PurchaseID string `gorm:"index"` + TemplateID string + Quantity int + ProfileType string +} + +func (DB_PurchaseLoot) TableName() string { + return "PurchaseLoot" +} + type DB_VariantChannel struct { ID string `gorm:"primary_key"` ItemID string `gorm:"index"` @@ -129,14 +157,14 @@ type DB_Gift struct { FromID string GiftedAt int64 Message string - Loot []DB_Loot `gorm:"foreignkey:GiftID"` + Loot []DB_GiftLoot `gorm:"foreignkey:GiftID"` } func (DB_Gift) TableName() string { return "Gifts" } -type DB_Loot struct { +type DB_GiftLoot struct { ID string `gorm:"primary_key"` GiftID string `gorm:"index"` TemplateID string @@ -144,8 +172,8 @@ type DB_Loot struct { ProfileType string } -func (DB_Loot) TableName() string { - return "Loot" +func (DB_GiftLoot) TableName() string { + return "GiftLoot" } type DB_DiscordPerson struct { @@ -166,14 +194,12 @@ type DB_SeasonStat struct { ID string `gorm:"primary_key"` PersonID string Build string - XP int - Level int - LevelClaimed int - Stars int - Tier int - TierClaimed int + SeasonXP int + SeasonalLevel int + SeasonalTier int + BattleStars int } func (DB_SeasonStat) TableName() string { return "Stats" -} \ No newline at end of file +}