Make message.CreateTable usable on postgres and sqlite
This commit is contained in:
parent
d46578894e
commit
9dde189438
1 changed files with 26 additions and 10 deletions
|
@ -18,6 +18,7 @@ package database
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
|
||||
|
@ -34,18 +35,33 @@ type MessageQuery struct {
|
|||
}
|
||||
|
||||
func (mq *MessageQuery) CreateTable(dbType string) error {
|
||||
_, err := mq.db.Exec(`CREATE TABLE IF NOT EXISTS message (
|
||||
chat_jid VARCHAR(255),
|
||||
chat_receiver VARCHAR(255),
|
||||
jid VARCHAR(255),
|
||||
mxid VARCHAR(255) NOT NULL UNIQUE,
|
||||
sender VARCHAR(255) NOT NULL,
|
||||
content bytea NOT NULL,
|
||||
if strings.ToLower(dbType) == "postgres" {
|
||||
_, err := mq.db.Exec(`CREATE TABLE IF NOT EXISTS message (
|
||||
chat_jid VARCHAR(255),
|
||||
chat_receiver VARCHAR(255),
|
||||
jid VARCHAR(255),
|
||||
mxid VARCHAR(255) NOT NULL UNIQUE,
|
||||
sender VARCHAR(255) NOT NULL,
|
||||
content bytea NOT NULL,
|
||||
|
||||
PRIMARY KEY (chat_jid, chat_receiver, jid),
|
||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver)
|
||||
)`)
|
||||
PRIMARY KEY (chat_jid, chat_receiver, jid),
|
||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver)
|
||||
)`)
|
||||
return err
|
||||
} else {
|
||||
_, err := mq.db.Exec(`CREATE TABLE IF NOT EXISTS message (
|
||||
chat_jid VARCHAR(255),
|
||||
chat_receiver VARCHAR(255),
|
||||
jid VARCHAR(255),
|
||||
mxid VARCHAR(255) NOT NULL UNIQUE,
|
||||
sender VARCHAR(255) NOT NULL,
|
||||
content BLOB NOT NULL,
|
||||
|
||||
PRIMARY KEY (chat_jid, chat_receiver, jid),
|
||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver)
|
||||
)`)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) New() *Message {
|
||||
|
|
Loading…
Reference in a new issue