2019-05-16 19:14:32 +02:00
|
|
|
package upgrades
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
upgrades[0] = upgrade{"Initial schema", func(dialect Dialect, tx *sql.Tx) error {
|
|
|
|
var byteType string
|
|
|
|
if dialect == SQLite {
|
|
|
|
byteType = "BLOB"
|
|
|
|
} else {
|
|
|
|
byteType = "bytea"
|
|
|
|
}
|
|
|
|
_, err := tx.Exec(`CREATE TABLE IF NOT EXISTS portal (
|
|
|
|
jid VARCHAR(255),
|
|
|
|
receiver VARCHAR(255),
|
|
|
|
mxid VARCHAR(255) UNIQUE,
|
|
|
|
|
|
|
|
name VARCHAR(255) NOT NULL,
|
|
|
|
topic VARCHAR(255) NOT NULL,
|
|
|
|
avatar VARCHAR(255) NOT NULL,
|
|
|
|
|
|
|
|
PRIMARY KEY (jid, receiver)
|
|
|
|
)`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = tx.Exec(`CREATE TABLE IF NOT EXISTS puppet (
|
|
|
|
jid VARCHAR(255) PRIMARY KEY,
|
|
|
|
avatar VARCHAR(255),
|
|
|
|
displayname VARCHAR(255),
|
|
|
|
name_quality SMALLINT
|
|
|
|
)`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = tx.Exec(fmt.Sprintf(`CREATE TABLE IF NOT EXISTS "user" (
|
|
|
|
mxid VARCHAR(255) PRIMARY KEY,
|
2019-05-17 12:10:46 +02:00
|
|
|
jid VARCHAR(255) UNIQUE,
|
2019-05-16 19:14:32 +02:00
|
|
|
|
|
|
|
management_room VARCHAR(255),
|
|
|
|
|
|
|
|
client_id VARCHAR(255),
|
|
|
|
client_token VARCHAR(255),
|
|
|
|
server_token VARCHAR(255),
|
|
|
|
enc_key %[1]s,
|
|
|
|
mac_key %[1]s
|
|
|
|
)`, byteType))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = tx.Exec(fmt.Sprintf(`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 %[1]s NOT NULL,
|
|
|
|
|
|
|
|
PRIMARY KEY (chat_jid, chat_receiver, jid),
|
2019-05-17 12:10:46 +02:00
|
|
|
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE
|
2019-05-16 19:14:32 +02:00
|
|
|
)`, byteType))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}}
|
|
|
|
}
|