2017-10-11 06:53:50 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
|
|
package migrations
|
|
|
|
|
|
|
|
|
|
import (
|
2017-10-18 07:03:34 +04:00
|
|
|
|
"database/sql"
|
2017-10-11 06:53:50 +04:00
|
|
|
|
)
|
|
|
|
|
|
2017-11-14 03:44:21 +04:00
|
|
|
|
// ProfileDataAdditionsUp creates some helping databases for profiles
|
2017-10-11 06:53:50 +04:00
|
|
|
|
func ProfileDataAdditionsUp(tx *sql.Tx) error {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err := tx.Exec("ALTER TABLE `profiles` ADD `pokeballs` INT(11) DEFAULT 5 NOT NULL COMMENT 'Покеболы' AFTER `level_id`")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2017-10-11 06:53:50 +04:00
|
|
|
|
|
2017-11-14 03:44:21 +04:00
|
|
|
|
request := "CREATE TABLE `levels` ("
|
|
|
|
|
request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID уровня и его номер',"
|
|
|
|
|
request += "`max_exp` int(11) NOT NULL COMMENT 'Опыт для прохождения уровня',"
|
|
|
|
|
request += "`max_egg` int(11) NOT NULL COMMENT 'Опыт для открытия яйца',"
|
|
|
|
|
request += "`created_at` datetime NOT NULL COMMENT 'Добавлен в базу',"
|
|
|
|
|
request += "PRIMARY KEY (`id`),"
|
|
|
|
|
request += "UNIQUE KEY `id` (`id`),"
|
|
|
|
|
request += "KEY `levels_created_at` (`created_at`)"
|
2018-03-31 16:45:09 +04:00
|
|
|
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Уровни'"
|
2017-11-14 03:44:21 +04:00
|
|
|
|
_, err = tx.Exec(request)
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2017-10-11 06:53:50 +04:00
|
|
|
|
|
2017-10-18 07:03:34 +04:00
|
|
|
|
// Insert levels
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 200, 6, NOW())")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 400, 12, NOW())")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 800, 24, NOW())")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 1600, 48, NOW())")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 3200, 96, NOW())")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 6400, 192, NOW())")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 12800, 384, NOW())")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 25600, 768, NOW())")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 51200, 1536, NOW())")
|
2017-10-11 06:53:50 +04:00
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return err
|
2017-10-11 06:53:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-14 03:44:21 +04:00
|
|
|
|
// ProfileDataAdditionsDown drops `levels` table and `pokeballs` column of `profiles` table
|
2017-10-11 06:53:50 +04:00
|
|
|
|
func ProfileDataAdditionsDown(tx *sql.Tx) error {
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err := tx.Exec("ALTER TABLE `profiles` DROP COLUMN `pokeballs`")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2017-10-11 06:53:50 +04:00
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
_, err = tx.Exec("DROP TABLE `levels`")
|
2017-10-11 06:53:50 +04:00
|
|
|
|
|
2018-03-31 16:45:09 +04:00
|
|
|
|
return err
|
2017-10-11 06:53:50 +04:00
|
|
|
|
}
|