2022-09-29 12:40:28 +00:00
# Migration 🧳 Helper
2022-03-03 13:40:38 +00:00
2022-09-29 12:40:28 +00:00
> **Tiny helper library for migrating data.**
2022-03-03 13:40:38 +00:00
2022-09-29 12:40:28 +00:00
## Features
2022-03-03 13:40:38 +00:00
2022-09-29 12:40:28 +00:00
* Zero dependencies.
* 100% code coverage.
* TypeScript definitions included.
## Usage
2022-03-03 13:40:38 +00:00
```ts
2022-09-29 12:40:28 +00:00
import {migrate, Migration} from '@holllo/migration-helper';
2022-03-03 13:40:38 +00:00
// Your data that needs migrating.
const data = 'data';
// Your data's current version.
const version = '1.0.0';
// Create some migrations to apply.
const migrations: Array< Migration < string > > = [
{
version: '1.0.1',
migrate: async (data: string) => `${data} migrated` ,
},
{
version: '1.0.2',
migrate: async (data: string) => `${data} (again!)` ,
},
];
// Migrate your data.
2022-03-03 14:01:06 +00:00
const migrated = await migrate(data, version, migrations);
2022-03-03 13:40:38 +00:00
// Congratulations, your data is now on version 1.0.2!
console.log(migrated);
```
2022-09-29 12:40:28 +00:00
See [the tests directory ](https://git.bauke.xyz/Holllo/migration-helper/src/branch/main/tests ) for how to use `number` , `Date` or a custom way of versioning.
## License
2022-03-03 13:40:38 +00:00
2022-09-29 12:40:28 +00:00
Distributed under the [AGPL-3.0-or-later ](https://spdx.org/licenses/AGPL-3.0-or-later.html ) license, see [LICENSE ](https://git.bauke.xyz/Holllo/migration-helper/src/branch/main/LICENSE ) for more information.