|
2 | 2 | 
|
3 | 3 | [](https://david-dm.org//kolomied/cdk-sqlserver-seeder)
|
4 | 4 |
|
5 |
| -A simple CDK seeder for SQL Server |
| 5 | +A simple CDK seeder for SQL Server RDS databases. |
6 | 6 |
|
7 |
| -## Prerequisites for local development |
| 7 | +*cdk-sqlserver-seeder* library is a [AWS CDK](https://aws.amazon.com/cdk/) construct that provides a way |
| 8 | +to execute custom SQL scripts on RDS SQL Server resource creation/deletion. |
8 | 9 |
|
9 |
| -Install PowerShell Core https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7 |
10 |
| -Install https://www.powershellgallery.com/packages/AWSLambdaPSCore/2.0.0.0 |
| 10 | +The construct relies on [Invoke-SqlCmd](https://docs.microsoft.com/en-us/powershell/module/sqlserver/invoke-sqlcmd) cmdlet |
| 11 | +to run the scripts and handle possible errors. Provides a way to handle transient errors during stack provisioning. |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +```typescript |
| 16 | +import * as cdk from '@aws-cdk/core'; |
| 17 | +import * as ec2 from '@aws-cdk/aws-ec2'; |
| 18 | +import * as rds from '@aws-cdk/aws-rds'; |
| 19 | +import { SqlServerSeeder } from 'cdk-sqlserver-seeder'; |
| 20 | + |
| 21 | +export class DatabaseStack extends cdk.Stack { |
| 22 | + constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { |
| 23 | + super(scope, id, props); |
| 24 | + |
| 25 | + const sqlServer = new rds.DatabaseInstance(this, 'Instance', { |
| 26 | + engine: rds.DatabaseInstanceEngine.SQL_SERVER_WEB, |
| 27 | + // all other properties removed for clarity |
| 28 | + }); |
| 29 | + |
| 30 | + const seeder = new SqlSeederSecret(this, "SqlSeederSecret", { |
| 31 | + database: sqlServer, |
| 32 | + port: 1433, |
| 33 | + vpc: vpc, |
| 34 | + createScriptPath: "./SQL/v1.0.0.sql", // script to be executed on resource creation |
| 35 | + deleteScriptPath: "./SQL/cleanup.sql" // script to be executed on resource deletion |
| 36 | + }); |
| 37 | + } |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +## Acknowledgements |
| 42 | +The whole project inspired by [aws-cdk-dynamodb-seeder](https://github.com/elegantdevelopment/aws-cdk-dynamodb-seeder). |
| 43 | +I though it would be very helpful to have a similar way to seed initial schema to more traditional SQL Server databases. |
0 commit comments