Пример #1
0
func TestDatabase(t *testing.T) {
	db, err := gorm.Open("sqlite3", "test.db")
	if err != nil {
		t.Fatal(err)
	}
	db.LogMode(true)
	i18n.Migrate(db)
	testProvider(t, &i18n.DatabaseProvider{Db: db, Logger: logger})
}
Пример #2
0
//Migrate db:migrate
func (p *Engine) Migrate(db *gorm.DB) {
	i18n.Migrate(db)

	db.AutoMigrate(
		&Setting{}, &Notice{},
		&User{}, &Role{}, &Permission{}, &Log{},
	)

	db.Model(&User{}).AddUniqueIndex("idx_user_provider_type_id", "provider_type", "provider_id")
	db.Model(&Role{}).AddUniqueIndex("idx_roles_name_resource_type_id", "name", "resource_type", "resource_id")
	db.Model(&Permission{}).AddUniqueIndex("idx_permissions_user_role", "user_id", "role_id")
}