package model import ( "time" ) func SentinelBirthday() time.Time { return time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC) } type User struct { ID uint64 `gorm:"primaryKey"` Nick string `gorm:"not null;uniqueIndex:uniq_user_nick"` Name string Surname string Fathersname string Sex Sex `gorm:"type:smallint;check:sex IN (0,1,2)"` Birthday time.Time Cards []Card `gorm:"foreignKey:UserID"` CardsIDs []uint64 `gorm:"-"` // just for compatibility Flights []Flight `gorm:"many2many:user_flights;joinForeignKey:UserID;joinReferences:FlightID"` FlightsIDs []uint64 `gorm:"-"` } func (User) TableName() string { return "users" } type Card struct { ID uint64 `gorm:"primaryKey"` Prefix string `gorm:"not null;uniqueIndex:uniq_card_identity"` Number uint64 `gorm:"not null;uniqueIndex:uniq_card_identity"` Bonusprogramm string `gorm:"not null;uniqueIndex:uniq_card_identity"` Flights []Flight `gorm:"many2many:card_flights;joinForeignKey:CardID;joinReferences:FlightID"` FlightsIDs []uint64 `gorm:"-"` UserID uint64 User User `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` } func (Card) TableName() string { return "cards" } type LatLong struct { Lat, Long float64 } type Flight struct { ID uint64 `gorm:"primaryKey"` Number string `gorm:"not null;uniqueIndex:uniq_flight_identity"` From string `gorm:"not null;uniqueIndex:uniq_flight_identity"` FromCoords LatLong `gorm:"-"` To string `gorm:"not null;uniqueIndex:uniq_flight_identity"` ToCoords LatLong `gorm:"-"` Date time.Time `gorm:"not null;uniqueIndex:uniq_flight_identity"` HasTime bool Code string `gorm:"-"` Users []User `gorm:"many2many:user_flights;joinForeignKey:FlightID;joinReferences:UserID"` Cards []Card `gorm:"many2many:card_flights;joinForeignKey:FlightID;joinReferences:CardID"` UserID uint64 `gorm:"-"` CardID uint64 `gorm:"-"` } func (Flight) TableName() string { return "flights" }