Archive pokememes
This commit is contained in:
parent
3a5411f814
commit
be9b2d72f1
@ -150,6 +150,15 @@ func (dc *DataCache) UpdatePlayerTimestamp(playerID int) error {
|
|||||||
dc.playersMutex.Unlock()
|
dc.playersMutex.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
dc.squadsMutex.Lock()
|
||||||
|
for i := range dc.squadPlayers {
|
||||||
|
for j := range dc.squadPlayers[i] {
|
||||||
|
if dc.squadPlayers[i][j].Player.ID == playerID {
|
||||||
|
dc.squadPlayers[i][j].Player = *dc.players[playerID]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dc.squadsMutex.Unlock()
|
||||||
dc.playersMutex.Unlock()
|
dc.playersMutex.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ func (dc *DataCache) initPokememes() {
|
|||||||
func (dc *DataCache) loadPokememes() {
|
func (dc *DataCache) loadPokememes() {
|
||||||
c.Log.Info("Load current Pokememes data from database to DataCache...")
|
c.Log.Info("Load current Pokememes data from database to DataCache...")
|
||||||
pokememes := []dbmapping.Pokememe{}
|
pokememes := []dbmapping.Pokememe{}
|
||||||
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes")
|
err := c.Db.Select(&pokememes, "SELECT * FROM pokememes WHERE is_active=1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This is critical error and we need to stop immediately!
|
// This is critical error and we need to stop immediately!
|
||||||
c.Log.Fatal(err.Error())
|
c.Log.Fatal(err.Error())
|
||||||
|
@ -64,6 +64,16 @@ func (dc *DataCache) AddProfile(profile *dbmapping.Profile) (int, error) {
|
|||||||
dc.currentProfilesMutex.Lock()
|
dc.currentProfilesMutex.Lock()
|
||||||
dc.profiles[insertedProfile.ID] = &insertedProfile
|
dc.profiles[insertedProfile.ID] = &insertedProfile
|
||||||
dc.currentProfiles[insertedProfile.PlayerID] = &insertedProfile
|
dc.currentProfiles[insertedProfile.PlayerID] = &insertedProfile
|
||||||
|
|
||||||
|
dc.squadsMutex.Lock()
|
||||||
|
for i := range dc.squadPlayers {
|
||||||
|
for j := range dc.squadPlayers[i] {
|
||||||
|
if dc.squadPlayers[i][j].Player.ID == insertedProfile.PlayerID {
|
||||||
|
dc.squadPlayers[i][j].Profile = insertedProfile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dc.squadsMutex.Unlock()
|
||||||
dc.currentProfilesMutex.Unlock()
|
dc.currentProfilesMutex.Unlock()
|
||||||
dc.profilesMutex.Unlock()
|
dc.profilesMutex.Unlock()
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ type Pokememe struct {
|
|||||||
Purchaseable bool `db:"purchaseable"`
|
Purchaseable bool `db:"purchaseable"`
|
||||||
ImageURL string `db:"image_url"`
|
ImageURL string `db:"image_url"`
|
||||||
PlayerID int `db:"player_id"`
|
PlayerID int `db:"player_id"`
|
||||||
|
IsActive int `db:"is_active"`
|
||||||
CreatedAt time.Time `db:"created_at"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
lib/migrations/32_add_is_active_to_pokememes.go
Normal file
30
lib/migrations/32_add_is_active_to_pokememes.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddIsActiveToPokememesUp adds `is_active` to `pokememes`
|
||||||
|
func AddIsActiveToPokememesUp(tx *sql.Tx) error {
|
||||||
|
request := "ALTER TABLE `pokememes` ADD COLUMN `is_active` tinyint(1) DEFAULT 1 NOT NULL COMMENT 'Является ли покемем играющим в данный момент?'"
|
||||||
|
_, err := tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddIsActiveToPokememesDown removes `is_active` from `pokememes` table
|
||||||
|
func AddIsActiveToPokememesDown(tx *sql.Tx) error {
|
||||||
|
request := "ALTER TABLE `pokememes` DROP COLUMN `is_active`"
|
||||||
|
_, err := tx.Exec(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -42,6 +42,7 @@ func (m *Migrations) Init() {
|
|||||||
goose.AddNamedMigration("29_fix_leagues_names.go", FixLeaguesNamesUp, FixLeaguesNamesDown)
|
goose.AddNamedMigration("29_fix_leagues_names.go", FixLeaguesNamesUp, FixLeaguesNamesDown)
|
||||||
goose.AddNamedMigration("30_create_alarms.go", CreateAlarmsUp, CreateAlarmsUp)
|
goose.AddNamedMigration("30_create_alarms.go", CreateAlarmsUp, CreateAlarmsUp)
|
||||||
goose.AddNamedMigration("31_change_squads_table.go", ChangeSquadsTableUp, ChangeSquadsTableDown)
|
goose.AddNamedMigration("31_change_squads_table.go", ChangeSquadsTableUp, ChangeSquadsTableDown)
|
||||||
|
goose.AddNamedMigration("32_add_is_active_to_pokememes.go", AddIsActiveToPokememesUp, AddIsActiveToPokememesDown)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate migrates database to current version
|
// Migrate migrates database to current version
|
||||||
|
Reference in New Issue
Block a user