models

package
v0.0.0-...-d7ce4c8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InitAdmin = &gormigrate.Migration{
	ID: "init_admin",
	Migrate: func(tx *gorm.DB) error {
		var err error

		type adminUser struct {
			ID        uint64 `json:"id,omitempty"`
			Email     string `gorm:"not null;unique"`
			FirstName string
			LastName  string
			Password  string
			Username  string `json:"username,omitempty"`
			Role      string `json:"role,omitempty"`
			LastLogin *time.Time
			CreatedAt time.Time
			UpdatedAt time.Time
			DeletedAt *time.Time
		}

		if err = tx.CreateTable(&adminUser{}).Error; err != nil {
			go utils.LogErrToFile(err.Error())
			return err
		}
		var pwd []byte
		if pwd, err = bcrypt.GenerateFromPassword([]byte("1234567"), bcrypt.DefaultCost); err != nil {
			go utils.LogErrToFile(err.Error())
			return err
		}

		usr := adminUser{
			ID:        1,
			Email:     "root@gmail.com",
			FirstName: "root",
			LastName:  "root",
			Username:  "root",
			Role:      models.Role.ROOT,
			Password:  string(pwd),
		}
		return tx.Save(&usr).Error
	},
	Rollback: func(tx *gorm.DB) error {
		return tx.DropTable("admin_users").Error
	},
}

InitAdmin ...

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL