https://serverless-stack.com/ logo
#sst
Title
# sst
k

Kevin Baker

11/03/2021, 2:31 PM
Are there any common patters for data migrations and or seeding data for SST/CDK? or is this more of a dependency on ORM/DAL selection
t

thdxr

11/03/2021, 2:31 PM
Probably the latter but you can use sst.Script to trigger those as part of the deploy process
k

Kevin Baker

11/03/2021, 2:32 PM
Perfect
o

Omi Chowdhury

11/03/2021, 2:39 PM
We deploy migrations as stacks, then run them via the AWS console. For large migrations having the same tooling as the app (SQS, step functions, running lambdas in parallel) is super useful. We usually code them to have a preview mode, run it to make sure the existing data looks like we expect, then run it again with the preview flag set to false
k

Kevin Baker

11/03/2021, 2:41 PM
Interesting... so your migrations are a stack that gets deployed and then executed in the AWS Console?
o

Omi Chowdhury

11/03/2021, 2:43 PM
yeah, and a single migration could be multiple lambdas that need to be orchestrated. Some of them are just a single lambda script though
k

Kevin Baker

11/03/2021, 2:44 PM
And you control Authorization for the lambda to schema and databases via the CDK definition?
o

Omi Chowdhury

11/03/2021, 2:46 PM
yeah - same as a normal lambda
k

Kevin Baker

11/03/2021, 2:47 PM
Super interested in this way of approaching migrations... especially where a data related deployment would often need to be deployed ahead of the application
t

thdxr

11/03/2021, 3:05 PM
I've been thinking about this approach as well. A migration is really just some functionality that needs to run so no need to treat it like something outside of your normal application
k

Kevin Baker

11/03/2021, 3:07 PM
I've thought of it like Rails used to be and or the way TypeORM handles it.. .that said in a modern architecture there are all kinds of resources for an application that might need a "migration" like activity.... nice to leverage the framework for that
o

Omi Chowdhury

11/03/2021, 3:50 PM
I’d like to create a layer on top of that, to track what migrations/ops scripts exist, their parameters, and audit log of when they’ve been run and outputs. I’d probably have the build export some metadata, expose it via an API, have it store state either in dynamo or faunadb, build a UI in retool