diff --git a/db/migrations/20160221001538_0.1.2_store-smtp-settings.sql b/db/migrations/20160221001538_0.1.2_store-smtp-settings.sql index 7d35b664..33bc42e5 100644 --- a/db/migrations/20160221001538_0.1.2_store-smtp-settings.sql +++ b/db/migrations/20160221001538_0.1.2_store-smtp-settings.sql @@ -2,13 +2,40 @@ -- +goose Up -- SQL in section 'Up' is executed when this migration is applied ALTER TABLE campaigns ADD COLUMN smtp_id bigint; -UPDATE campaigns SET smtp_id = (SELECT smtp.smtp_id FROM smtp) WHERE campaigns.id = (SELECT smtp.smtp_id FROM smtp,campaigns WHERE smtp.campaign_id=campaigns.id); -- sure hope the current smtp table works like I think it does - +UPDATE campaigns + SET smtp_id = (SELECT smtp.smtp_id FROM smtp) + WHERE campaigns.id = ( + SELECT smtp.smtp_id + FROM smtp,campaigns + WHERE smtp.campaign_id=campaigns.id + ) +; -- sure hope the current smtp table works like I think it does ALTER TABLE smtp RENAME TO smtp_old; -CREATE TABLE smtp(id integer primary key autoincrement,host varchar(255),username varchar(255),from_address varchar(255),modified_date datetime default CURRENT_TIMESTAMP,ignore_cert_errors BOOLEAN); -INSERT INTO smtp SELECT smtp_id AS id,host,username,from_address,'',ignore_cert_errors FROM smtp_old; +CREATE TABLE smtp( + id integer primary key autoincrement, + user_id bigint, + name varchar(255), + interface_type varchar(255), + host varchar(255), + username varchar(255), + password varchar(255), + from_address varchar(255), + modified_date datetime default CURRENT_TIMESTAMP, + ignore_cert_errors BOOLEAN +); +INSERT INTO smtp + SELECT smtp_id AS id,'','SMTP',smtp_id AS id,host,username,'',from_address,'',ignore_cert_errors + FROM smtp_old +; +UPDATE smtp + SET user_id = (SELECT campaigns.user_id FROM campaigns) + WHERE smtp.id = ( + SELECT smtp.id + FROM smtp,campaigns + WHERE smtp.id=campaigns.smtp_id + ) +; DROP TABLE smtp_old; - -- +goose Down -- SQL section 'Down' is executed when this migration is rolled back diff --git a/models/smtp.go b/models/smtp.go index cc06ffbe..78eed6f5 100644 --- a/models/smtp.go +++ b/models/smtp.go @@ -3,18 +3,17 @@ package models import ( "errors" "time" - -// "github.com/jinzhu/gorm" ) // SMTP contains the attributes needed to handle the sending of campaign emails type SMTP struct { - Id int64 `json:"-" gorm:"column:id; primary_key:yes"` - Name string `json:"-" gorm:"column:name"` + Id int64 `json:"id" gorm:"column:id; primary_key:yes"` UserId int64 `json:"-" gorm:"column:user_id"` + Interface string `json:"interface_type" gorm:"column:interface_type"` + Name string `json:"name"` Host string `json:"host"` Username string `json:"username,omitempty"` - Password string `json:"password,omitempty" sql:"-"` + Password string `json:"password,omitempty"` FromAddress string `json:"from_address"` IgnoreCertErrors bool `json:"ignore_cert_errors"` ModifiedDate time.Time `json:"modified_date"` @@ -50,7 +49,6 @@ func GetSMTPs(uid int64) ([]SMTP, error) { err := db.Where("user_id=?", uid).Find(&ss).Error if err != nil { Logger.Println(err) - return ss, err } return ss, err } @@ -61,7 +59,6 @@ func GetSMTP(id int64, uid int64) (SMTP, error) { err := db.Where("user_id=? and id=?", uid, id).Find(&s).Error if err != nil { Logger.Println(err) - return s, err } return s, err } @@ -107,7 +104,6 @@ func DeleteSMTP(id int64, uid int64) error { err = db.Where("user_id=?", uid).Delete(SMTP{Id: id}).Error if err != nil { Logger.Println(err) - return err } return err }