Skip to content

Instantly share code, notes, and snippets.

@radzionc
Created February 26, 2018 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radzionc/0f86b729b448b6312708aac1d6eff1a6 to your computer and use it in GitHub Desktop.
Save radzionc/0f86b729b448b6312708aac1d6eff1a6 to your computer and use it in GitHub Desktop.
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