Hi folks.
I would like to share with you the idea/prototype for managing and running migration or seed scripts for DynamoDB.
First, let's clarify what a migration and a seed script are.
Migration refers to the process of transferring data from one database to another, or making structural changes to a database, such as upgrading, transforming, or migrating to a new database management system (DBMS). Due to the fact that aws cdk helps us and handles for us DynamoDB structural changes. I would like to make an agriment that into this article migration refers only for transforming data.
Seed refers to the process of populating a database with initial data, often for development, testing, or setup purposes.
Second, let's outline the required functionality.
In the company where I've worked, the product follows a multi-service architecture. I identified five key requirements:
TypeScript support: The tool should support TypeScript.- Minimal migration/seed script logic*: The migration and seeding processes should require minimal scripting.
Ability to run specific scripts: The tool should allow developers to execute particular scripts.
Service independence: The tool should function independently of any specific services.- Leverage the latest AWS SDK version: The tool should utilize the most recent version of the AWS SDK.
Third, before diving into my own implementation, I explored existing packages. One option was the . The repository structure is straightforward, consisting of three primary folders.
- The first folder, named
templates, contains files for the
Let's open the file and examine the code.
This implementation is straightforward and flexible, allowing it to be used not only for migrations but also as a seeding tool. Additionally, the data source and target can be entirely different from each other.
The only question left is: How do you run it?
Before we dive into running the solution, we first need to decide how to compile and store it. There are several options available, and I’ll outline a few:
- We can build artifacts on a pre-push hook and push them to the repository (
distfolder as an example). - We can build artifacts on a pre-push hook and store them in an S3 bucket.
- We can set up a Bitbucket pipeline or GitHub Actions workflow to handle builds and storage.
Note: that Bitbucket pipelines only store artifacts for 14 days, so you’d need to build them daily or on demand if you require longer retention.
There are plenty of other options as well, and you can choose the one that best fits your requirements.
To run it, I created my own CLI and published it in our private npm repository. There are several commands available, one of which is
migrationrun. In my next article, I will discuss how to build your own CLI. For now, I will provide the code and the command.
The command looks like:
CODEnpx @company/cli migration --list="migration-foo, migration-bar"
and the code:
or subscribe.
↗ Original-Artikel auf dev.to lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to. - We can build artifacts on a pre-push hook and push them to the repository (
SOCIAL SHARE CARD GENERATOR