@nozbe/watermelondb
Version:
Build powerful React Native and React web apps that scale from hundreds to tens of thousands of records and remain fast
32 lines (25 loc) • 853 B
JavaScript
// @flow
import { unnest } from '../../utils/fp'
import { type SchemaMigrations, type MigrationStep } from './index'
import { type SchemaVersion } from '../index'
export function stepsForMigration({
migrations: schemaMigrations,
fromVersion,
toVersion,
}: $Exact<{
migrations: SchemaMigrations,
fromVersion: SchemaVersion,
toVersion: SchemaVersion,
}>): ?(MigrationStep[]) {
const { sortedMigrations, minVersion, maxVersion } = schemaMigrations
// see if migrations in this range are available
if (fromVersion < minVersion || toVersion > maxVersion) {
return null
}
// return steps
const matchingMigrations = sortedMigrations.filter(
({ toVersion: version }) => version > fromVersion && version <= toVersion,
)
const allSteps = unnest(matchingMigrations.map((migration) => migration.steps))
return allSteps
}