2019-05-16 19:14:32 +02:00
|
|
|
package upgrades
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-08-25 16:25:19 +02:00
|
|
|
upgrades[0] = upgrade{"Initial schema", func(tx *sql.Tx, ctx context) error {
|
2019-05-16 19:14:32 +02:00
|
|
|
_, err := tx.Exec(`CREATE TABLE IF NOT EXISTS portal (
|
|
|
|
jid VARCHAR(255),
|
|
|
|
receiver VARCHAR(255),
|
|
|
|
mxid VARCHAR(255) UNIQUE,
|
2020-05-21 19:56:41 +02:00
|
|
|
|
2019-05-16 19:14:32 +02:00
|
|
|
name VARCHAR(255) NOT NULL,
|
|
|
|
topic VARCHAR(255) NOT NULL,
|
|
|
|
avatar VARCHAR(255) NOT NULL,
|
2020-05-21 19:56:41 +02:00
|
|
|
|
2019-05-16 19:14:32 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-05-21 19:56:41 +02:00
|
|
|
_, err = tx.Exec(`CREATE TABLE IF NOT EXISTS "user" (
|
2019-05-16 19:14:32 +02:00
|
|
|
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),
|
2020-05-21 19:56:41 +02:00
|
|
|
enc_key bytea,
|
|
|
|
mac_key bytea
|
|
|
|
)`)
|
2019-05-16 19:14:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-21 19:56:41 +02:00
|
|
|
_, err = tx.Exec(`CREATE TABLE IF NOT EXISTS message (
|
2019-05-16 19:14:32 +02:00
|
|
|
chat_jid VARCHAR(255),
|
|
|
|
chat_receiver VARCHAR(255),
|
|
|
|
jid VARCHAR(255),
|
|
|
|
mxid VARCHAR(255) NOT NULL UNIQUE,
|
|
|
|
sender VARCHAR(255) NOT NULL,
|
2020-05-21 19:56:41 +02:00
|
|
|
content bytea NOT NULL,
|
2019-05-16 19:14:32 +02:00
|
|
|
|
|
|
|
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
|
2020-05-21 19:56:41 +02:00
|
|
|
)`)
|
2019-05-16 19:14:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}}
|
|
|
|
}
|