diff --git a/config.template.yaml b/config.template.yaml index 78782b1c..f50e2a20 100644 --- a/config.template.yaml +++ b/config.template.yaml @@ -219,3 +219,13 @@ setuid: user: 'user' # how long to wait in ms before changing uid/gid timeout: 15 + +# Determines channel data storage mechanism. +# Defaults to 'file', in which channel data is JSON stringified and saved to a file +# in the `chandump/` folder. This is the legacy behavior of CyTube. +# The other possible option is 'database', in which case each key-value pair of +# channel data is stored as a row in the `channel_data` database table. +# To migrate legacy chandump files to the database, shut down CyTube (to prevent +# concurrent updates), then run `node lib/channel-storage/migrate.js`. +channel-storage: + type: 'file' diff --git a/src/channel-storage/channelstore.js b/src/channel-storage/channelstore.js index 5d29e121..247565d3 100644 --- a/src/channel-storage/channelstore.js +++ b/src/channel-storage/channelstore.js @@ -1,7 +1,8 @@ import { FileStore } from './filestore'; import { DatabaseStore } from './dbstore'; +import Config from '../config'; -const CHANNEL_STORE = new FileStore(); +const CHANNEL_STORE = loadChannelStore(); export function load(channelName) { return CHANNEL_STORE.load(channelName); @@ -10,3 +11,13 @@ export function load(channelName) { export function save(channelName, data) { return CHANNEL_STORE.save(channelName, data); } + +function loadChannelStore() { + switch (Config.get('channel-storage.type')) { + case 'database': + return new DatabaseStore(); + case 'file': + default: + return new FileStore(); + } +} diff --git a/src/config.js b/src/config.js index 8239b7fb..c1bed5a4 100644 --- a/src/config.js +++ b/src/config.js @@ -110,6 +110,9 @@ var defaults = { "user": "nobody", "timeout": 15 }, + "channel-storage": { + type: "file" + } }; /**