WorldBrain / storex

Storex Core - A modular and portable database abstraction ecosystem for JavaScript
MIT License
150 stars 8 forks source link

Feature: DB-agnostic data migrations #3

Closed ShishKabab closed 5 years ago

ShishKabab commented 6 years ago

Motivation: This is an annoying topic that we keep solving for every framework out there, while the basic operations can be quite simple and should be shareable across different frameworks, languages and database technologies out there.

Design considerations:

The idea: Provide packages for migration through an API and CLI interfaces. Example:

import MigrationManager from `storex-migrations`

...
await storageManager.finishInitliazation()

const migrations = new MigrationManager(storageManager, [
    // Only the more complex migration logic happens here, the rest is generated automatically
    {
        version: new Date(...),
        forwardSteps: [
            {
                collection: 'users',
                operation: 'mergeFields',
                sourceFields: ['firstName', 'lastName'],
                targetField: 'displayName',
                value: {'${object.firstName} ${object.lastName}'}
            },
            ...
        ]
    }
])
await migrations.migrate() // Calls method on storageManager with a set of instructions to migrate data

Steps:

Even if you only do one of these things, it'd already be big help :)

ShishKabab commented 5 years ago

Just published the first version of user-logic for data-driven logic that can be used to define simple data model manipulations during migrations: https://www.npmjs.com/package/user-logic

ShishKabab commented 5 years ago

Work started here: https://github.com/WorldBrain/storex-schema-migrations

ShishKabab commented 5 years ago

Basic implementation done, further development and issues on missing features should be done in the repo mentioned above.