forked from TF2Stadium/Helen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrations.go
35 lines (28 loc) · 940 Bytes
/
migrations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package migrations
import (
"os"
"github.com/TF2Stadium/Helen/config"
"github.com/TF2Stadium/Helen/database"
"github.com/TF2Stadium/Helen/models"
)
func Do() {
database.DB.AutoMigrate(&models.Player{})
database.DB.AutoMigrate(&models.Lobby{})
database.DB.AutoMigrate(&models.LobbySlot{})
database.DB.AutoMigrate(&models.ServerRecord{})
database.DB.AutoMigrate(&models.PlayerStats{})
database.DB.AutoMigrate(&models.PlayerSetting{})
database.DB.Model(&models.LobbySlot{}).AddUniqueIndex("idx_lobby_slot_lobby_id_slot", "lobby_id", "slot")
database.DB.Model(&models.PlayerSetting{}).AddUniqueIndex("idx_player_id_key", "player_id", "key")
}
func TestCleanup() {
if os.Getenv("DEPLOYMENT_ENV") == "" {
os.Setenv("DEPLOYMENT_ENV", "test")
defer os.Unsetenv("DEPLOYMENT_ENV")
}
config.SetupConstants()
database.Init()
database.DB.Exec("DROP SCHEMA public CASCADE;")
database.DB.Exec("CREATE SCHEMA public;")
Do()
}