initial commit
This commit is contained in:
parent
b50c054b30
commit
fac7588d23
21 changed files with 266 additions and 55 deletions
|
|
@ -10,12 +10,18 @@ type UserModel struct {
|
|||
ProviderSubject string `gorm:"uniqueIndex;not null"`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (UserModel) TableName() string { return "users" }
|
||||
|
||||
type AdminModel struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Email string `gorm:"uniqueIndex;not null"`
|
||||
Name string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (AdminModel) TableName() string { return "admins" }
|
||||
|
||||
type SessionModel struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Token string `gorm:"uniqueIndex;not null"`
|
||||
|
|
@ -24,3 +30,5 @@ type SessionModel struct {
|
|||
ExpiresAt time.Time
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (SessionModel) TableName() string { return "sessions" }
|
||||
|
|
|
|||
16
internal/persistence/models_test.go
Normal file
16
internal/persistence/models_test.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package persistence
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestModelsUseMigrationTableNames(t *testing.T) {
|
||||
tests := map[string]string{
|
||||
"users": (UserModel{}).TableName(),
|
||||
"admins": (AdminModel{}).TableName(),
|
||||
"sessions": (SessionModel{}).TableName(),
|
||||
}
|
||||
for expected, actual := range tests {
|
||||
if actual != expected {
|
||||
t.Errorf("table name = %q, want %q", actual, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue