Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CreateUser = gormigrate.Migration{ ID: "2024-09-18:create-users", Migrate: func(tx *gorm.DB) error { if err := tx.AutoMigrate(&User{}); err != nil { return err } if err := tx.Migrator().AddColumn(&accountWithNullableUserID{}, "user_id"); err != nil { return err } var accounts []accountWithNullableUserID if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).Find(&accounts).Error; err != nil { return err } if len(accounts) != 0 { user := User{ Name: "default", } if err := tx.Create(&user).Error; err != nil { return err } if err := tx.Model(&account{}).Where("1 = 1").Update("user_id", user.ID).Error; err != nil { return err } } return tx.Migrator().AlterColumn(&account{}, "user_id") }, Rollback: func(tx *gorm.DB) error { if err := tx.Migrator().DropColumn(&account{}, "user_id"); err != nil { return err } return tx.Migrator().DropTable(&User{}) }, }
CreateUser defines the migration, which creates the users.
Functions ¶
This section is empty.
Types ¶
type User ¶
type User struct { ID string `gorm:"type:uuid;primary_key;default:uuid_generate_v4()"` CreatedAt time.Time UpdatedAt time.Time Disabled bool `gorm:"not null;default:false"` Name string `gorm:"type:varchar(255);not null"` Nickname string `gorm:"type:varchar(255)"` Accounts []account }
User represents the database model for a user
Click to show internal directories.
Click to hide internal directories.