Currently the only backend we have is defined in app/persistence/local.backend.ts
export class AppProxy extends SingletonProxyMixin({
// App is the Sequelize model
model: App,
// Maps 'app' state to an object that can be fed to sequelize for insert or update
mapStateToObject: async state => ({
version: state.get('version'),
autoLaunchEnabled: state.get('autoLaunchEnabled'),
downloadFolder: state.get('downloadFolder'),
}),
// Maps sequelize object to 'app' redux state
// As our state is fully Immutable, we must be sure that this always return Immutable objects
mapObjectToState: async obj => Immutable.Map({
version: obj.version,
autoLaunchEnabled: obj.autoLaunchEnabled,
downloadFolder: obj.downloadFolder,
}),
}) {
}- Simple maps should extend
SingletonProxyMixin - Complex maps should extend
KeyedProxyMixin - Set and List should extend
ListProxyMixin
Then, at the end of the file, add your mapping like this:
export default {
app: new SingletonStateProxy(AppProxy),
...
}See test/persistence/test-app.ts for simple example, and test/persistence/applications-app.ts for more complex ones.
See app/database/model.ts
Add your migration script in app/persistence/umzug-runs/ folder. Your migration script should be the latest executed script (alphabetically sorted).
If we need to add a new mapping type (i.e. for Immutable.Record), here is what must be done:
- Add a new type of proxy in app/persistence/backend.ts.
The new class MUST implement the following methods
clear()toState()async get()async set(state)
- Add a new type of proxy in app/persistence/local.backend.ts.
For simplicity, is can extend
SingletonProxy. The new class MUST implement the following methodsstatic async mapStateToObject()static mapObjectToState()static async create()get()async update(state)toJSON()isEmpty()toState()