Skip to content

Instantly share code, notes, and snippets.

@radzionc
Created February 26, 2018 10:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
const database = new AWS.DynamoDB()
const neededTables = TABLES_PARAMS.map(({ TableName }) => TableName)
const existingTables = await database
.listTables()
.promise()
.then(data => data.TableNames)
const dbsToDelete = _.without(existingTables, ...neededTables)
const dbsToCreate = _.without(neededTables, ...existingTables)
await Promise.all(
dbsToDelete.map(TableName =>
database.deleteTable({ TableName }).promise()
)
)
await Promise.all(
dbsToCreate.map(TableName =>
database
.createTable(TABLES_PARAMS.find(t => t.TableName === TableName))
.promise()
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment