|
@@ -45,6 +45,7 @@ const (
|
|
|
attachment_deleted INT NOT NULL,
|
|
attachment_deleted INT NOT NULL,
|
|
|
sender TEXT NOT NULL,
|
|
sender TEXT NOT NULL,
|
|
|
user TEXT NOT NULL,
|
|
user TEXT NOT NULL,
|
|
|
|
|
+ content_type TEXT NOT NULL,
|
|
|
encoding TEXT NOT NULL,
|
|
encoding TEXT NOT NULL,
|
|
|
published INT NOT NULL
|
|
published INT NOT NULL
|
|
|
);
|
|
);
|
|
@@ -63,43 +64,43 @@ const (
|
|
|
COMMIT;
|
|
COMMIT;
|
|
|
`
|
|
`
|
|
|
insertMessageQuery = `
|
|
insertMessageQuery = `
|
|
|
- INSERT INTO messages (mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, attachment_deleted, sender, user, encoding, published)
|
|
|
|
|
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
|
|
|
+ INSERT INTO messages (mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, attachment_deleted, sender, user, content_type, encoding, published)
|
|
|
|
|
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
`
|
|
`
|
|
|
deleteMessageQuery = `DELETE FROM messages WHERE mid = ?`
|
|
deleteMessageQuery = `DELETE FROM messages WHERE mid = ?`
|
|
|
updateMessagesForTopicExpiryQuery = `UPDATE messages SET expires = ? WHERE topic = ?`
|
|
updateMessagesForTopicExpiryQuery = `UPDATE messages SET expires = ? WHERE topic = ?`
|
|
|
selectRowIDFromMessageID = `SELECT id FROM messages WHERE mid = ?` // Do not include topic, see #336 and TestServer_PollSinceID_MultipleTopics
|
|
selectRowIDFromMessageID = `SELECT id FROM messages WHERE mid = ?` // Do not include topic, see #336 and TestServer_PollSinceID_MultipleTopics
|
|
|
selectMessagesByIDQuery = `
|
|
selectMessagesByIDQuery = `
|
|
|
- SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, encoding
|
|
|
|
|
|
|
+ SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, content_type, encoding
|
|
|
FROM messages
|
|
FROM messages
|
|
|
WHERE mid = ?
|
|
WHERE mid = ?
|
|
|
`
|
|
`
|
|
|
selectMessagesSinceTimeQuery = `
|
|
selectMessagesSinceTimeQuery = `
|
|
|
- SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, encoding
|
|
|
|
|
|
|
+ SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, content_type, encoding
|
|
|
FROM messages
|
|
FROM messages
|
|
|
WHERE topic = ? AND time >= ? AND published = 1
|
|
WHERE topic = ? AND time >= ? AND published = 1
|
|
|
ORDER BY time, id
|
|
ORDER BY time, id
|
|
|
`
|
|
`
|
|
|
selectMessagesSinceTimeIncludeScheduledQuery = `
|
|
selectMessagesSinceTimeIncludeScheduledQuery = `
|
|
|
- SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, encoding
|
|
|
|
|
|
|
+ SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, content_type, encoding
|
|
|
FROM messages
|
|
FROM messages
|
|
|
WHERE topic = ? AND time >= ?
|
|
WHERE topic = ? AND time >= ?
|
|
|
ORDER BY time, id
|
|
ORDER BY time, id
|
|
|
`
|
|
`
|
|
|
selectMessagesSinceIDQuery = `
|
|
selectMessagesSinceIDQuery = `
|
|
|
- SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, encoding
|
|
|
|
|
|
|
+ SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, content_type, encoding
|
|
|
FROM messages
|
|
FROM messages
|
|
|
WHERE topic = ? AND id > ? AND published = 1
|
|
WHERE topic = ? AND id > ? AND published = 1
|
|
|
ORDER BY time, id
|
|
ORDER BY time, id
|
|
|
`
|
|
`
|
|
|
selectMessagesSinceIDIncludeScheduledQuery = `
|
|
selectMessagesSinceIDIncludeScheduledQuery = `
|
|
|
- SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, encoding
|
|
|
|
|
|
|
+ SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, content_type, encoding
|
|
|
FROM messages
|
|
FROM messages
|
|
|
WHERE topic = ? AND (id > ? OR published = 0)
|
|
WHERE topic = ? AND (id > ? OR published = 0)
|
|
|
ORDER BY time, id
|
|
ORDER BY time, id
|
|
|
`
|
|
`
|
|
|
selectMessagesDueQuery = `
|
|
selectMessagesDueQuery = `
|
|
|
- SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, encoding
|
|
|
|
|
|
|
+ SELECT mid, time, expires, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, user, content_type, encoding
|
|
|
FROM messages
|
|
FROM messages
|
|
|
WHERE time <= ? AND published = 0
|
|
WHERE time <= ? AND published = 0
|
|
|
ORDER BY time, id
|
|
ORDER BY time, id
|
|
@@ -121,7 +122,7 @@ const (
|
|
|
|
|
|
|
|
// Schema management queries
|
|
// Schema management queries
|
|
|
const (
|
|
const (
|
|
|
- currentSchemaVersion = 11
|
|
|
|
|
|
|
+ currentSchemaVersion = 12
|
|
|
createSchemaVersionTableQuery = `
|
|
createSchemaVersionTableQuery = `
|
|
|
CREATE TABLE IF NOT EXISTS schemaVersion (
|
|
CREATE TABLE IF NOT EXISTS schemaVersion (
|
|
|
id INT PRIMARY KEY,
|
|
id INT PRIMARY KEY,
|
|
@@ -240,6 +241,11 @@ const (
|
|
|
);
|
|
);
|
|
|
INSERT INTO stats (key, value) VALUES ('messages', 0);
|
|
INSERT INTO stats (key, value) VALUES ('messages', 0);
|
|
|
`
|
|
`
|
|
|
|
|
+
|
|
|
|
|
+ // 11 -> 12
|
|
|
|
|
+ migrate11To12AlterMessagesTableQuery = `
|
|
|
|
|
+ ALTER TABLE messages ADD COLUMN content_type TEXT NOT NULL DEFAULT('');
|
|
|
|
|
+ `
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
var (
|
|
@@ -255,6 +261,7 @@ var (
|
|
|
8: migrateFrom8,
|
|
8: migrateFrom8,
|
|
|
9: migrateFrom9,
|
|
9: migrateFrom9,
|
|
|
10: migrateFrom10,
|
|
10: migrateFrom10,
|
|
|
|
|
+ 11: migrateFrom11,
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -384,6 +391,7 @@ func (c *messageCache) addMessages(ms []*message) error {
|
|
|
attachmentDeleted, // Always zero
|
|
attachmentDeleted, // Always zero
|
|
|
sender,
|
|
sender,
|
|
|
m.User,
|
|
m.User,
|
|
|
|
|
+ m.ContentType,
|
|
|
m.Encoding,
|
|
m.Encoding,
|
|
|
published,
|
|
published,
|
|
|
)
|
|
)
|
|
@@ -656,7 +664,7 @@ func readMessages(rows *sql.Rows) ([]*message, error) {
|
|
|
func readMessage(rows *sql.Rows) (*message, error) {
|
|
func readMessage(rows *sql.Rows) (*message, error) {
|
|
|
var timestamp, expires, attachmentSize, attachmentExpires int64
|
|
var timestamp, expires, attachmentSize, attachmentExpires int64
|
|
|
var priority int
|
|
var priority int
|
|
|
- var id, topic, msg, title, tagsStr, click, icon, actionsStr, attachmentName, attachmentType, attachmentURL, sender, user, encoding string
|
|
|
|
|
|
|
+ var id, topic, msg, title, tagsStr, click, icon, actionsStr, attachmentName, attachmentType, attachmentURL, sender, user, contentType, encoding string
|
|
|
err := rows.Scan(
|
|
err := rows.Scan(
|
|
|
&id,
|
|
&id,
|
|
|
×tamp,
|
|
×tamp,
|
|
@@ -676,6 +684,7 @@ func readMessage(rows *sql.Rows) (*message, error) {
|
|
|
&attachmentURL,
|
|
&attachmentURL,
|
|
|
&sender,
|
|
&sender,
|
|
|
&user,
|
|
&user,
|
|
|
|
|
+ &contentType,
|
|
|
&encoding,
|
|
&encoding,
|
|
|
)
|
|
)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -706,22 +715,23 @@ func readMessage(rows *sql.Rows) (*message, error) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return &message{
|
|
return &message{
|
|
|
- ID: id,
|
|
|
|
|
- Time: timestamp,
|
|
|
|
|
- Expires: expires,
|
|
|
|
|
- Event: messageEvent,
|
|
|
|
|
- Topic: topic,
|
|
|
|
|
- Message: msg,
|
|
|
|
|
- Title: title,
|
|
|
|
|
- Priority: priority,
|
|
|
|
|
- Tags: tags,
|
|
|
|
|
- Click: click,
|
|
|
|
|
- Icon: icon,
|
|
|
|
|
- Actions: actions,
|
|
|
|
|
- Attachment: att,
|
|
|
|
|
- Sender: senderIP, // Must parse assuming database must be correct
|
|
|
|
|
- User: user,
|
|
|
|
|
- Encoding: encoding,
|
|
|
|
|
|
|
+ ID: id,
|
|
|
|
|
+ Time: timestamp,
|
|
|
|
|
+ Expires: expires,
|
|
|
|
|
+ Event: messageEvent,
|
|
|
|
|
+ Topic: topic,
|
|
|
|
|
+ Message: msg,
|
|
|
|
|
+ Title: title,
|
|
|
|
|
+ Priority: priority,
|
|
|
|
|
+ Tags: tags,
|
|
|
|
|
+ Click: click,
|
|
|
|
|
+ Icon: icon,
|
|
|
|
|
+ Actions: actions,
|
|
|
|
|
+ Attachment: att,
|
|
|
|
|
+ Sender: senderIP, // Must parse assuming database must be correct
|
|
|
|
|
+ User: user,
|
|
|
|
|
+ ContentType: contentType,
|
|
|
|
|
+ Encoding: encoding,
|
|
|
}, nil
|
|
}, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -929,7 +939,7 @@ func migrateFrom9(db *sql.DB, cacheDuration time.Duration) error {
|
|
|
return tx.Commit()
|
|
return tx.Commit()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func migrateFrom10(db *sql.DB, cacheDuration time.Duration) error {
|
|
|
|
|
|
|
+func migrateFrom10(db *sql.DB, _ time.Duration) error {
|
|
|
log.Tag(tagMessageCache).Info("Migrating cache database schema: from 10 to 11")
|
|
log.Tag(tagMessageCache).Info("Migrating cache database schema: from 10 to 11")
|
|
|
tx, err := db.Begin()
|
|
tx, err := db.Begin()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -944,3 +954,19 @@ func migrateFrom10(db *sql.DB, cacheDuration time.Duration) error {
|
|
|
}
|
|
}
|
|
|
return tx.Commit()
|
|
return tx.Commit()
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func migrateFrom11(db *sql.DB, _ time.Duration) error {
|
|
|
|
|
+ log.Tag(tagMessageCache).Info("Migrating cache database schema: from 11 to 12")
|
|
|
|
|
+ tx, err := db.Begin()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ defer tx.Rollback()
|
|
|
|
|
+ if _, err := tx.Exec(migrate11To12AlterMessagesTableQuery); err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ if _, err := tx.Exec(updateSchemaVersion, 12); err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ return tx.Commit()
|
|
|
|
|
+}
|