openvibers/openvibe.chat Commits
emotes.media_url and media_asset_id (Live's Media asset sync), added to existing databases on boot
Changes
@@@ -100,9 +100,19 @@ function close() {* every change to Chat's tables for the Live mirror — the service does; the importer does not,* so imported rows (which came from Live) are never sent back.*/++const ADDED_COLUMNS = [++ ['emotes', 'media_url', 'TEXT'], // Live: emote images synced to OpenVibe.Media++ ['emotes', 'media_asset_id', 'INTEGER'],++];++function initDb({ captureMirror = false } = {}) {const d = getDb();d.exec(fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8'));++ // Columns Live added after a Chat database was created (CREATE TABLE IF NOT EXISTS does not add them).++ for (const [table, column, type] of ADDED_COLUMNS) {++ const have = d.prepare(`PRAGMA table_info(${table})`).all().some((c) => c.name === column);++ if (!have) d.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${type}`);++ }const upsertAuth = d.prepare('INSERT INTO table_authority (table_name, authority, note) VALUES (?, ?, ?) ON CONFLICT(table_name) DO UPDATE SET authority = excluded.authority, note = excluded.note');for (const t of Object.keys(CHAT_TABLES)) upsertAuth.run(t, 'chat', 'Chat writes; Live keeps a read mirror');for (const [t, note] of Object.entries(STAGED_TABLES)) upsertAuth.run(t, 'live', note);@@@ -256,7 +256,9 @@ CREATE TABLE IF NOT EXISTS emotes (is_approved INTEGER DEFAULT 1,created_at DATETIME DEFAULT CURRENT_TIMESTAMP,channel_owner_id INTEGER,-- size INTEGER DEFAULT 100++ size INTEGER DEFAULT 100,++ media_url TEXT,++ media_asset_id INTEGER);CREATE INDEX IF NOT EXISTS idx_emotes_user ON emotes(user_id);CREATE INDEX IF NOT EXISTS idx_emotes_channel_owner ON emotes(channel_owner_id);
@@ -100,9 +100,19 @@ function close() {
@@ -100,9 +100,19 @@ function close() {
* every change to Chat's tables for the Live mirror — the service does; the importer does not,
* every change to Chat's tables for the Live mirror — the service does; the importer does not,
* so imported rows (which came from Live) are never sent back.
* so imported rows (which came from Live) are never sent back.
*/
*/
+const ADDED_COLUMNS = [
+ ['emotes', 'media_url', 'TEXT'], // Live: emote images synced to OpenVibe.Media
+ ['emotes', 'media_asset_id', 'INTEGER'],
+];
+
function initDb({ captureMirror = false } = {}) {
function initDb({ captureMirror = false } = {}) {
const d = getDb();
const d = getDb();
d.exec(fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8'));
d.exec(fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8'));
+ // Columns Live added after a Chat database was created (CREATE TABLE IF NOT EXISTS does not add them).
+ for (const [table, column, type] of ADDED_COLUMNS) {
+ const have = d.prepare(`PRAGMA table_info(${table})`).all().some((c) => c.name === column);
+ if (!have) d.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${type}`);
+ }
const upsertAuth = d.prepare('INSERT INTO table_authority (table_name, authority, note) VALUES (?, ?, ?) ON CONFLICT(table_name) DO UPDATE SET authority = excluded.authority, note = excluded.note');
const upsertAuth = d.prepare('INSERT INTO table_authority (table_name, authority, note) VALUES (?, ?, ?) ON CONFLICT(table_name) DO UPDATE SET authority = excluded.authority, note = excluded.note');
for (const t of Object.keys(CHAT_TABLES)) upsertAuth.run(t, 'chat', 'Chat writes; Live keeps a read mirror');
for (const t of Object.keys(CHAT_TABLES)) upsertAuth.run(t, 'chat', 'Chat writes; Live keeps a read mirror');
for (const [t, note] of Object.entries(STAGED_TABLES)) upsertAuth.run(t, 'live', note);
for (const [t, note] of Object.entries(STAGED_TABLES)) upsertAuth.run(t, 'live', note);
@@ -256,7 +256,9 @@ CREATE TABLE IF NOT EXISTS emotes (
@@ -256,7 +256,9 @@ CREATE TABLE IF NOT EXISTS emotes (
is_approved INTEGER DEFAULT 1,
is_approved INTEGER DEFAULT 1,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
channel_owner_id INTEGER,
channel_owner_id INTEGER,
- size INTEGER DEFAULT 100
+ size INTEGER DEFAULT 100,
+ media_url TEXT,
+ media_asset_id INTEGER
);
);
CREATE INDEX IF NOT EXISTS idx_emotes_user ON emotes(user_id);
CREATE INDEX IF NOT EXISTS idx_emotes_user ON emotes(user_id);
CREATE INDEX IF NOT EXISTS idx_emotes_channel_owner ON emotes(channel_owner_id);
CREATE INDEX IF NOT EXISTS idx_emotes_channel_owner ON emotes(channel_owner_id);