1 | # Dynograte
|
2 |
|
3 | Dynograte is a Node.js DynamoDB migration tool
|
4 |
|
5 | ## Installation
|
6 |
|
7 | ```bash
|
8 | npm install dynograte
|
9 | ```
|
10 |
|
11 | Dynograte also comes packaged with tooling for making your life easier. You
|
12 | obviously need it. You can install Dynograte globally with:
|
13 |
|
14 | ```bash
|
15 | npm 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 |
|
27 | Dynograte creates a DynamoDB table with a name that you specify. This table is
|
28 | used to track migration files that have already been run. Dynograte will only
|
29 | run migration files that do not exist in the migrations table.
|
30 |
|
31 | ## Examples
|
32 |
|
33 | Dynograte can load migrations from a directory
|
34 |
|
35 | ```javascript
|
36 | const path = require('path');
|
37 | const dynamodb = new aws.DynamoDB(config.dynamodb);
|
38 |
|
39 | let migrationDir = path.resolve(__dirname, './dynamodb-migrations');
|
40 |
|
41 | return dynograte.migrate({
|
42 | dynamodb: dynamodb,
|
43 | migrationTableName: 'my-awesome-migration-table',
|
44 | migrationDir: migrationDir
|
45 | });
|
46 |
|
47 | ```
|
48 |
|
49 | Dynograte can handle migrations as functions
|
50 |
|
51 | ```javascript
|
52 |
|
53 | return 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 |
|
67 | Or a single migration function
|
68 |
|
69 | ```javascript
|
70 |
|
71 | return dynograte.migrate({
|
72 | dynamodb: dynamodb,
|
73 | migrationTableName: randomTableName
|
74 | }, (dynamodb) => {
|
75 | return theBestMigration(dynamodb);
|
76 | });
|
77 |
|
78 | ```
|
79 |
|
80 | ## CLI
|
81 |
|
82 | Dynograte comes packaged with a CLI, which will auto-generate migration files.
|
83 | Migration files are prefixed with the current `Date` in YY-MM-DD-HH-MM-SS format
|
84 | followed by a migration name of your choosing.
|
85 |
|
86 | ```bash
|
87 | dynograte create --dir ~/Proj/dynomodb-migrations --migration update-users-table
|
88 | ```
|
89 |
|
90 | The `create` command will generate a file in `~/Proj/dynomodb-migrations` that has
|
91 | a 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 |
|
96 | exports.up = (dynamodb) => {
|
97 |
|
98 | };
|
99 |
|
100 | ```
|
101 |
|
102 | ## Tests
|
103 |
|
104 | To run the tests, you can either run docker, or specify your own DynamoDB
|
105 | configuration 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
|
112 | configuration. You can also manually create it to include your own custom config:
|
113 |
|
114 | ```javascript
|
115 | 'use strict';
|
116 |
|
117 | const aws = require('aws-sdk');
|
118 |
|
119 | module.exports = {
|
120 | dynamodb: {
|
121 | region: 'us-east-1',
|
122 | endpoint: new aws.Endpoint('http://localhost:32795')
|
123 | }
|
124 | };
|
125 |
|
126 | ```
|