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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"strings"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ type MessageQuery struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mq *MessageQuery) CreateTable(dbType string) error {
|
func (mq *MessageQuery) CreateTable(dbType string) error {
|
||||||
|
if strings.ToLower(dbType) == "postgres" {
|
||||||
_, err := mq.db.Exec(`CREATE TABLE IF NOT EXISTS message (
|
_, err := mq.db.Exec(`CREATE TABLE IF NOT EXISTS message (
|
||||||
chat_jid VARCHAR(255),
|
chat_jid VARCHAR(255),
|
||||||
chat_receiver VARCHAR(255),
|
chat_receiver VARCHAR(255),
|
||||||
|
@ -46,6 +48,20 @@ func (mq *MessageQuery) CreateTable(dbType string) error {
|
||||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver)
|
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver)
|
||||||
)`)
|
)`)
|
||||||
return err
|
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 {
|
func (mq *MessageQuery) New() *Message {
|
||||||
|
|
Loading…
Reference in a new issue