https://github.com/markwylde/node-mini-migrations
A really simple node migrations library that is completely independant of any database or file system.
https://github.com/markwylde/node-mini-migrations
database migrations sqlite
Last synced: about 2 months ago
JSON representation
A really simple node migrations library that is completely independant of any database or file system.
- Host: GitHub
- URL: https://github.com/markwylde/node-mini-migrations
- Owner: markwylde
- License: mit
- Created: 2019-11-07T10:26:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-13T14:17:52.000Z (over 3 years ago)
- Last Synced: 2026-01-03T02:42:35.665Z (6 months ago)
- Topics: database, migrations, sqlite
- Language: JavaScript
- Homepage:
- Size: 106 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mini Migrations for NodeJS
A really simple node migrations library that is completely independent of any database or file system.
## Installation
```bash
npm install --save node-mini-migrations
```
## Example Usage
### driver
```javascript
import sqlite from 'sqlite-fp/promises.js';
import up from 'node-mini-migrations/up.js';
import getMigrationsFromDirectory from 'node-mini-migrations/getMigrationsFromDirectory.js';
function migrator (db) {
return {
init: (direction) => {
return sqlite.run(db, 'CREATE TABLE IF NOT EXISTS _migrations (file TEXT PRIMARY KEY);');
},
getMigrationState: (id) => {
return sqlite.getOne(db, 'SELECT file FROM _migrations WHERE file = ?', [id]);
},
setMigrationUp: (id) => {
return sqlite.run(db, 'INSERT INTO _migrations (file) VALUES (?)', [id]);
},
setMigrationDown: (id) => {
return sqlite.run(db, 'DELETE FROM _migrations WHERE file = ?', [id]);
},
handler: (fn) => fn(db)
};
};
const db = await sqlite.connect('./test.sqlite');
await up(
migrator(db),
getMigrationsFromDirectory('./test/migrations')
);
```
### migration
```javascript
export function up (db) {
return db.exec('CREATE TABLE test_table (test TEXT)')
}
export function down (db) {
return db.exec('DROP TABLE test_table')
}
```
## License
This project is licensed under the terms of the MIT license.