Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/migrations/12_create_profile_relations.go

38 lines
1.4 KiB
Go
Raw Normal View History

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
// CreateProfileRelationsUp creates profile-pokememes relation table
2017-10-11 06:53:50 +04:00
func CreateProfileRelationsUp(tx *sql.Tx) error {
2017-11-14 03:44:21 +04:00
request := "CREATE TABLE `profiles_pokememes` ("
request += "`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID связи',"
request += "`profile_id` int(11) NOT NULL COMMENT 'ID профиля',"
request += "`pokememe_id` int(11) NOT NULL COMMENT 'ID покемема',"
request += "`pokememe_lvl` int(11) NOT NULL COMMENT 'Уровень покемема',"
request += "`pokememe_rarity` varchar(191) NOT NULL DEFAULT 'common' COMMENT 'Редкость покемема',"
request += "`created_at` datetime NOT NULL COMMENT 'Добавлено в базу',"
request += "PRIMARY KEY (`id`),"
request += "UNIQUE KEY `id` (`id`),"
request += "KEY `profiles_pokememes_created_at` (`created_at`)"
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Профили-Покемемы';"
_, err := tx.Exec(request)
2017-10-18 07:03:34 +04:00
if err != nil {
return err
}
return nil
2017-10-11 06:53:50 +04:00
}
2017-11-14 03:44:21 +04:00
// CreateProfileRelationsDown drops profile-pokememes relation table
2017-10-11 06:53:50 +04:00
func CreateProfileRelationsDown(tx *sql.Tx) error {
2017-10-18 07:03:34 +04:00
_, err := tx.Exec("DROP TABLE `profiles_pokememes`;")
if err != nil {
return err
}
return nil
2017-10-11 06:53:50 +04:00
}