UNPKG

2.61 kBMarkdownView Raw
1# Dynograte
2
3Dynograte is a Node.js DynamoDB migration tool
4
5## Installation
6
7```bash
8npm install dynograte
9```
10
11Dynograte also comes packaged with tooling for making your life easier. You
12obviously need it. You can install Dynograte globally with:
13
14```bash
15npm install dynograte -g
16```
17
18## Features
19
20- Migrating DynamoDB tables from a directory
21- Migrating DynamoDB tables from functions
22- Command line tool for auto-generating migration files
23- Reminds you of a dinosaur
24
25## How it works
26
27Dynograte creates a DynamoDB table with a name that you specify. This table is
28used to track migration files that have already been run. Dynograte will only
29run migration files that do not exist in the migrations table.
30
31## Examples
32
33Dynograte can load migrations from a directory
34
35```javascript
36const path = require('path');
37const dynamodb = new aws.DynamoDB(config.dynamodb);
38
39let migrationDir = path.resolve(__dirname, './dynamodb-migrations');
40
41return dynograte.migrate({
42 dynamodb: dynamodb,
43 migrationTableName: 'my-awesome-migration-table',
44 migrationDir: migrationDir
45});
46
47```
48
49Dynograte can handle migrations as functions
50
51```javascript
52
53return dynograte.migrate({
54 dynamodb: dynamodb,
55 migrationTableName: randomTableName
56}, [
57 (dynamodb) => {
58 return theBestMigration(dynamodb);
59 },
60 (dynamodb) => {
61 return Promise.resolve();
62 }
63]);
64
65```
66
67Or a single migration function
68
69```javascript
70
71return dynograte.migrate({
72 dynamodb: dynamodb,
73 migrationTableName: randomTableName
74}, (dynamodb) => {
75 return theBestMigration(dynamodb);
76});
77
78```
79
80## CLI
81
82Dynograte comes packaged with a CLI, which will auto-generate migration files.
83Migration files are prefixed with the current `Date` in YY-MM-DD-HH-MM-SS format
84followed by a migration name of your choosing.
85
86```bash
87dynograte create --dir ~/Proj/dynomodb-migrations --migration update-users-table
88```
89
90The `create` command will generate a file in `~/Proj/dynomodb-migrations` that has
91a file name similar to `2016-09-07-10-48-28_update-users-table.js.js` and looks like:
92
93```javascript
94'use strict';
95
96exports.up = (dynamodb) => {
97
98};
99
100```
101
102## Tests
103
104To run the tests, you can either run docker, or specify your own DynamoDB
105configuration in `config.js`.
106
107```bash
108./start-docker && npm test
109```
110
111`start-docker.sh` generates a `config.js` file that contains the DynamoDB
112configuration. You can also manually create it to include your own custom config:
113
114```javascript
115'use strict';
116
117const aws = require('aws-sdk');
118
119module.exports = {
120 dynamodb: {
121 region: 'us-east-1',
122 endpoint: new aws.Endpoint('http://localhost:32795')
123 }
124};
125
126```