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/31_change_squads_table.go
2018-02-17 07:03:58 +04:00

79 lines
1.8 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"
)
// ChangeSquadsTableUp changes `sqauds` to new format
func ChangeSquadsTableUp(tx *sql.Tx) error {
request := "ALTER TABLE `squads` DROP COLUMN `flood_chat_id`"
_, err := tx.Exec(request)
if err != nil {
return err
}
request = "ALTER TABLE `squads` DROP COLUMN `author_id`"
_, err = tx.Exec(request)
if err != nil {
return err
}
request = "ALTER TABLE `squads` ADD COLUMN `min_level` int(11) NOT NULL DEFAULT 0 AFTER `chat_id`"
_, err = tx.Exec(request)
if err != nil {
return err
}
request = "ALTER TABLE `squads` ADD COLUMN `max_level` int(11) NOT NULL DEFAULT 0 AFTER `min_level`"
_, err = tx.Exec(request)
if err != nil {
return err
}
request = "ALTER TABLE `squads` ADD COLUMN `invite_link` varchar(191) NOT NULL DEFAULT 'https://example.com' AFTER `max_level`"
_, err = tx.Exec(request)
if err != nil {
return err
}
return nil
}
// ChangeSquadsTableDown reverts `squads` to old format
func ChangeSquadsTableDown(tx *sql.Tx) error {
request := "ALTER TABLE `squads` ADD COLUMN `flood_chat_id` int(11) NOT NULL AFTER `chat_id`"
_, err := tx.Exec(request)
if err != nil {
return err
}
request = "ALTER TABLE `squads` ADD COLUMN `author_id` int(11) NOT NULL AFTER `flood_chat_id"
_, err = tx.Exec(request)
if err != nil {
return err
}
request = "ALTER TABLE `squads` DROP COLUMN `min_level`"
_, err = tx.Exec(request)
if err != nil {
return err
}
request = "ALTER TABLE `squads` DROP COLUMN `max_level`"
_, err = tx.Exec(request)
if err != nil {
return err
}
request = "ALTER TABLE `squads` DROP COLUMN `invite_link`"
_, err = tx.Exec(request)
if err != nil {
return err
}
return nil
}