diff options
| author | Horus_Arch | 2015-02-15 17:59:13 +0100 |
|---|---|---|
| committer | Horus_Arch | 2015-02-15 17:59:13 +0100 |
| commit | 26f781239bfcda867f19262becee3b9687a7c79d (patch) | |
| tree | 04a439594815ce1b37a1a73303eee4ac7a5be487 /app/controllers/db.go | |
| parent | a69bf1307d20a395b0eca9ffae06f57a659dabf1 (diff) | |
| download | freemail-26f781239bfcda867f19262becee3b9687a7c79d.tar.gz | |
Crashs on startup with error message 'Cannot start transaction.'
Diffstat (limited to 'app/controllers/db.go')
| -rw-r--r-- | app/controllers/db.go | 98 |
1 files changed, 72 insertions, 26 deletions
diff --git a/app/controllers/db.go b/app/controllers/db.go index 0f50968..5b7dd97 100644 --- a/app/controllers/db.go +++ b/app/controllers/db.go @@ -2,22 +2,25 @@ package controllers import ( "github.com/jinzhu/gorm" - _ "github.com/mattn/go-sqlite3" + // _ "github.com/mattn/go-sqlite3" + "database/sql" "github.com/revel/revel" "time" ) +// Website user type User struct { - Id int64 - Name string - Email string - Password string - Domains []Domain + Id int64 + Name string + Email string + Password string + // Domains []Domain CreatedAt time.Time UpdatedAt time.Time DeletedAt time.Time } +/* type Domain struct { Id int64 UserId int64 @@ -26,67 +29,110 @@ type Domain struct { UpdatedAt time.Time DeletedAt time.Time } +*/ + +// Domains for which we do E-Mail hosting +type VirtualDomain struct { + Id int64 + User User + UserId int64 + Name string +} + +// User for postfix +type VirtualUser struct { + Id int64 + UserId int64 + VirtualDomain VirtualDomain + VirtualDomainId int64 + Password string + Email string +} + +// E-Mail aliase for postfix +type VirtualAliase struct { + Id int64 + VirtualDomain VirtualDomain + VirtualDomainId int64 + Source string + Destination string +} type GormController struct { *revel.Controller - Db *gorm.DB + Gdb *gorm.DB } var Gdb gorm.DB func InitDB() { + // db.Init() Gdb, err := gorm.Open(revel.Config.StringDefault("db.driver", "sqlite3"), revel.Config.StringDefault("db.spec", "email.db")) if err != nil { revel.ERROR.Printf("%s", err) } Gdb.LogMode(true) Gdb.SetLogger(gorm.Logger{revel.TRACE}) + user := User{} Gdb.AutoMigrate(&user) - Gdb.Model(&user).AddUniqueIndex("idx_user_password", "password") + Gdb.Model(&user).AddUniqueIndex("idx_user_name", "name") Gdb.Model(&user).AddUniqueIndex("idx_user_email", "email") - domain := Domain{} - Gdb.AutoMigrate(&domain) - Gdb.Model(&domain).AddUniqueIndex("idx_domain_name", "domain") + /* + domain := Domain{} + Gdb.AutoMigrate(&domain) + Gdb.Model(&domain).AddUniqueIndex("idx_domain_name", "domain") + */ + + vu := VirtualUser{} + Gdb.AutoMigrate(&vu) + Gdb.Model(&vu).AddUniqueIndex("idx_virtual_user_email", "email") + Gdb.Debug().Model(&vu).Related(&user) + Gdb.Debug().Model(&user).Related(&vu) + + vd := VirtualDomain{} + Gdb.AutoMigrate(&vd) + + va := VirtualAliase{} + Gdb.AutoMigrate(&va) } -/* // transactions -// This method fills the c.Txn before each transaction +// This method fills the c.Gdb before each transaction func (c *GormController) Begin() revel.Result { txn := Gdb.Begin() if txn.Error != nil { - panic(txn.Error) + //panic(txn.Error) + revel.ERROR.Printf("%s \n", txn.Error) } - c.Txn = txn + c.Gdb = txn return nil } -// This method clears the c.Txn after each transaction +// This method clears the c.Gdb after each transaction func (c *GormController) Commit() revel.Result { - if c.Txn == nil { + if c.Gdb == nil { return nil } - c.Txn.Commit() - if err := c.Txn.Error; err != nil && err != sql.ErrTxDone { + c.Gdb.Commit() + if err := c.Gdb.Error; err != nil && err != sql.ErrTxDone { panic(err) } - c.Txn = nil + c.Gdb = nil return nil } -// This method clears the c.Txn after each transaction, too +// This method clears the c.Gdb after each transaction, too func (c *GormController) Rollback() revel.Result { - if c.Txn == nil { + if c.Gdb == nil { return nil } - c.Txn.Rollback() - if err := c.Txn.Error; err != nil && err != sql.ErrTxDone { + c.Gdb.Rollback() + if err := c.Gdb.Error; err != nil && err != sql.ErrTxDone { panic(err) } - c.Txn = nil + c.Gdb = nil return nil } -*/ |
