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 Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package migrations
import (
"database/sql"
)
// CreateProfileRelationsUp creates profile-pokememes relation table
func CreateProfileRelationsUp(tx *sql.Tx) error {
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)
if err != nil {
return err
}
return nil
}
// CreateProfileRelationsDown drops profile-pokememes relation table
func CreateProfileRelationsDown(tx *sql.Tx) error {
_, err := tx.Exec("DROP TABLE `profiles_pokememes`;")
if err != nil {
return err
}
return nil
}