Fixing issues in SMTP model and db schema. Add interface_type to support future sending interfaces beyond SMTP.

pull/169/head
William Woodson 2016-02-20 23:16:38 -06:00
parent 2d503ff215
commit 5b89fb04eb
2 changed files with 36 additions and 13 deletions

View File

@ -2,13 +2,40 @@
-- +goose Up -- +goose Up
-- SQL in section 'Up' is executed when this migration is applied -- SQL in section 'Up' is executed when this migration is applied
ALTER TABLE campaigns ADD COLUMN smtp_id bigint; 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; 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); CREATE TABLE smtp(
INSERT INTO smtp SELECT smtp_id AS id,host,username,from_address,'',ignore_cert_errors FROM smtp_old; 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; DROP TABLE smtp_old;
-- +goose Down -- +goose Down
-- SQL section 'Down' is executed when this migration is rolled back -- SQL section 'Down' is executed when this migration is rolled back

View File

@ -3,18 +3,17 @@ package models
import ( import (
"errors" "errors"
"time" "time"
// "github.com/jinzhu/gorm"
) )
// SMTP contains the attributes needed to handle the sending of campaign emails // SMTP contains the attributes needed to handle the sending of campaign emails
type SMTP struct { type SMTP struct {
Id int64 `json:"-" gorm:"column:id; primary_key:yes"` Id int64 `json:"id" gorm:"column:id; primary_key:yes"`
Name string `json:"-" gorm:"column:name"`
UserId int64 `json:"-" gorm:"column:user_id"` UserId int64 `json:"-" gorm:"column:user_id"`
Interface string `json:"interface_type" gorm:"column:interface_type"`
Name string `json:"name"`
Host string `json:"host"` Host string `json:"host"`
Username string `json:"username,omitempty"` Username string `json:"username,omitempty"`
Password string `json:"password,omitempty" sql:"-"` Password string `json:"password,omitempty"`
FromAddress string `json:"from_address"` FromAddress string `json:"from_address"`
IgnoreCertErrors bool `json:"ignore_cert_errors"` IgnoreCertErrors bool `json:"ignore_cert_errors"`
ModifiedDate time.Time `json:"modified_date"` 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 err := db.Where("user_id=?", uid).Find(&ss).Error
if err != nil { if err != nil {
Logger.Println(err) Logger.Println(err)
return ss, 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 err := db.Where("user_id=? and id=?", uid, id).Find(&s).Error
if err != nil { if err != nil {
Logger.Println(err) Logger.Println(err)
return s, 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 err = db.Where("user_id=?", uid).Delete(SMTP{Id: id}).Error
if err != nil { if err != nil {
Logger.Println(err) Logger.Println(err)
return err
} }
return err return err
} }