cdk-drizzle-migrate 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +4136 -0
- package/.jsiiignore +0 -0
- package/API.md +249 -0
- package/LICENSE +202 -0
- package/README.md +115 -0
- package/lib/drizzle-migrate-provider.d.ts +58 -0
- package/lib/drizzle-migrate-provider.js +95 -0
- package/lib/handler/handler.js +49302 -0
- package/lib/handler/index.d.ts +8 -0
- package/lib/handler/index.js +8 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +18 -0
- package/node_modules/@types/aws-lambda/LICENSE +21 -0
- package/node_modules/@types/aws-lambda/README.md +15 -0
- package/node_modules/@types/aws-lambda/common/api-gateway.d.ts +83 -0
- package/node_modules/@types/aws-lambda/common/cloudfront.d.ts +245 -0
- package/node_modules/@types/aws-lambda/handler.d.ts +172 -0
- package/node_modules/@types/aws-lambda/index.d.ts +54 -0
- package/node_modules/@types/aws-lambda/package.json +226 -0
- package/node_modules/@types/aws-lambda/trigger/alb.d.ts +48 -0
- package/node_modules/@types/aws-lambda/trigger/amplify-resolver.d.ts +38 -0
- package/node_modules/@types/aws-lambda/trigger/api-gateway-authorizer.d.ts +246 -0
- package/node_modules/@types/aws-lambda/trigger/api-gateway-proxy.d.ts +336 -0
- package/node_modules/@types/aws-lambda/trigger/appsync-resolver.d.ts +121 -0
- package/node_modules/@types/aws-lambda/trigger/autoscaling.d.ts +41 -0
- package/node_modules/@types/aws-lambda/trigger/cdk-custom-resource.d.ts +158 -0
- package/node_modules/@types/aws-lambda/trigger/cloudformation-custom-resource.d.ts +236 -0
- package/node_modules/@types/aws-lambda/trigger/cloudfront-request.d.ts +22 -0
- package/node_modules/@types/aws-lambda/trigger/cloudfront-response.d.ts +21 -0
- package/node_modules/@types/aws-lambda/trigger/cloudwatch-alarm.d.ts +69 -0
- package/node_modules/@types/aws-lambda/trigger/cloudwatch-events.d.ts +8 -0
- package/node_modules/@types/aws-lambda/trigger/cloudwatch-logs.d.ts +37 -0
- package/node_modules/@types/aws-lambda/trigger/codebuild-cloudwatch-state.d.ts +104 -0
- package/node_modules/@types/aws-lambda/trigger/codecommit.d.ts +35 -0
- package/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch-action.d.ts +31 -0
- package/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch-pipeline.d.ts +32 -0
- package/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch-stage.d.ts +23 -0
- package/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch.d.ts +11 -0
- package/node_modules/@types/aws-lambda/trigger/codepipeline.d.ts +55 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/_common.d.ts +41 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/create-auth-challenge.d.ts +22 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/custom-email-sender.d.ts +76 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/custom-message.d.ts +52 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/custom-sms-sender.d.ts +51 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/define-auth-challenge.d.ts +21 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/index.d.ts +128 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/post-authentication.d.ts +15 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/post-confirmation.d.ts +26 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-authentication.d.ts +16 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-signup.d.ts +31 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-token-generation-v2.d.ts +73 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-token-generation.d.ts +53 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/user-migration.d.ts +40 -0
- package/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/verify-auth-challenge-response.d.ts +22 -0
- package/node_modules/@types/aws-lambda/trigger/connect-contact-flow.d.ts +64 -0
- package/node_modules/@types/aws-lambda/trigger/dynamodb-stream.d.ts +55 -0
- package/node_modules/@types/aws-lambda/trigger/eventbridge.d.ts +19 -0
- package/node_modules/@types/aws-lambda/trigger/guard-duty-event-notification.d.ts +36 -0
- package/node_modules/@types/aws-lambda/trigger/iot-authorizer.d.ts +48 -0
- package/node_modules/@types/aws-lambda/trigger/iot.d.ts +28 -0
- package/node_modules/@types/aws-lambda/trigger/kinesis-firehose-transformation.d.ts +51 -0
- package/node_modules/@types/aws-lambda/trigger/kinesis-stream.d.ts +56 -0
- package/node_modules/@types/aws-lambda/trigger/lambda-function-url.d.ts +45 -0
- package/node_modules/@types/aws-lambda/trigger/lex-v2.d.ts +164 -0
- package/node_modules/@types/aws-lambda/trigger/lex.d.ts +120 -0
- package/node_modules/@types/aws-lambda/trigger/msk.d.ts +28 -0
- package/node_modules/@types/aws-lambda/trigger/s3-batch.d.ts +41 -0
- package/node_modules/@types/aws-lambda/trigger/s3-event-notification.d.ts +290 -0
- package/node_modules/@types/aws-lambda/trigger/s3.d.ts +60 -0
- package/node_modules/@types/aws-lambda/trigger/secretsmanager.d.ts +15 -0
- package/node_modules/@types/aws-lambda/trigger/self-managed-kafka.d.ts +27 -0
- package/node_modules/@types/aws-lambda/trigger/ses.d.ts +109 -0
- package/node_modules/@types/aws-lambda/trigger/sns.d.ts +39 -0
- package/node_modules/@types/aws-lambda/trigger/sqs.d.ts +58 -0
- package/node_modules/@types/aws-lambda/trigger/transfer-family-authorizer.d.ts +110 -0
- package/package.json +165 -0
package/.jsiiignore
ADDED
|
File without changes
|
package/API.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# API Reference <a name="API Reference" id="api-reference"></a>
|
|
2
|
+
|
|
3
|
+
## Constructs <a name="Constructs" id="Constructs"></a>
|
|
4
|
+
|
|
5
|
+
### DrizzleMigrate <a name="DrizzleMigrate" id="cdk-drizzle-migrate.DrizzleMigrate"></a>
|
|
6
|
+
|
|
7
|
+
A custom resource that runs Drizzle migrations.
|
|
8
|
+
|
|
9
|
+
#### Initializers <a name="Initializers" id="cdk-drizzle-migrate.DrizzleMigrate.Initializer"></a>
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { DrizzleMigrate } from 'cdk-drizzle-migrate'
|
|
13
|
+
|
|
14
|
+
new DrizzleMigrate(scope: Construct, id: string, props: DrizzleMigrateProps)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
| **Name** | **Type** | **Description** |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrate.Initializer.parameter.scope">scope</a></code> | <code>constructs.Construct</code> | *No description.* |
|
|
20
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrate.Initializer.parameter.id">id</a></code> | <code>string</code> | *No description.* |
|
|
21
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrate.Initializer.parameter.props">props</a></code> | <code><a href="#cdk-drizzle-migrate.DrizzleMigrateProps">DrizzleMigrateProps</a></code> | *No description.* |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
##### `scope`<sup>Required</sup> <a name="scope" id="cdk-drizzle-migrate.DrizzleMigrate.Initializer.parameter.scope"></a>
|
|
26
|
+
|
|
27
|
+
- *Type:* constructs.Construct
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
##### `id`<sup>Required</sup> <a name="id" id="cdk-drizzle-migrate.DrizzleMigrate.Initializer.parameter.id"></a>
|
|
32
|
+
|
|
33
|
+
- *Type:* string
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
##### `props`<sup>Required</sup> <a name="props" id="cdk-drizzle-migrate.DrizzleMigrate.Initializer.parameter.props"></a>
|
|
38
|
+
|
|
39
|
+
- *Type:* <a href="#cdk-drizzle-migrate.DrizzleMigrateProps">DrizzleMigrateProps</a>
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
#### Methods <a name="Methods" id="Methods"></a>
|
|
44
|
+
|
|
45
|
+
| **Name** | **Description** |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrate.toString">toString</a></code> | Returns a string representation of this construct. |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
##### `toString` <a name="toString" id="cdk-drizzle-migrate.DrizzleMigrate.toString"></a>
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
public toString(): string
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Returns a string representation of this construct.
|
|
58
|
+
|
|
59
|
+
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
|
|
60
|
+
|
|
61
|
+
| **Name** | **Description** |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrate.isConstruct">isConstruct</a></code> | Checks if `x` is a construct. |
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
##### `isConstruct` <a name="isConstruct" id="cdk-drizzle-migrate.DrizzleMigrate.isConstruct"></a>
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { DrizzleMigrate } from 'cdk-drizzle-migrate'
|
|
71
|
+
|
|
72
|
+
DrizzleMigrate.isConstruct(x: any)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Checks if `x` is a construct.
|
|
76
|
+
|
|
77
|
+
Use this method instead of `instanceof` to properly detect `Construct`
|
|
78
|
+
instances, even when the construct library is symlinked.
|
|
79
|
+
|
|
80
|
+
Explanation: in JavaScript, multiple copies of the `constructs` library on
|
|
81
|
+
disk are seen as independent, completely different libraries. As a
|
|
82
|
+
consequence, the class `Construct` in each copy of the `constructs` library
|
|
83
|
+
is seen as a different class, and an instance of one class will not test as
|
|
84
|
+
`instanceof` the other class. `npm install` will not create installations
|
|
85
|
+
like this, but users may manually symlink construct libraries together or
|
|
86
|
+
use a monorepo tool: in those cases, multiple copies of the `constructs`
|
|
87
|
+
library can be accidentally installed, and `instanceof` will behave
|
|
88
|
+
unpredictably. It is safest to avoid using `instanceof`, and using
|
|
89
|
+
this type-testing method instead.
|
|
90
|
+
|
|
91
|
+
###### `x`<sup>Required</sup> <a name="x" id="cdk-drizzle-migrate.DrizzleMigrate.isConstruct.parameter.x"></a>
|
|
92
|
+
|
|
93
|
+
- *Type:* any
|
|
94
|
+
|
|
95
|
+
Any object.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
100
|
+
|
|
101
|
+
| **Name** | **Type** | **Description** |
|
|
102
|
+
| --- | --- | --- |
|
|
103
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrate.property.node">node</a></code> | <code>constructs.Node</code> | The tree node. |
|
|
104
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrate.property.handler">handler</a></code> | <code>aws-cdk-lib.aws_lambda_nodejs.NodejsFunction</code> | The Lambda function that executes the migrations. |
|
|
105
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrate.property.resource">resource</a></code> | <code>aws-cdk-lib.CustomResource</code> | The custom resource that was created. |
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
##### `node`<sup>Required</sup> <a name="node" id="cdk-drizzle-migrate.DrizzleMigrate.property.node"></a>
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
public readonly node: Node;
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- *Type:* constructs.Node
|
|
116
|
+
|
|
117
|
+
The tree node.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
##### `handler`<sup>Required</sup> <a name="handler" id="cdk-drizzle-migrate.DrizzleMigrate.property.handler"></a>
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
public readonly handler: NodejsFunction;
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- *Type:* aws-cdk-lib.aws_lambda_nodejs.NodejsFunction
|
|
128
|
+
|
|
129
|
+
The Lambda function that executes the migrations.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
##### `resource`<sup>Required</sup> <a name="resource" id="cdk-drizzle-migrate.DrizzleMigrate.property.resource"></a>
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
public readonly resource: CustomResource;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- *Type:* aws-cdk-lib.CustomResource
|
|
140
|
+
|
|
141
|
+
The custom resource that was created.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
## Structs <a name="Structs" id="Structs"></a>
|
|
147
|
+
|
|
148
|
+
### DrizzleMigrateProps <a name="DrizzleMigrateProps" id="cdk-drizzle-migrate.DrizzleMigrateProps"></a>
|
|
149
|
+
|
|
150
|
+
Properties for DrizzleMigrate.
|
|
151
|
+
|
|
152
|
+
#### Initializer <a name="Initializer" id="cdk-drizzle-migrate.DrizzleMigrateProps.Initializer"></a>
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { DrizzleMigrateProps } from 'cdk-drizzle-migrate'
|
|
156
|
+
|
|
157
|
+
const drizzleMigrateProps: DrizzleMigrateProps = { ... }
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Properties <a name="Properties" id="Properties"></a>
|
|
161
|
+
|
|
162
|
+
| **Name** | **Type** | **Description** |
|
|
163
|
+
| --- | --- | --- |
|
|
164
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrateProps.property.dbSecret">dbSecret</a></code> | <code>aws-cdk-lib.aws_secretsmanager.ISecret</code> | The database secret containing connection details Must contain standard CDK database secret properties: username, password, host, port, engine, etc. |
|
|
165
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrateProps.property.migrationsPath">migrationsPath</a></code> | <code>string</code> | The path to the migrations directory This directory will be bundled with the Lambda function. |
|
|
166
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrateProps.property.vpc">vpc</a></code> | <code>aws-cdk-lib.aws_ec2.IVpc</code> | The VPC where the Lambda function will be deployed Required to allow the Lambda function to connect to the database. |
|
|
167
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrateProps.property.cluster">cluster</a></code> | <code>aws-cdk-lib.aws_rds.IDatabaseCluster \| aws-cdk-lib.aws_rds.IDatabaseInstance</code> | Optional database cluster or instance If provided and a new security group is created, the security group will be configured to allow access to the database. |
|
|
168
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrateProps.property.handlerProps">handlerProps</a></code> | <code>aws-cdk-lib.aws_lambda_nodejs.NodejsFunctionProps</code> | Optional properties to customize the Lambda function Excludes runtime, entry, and handler which are managed by the construct. |
|
|
169
|
+
| <code><a href="#cdk-drizzle-migrate.DrizzleMigrateProps.property.vpcSubnets">vpcSubnets</a></code> | <code>aws-cdk-lib.aws_ec2.SubnetSelection</code> | Optional subnet selection to deploy the Lambda function. |
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
##### `dbSecret`<sup>Required</sup> <a name="dbSecret" id="cdk-drizzle-migrate.DrizzleMigrateProps.property.dbSecret"></a>
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
public readonly dbSecret: ISecret;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
- *Type:* aws-cdk-lib.aws_secretsmanager.ISecret
|
|
180
|
+
|
|
181
|
+
The database secret containing connection details Must contain standard CDK database secret properties: username, password, host, port, engine, etc.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
##### `migrationsPath`<sup>Required</sup> <a name="migrationsPath" id="cdk-drizzle-migrate.DrizzleMigrateProps.property.migrationsPath"></a>
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
public readonly migrationsPath: string;
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
- *Type:* string
|
|
192
|
+
|
|
193
|
+
The path to the migrations directory This directory will be bundled with the Lambda function.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
##### `vpc`<sup>Required</sup> <a name="vpc" id="cdk-drizzle-migrate.DrizzleMigrateProps.property.vpc"></a>
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
public readonly vpc: IVpc;
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
- *Type:* aws-cdk-lib.aws_ec2.IVpc
|
|
204
|
+
|
|
205
|
+
The VPC where the Lambda function will be deployed Required to allow the Lambda function to connect to the database.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
##### `cluster`<sup>Optional</sup> <a name="cluster" id="cdk-drizzle-migrate.DrizzleMigrateProps.property.cluster"></a>
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
public readonly cluster: IDatabaseCluster | IDatabaseInstance;
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
- *Type:* aws-cdk-lib.aws_rds.IDatabaseCluster | aws-cdk-lib.aws_rds.IDatabaseInstance
|
|
216
|
+
- *Default:* No database connection is configured
|
|
217
|
+
|
|
218
|
+
Optional database cluster or instance If provided and a new security group is created, the security group will be configured to allow access to the database.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
##### `handlerProps`<sup>Optional</sup> <a name="handlerProps" id="cdk-drizzle-migrate.DrizzleMigrateProps.property.handlerProps"></a>
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
public readonly handlerProps: NodejsFunctionProps;
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
- *Type:* aws-cdk-lib.aws_lambda_nodejs.NodejsFunctionProps
|
|
229
|
+
- *Default:* Default Lambda configuration is used
|
|
230
|
+
|
|
231
|
+
Optional properties to customize the Lambda function Excludes runtime, entry, and handler which are managed by the construct.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
##### `vpcSubnets`<sup>Optional</sup> <a name="vpcSubnets" id="cdk-drizzle-migrate.DrizzleMigrateProps.property.vpcSubnets"></a>
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
public readonly vpcSubnets: SubnetSelection;
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
- *Type:* aws-cdk-lib.aws_ec2.SubnetSelection
|
|
242
|
+
- *Default:* PRIVATE_WITH_EGRESS subnets
|
|
243
|
+
|
|
244
|
+
Optional subnet selection to deploy the Lambda function.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# About
|
|
2
|
+
|
|
3
|
+
This CDK construct library makes it possible to run the drizzle
|
|
4
|
+
migrate at deploy of your stack time against the RDS cluster of your
|
|
5
|
+
choice. The supported engines are PostgreSQL, MariaDB and MySQL.
|
|
6
|
+
|
|
7
|
+
This construct library is intended to be used in enterprise
|
|
8
|
+
environments, and works in isolated subnets.
|
|
9
|
+
|
|
10
|
+
<p align="left">
|
|
11
|
+
<a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release" alt=semantic-release: angular"></a>
|
|
12
|
+
<a href="https://github.com/berenddeboer/cdk-rds-sql/actions/workflows/release.yml"><img src="https://github.com/berenddeboer/cdk-rds-sql/actions/workflows/release.yml/badge.svg" alt="Release badge"></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
# Requirements
|
|
16
|
+
|
|
17
|
+
This package assumes you deploy from a unix shell with access to `cp`,
|
|
18
|
+
`mkdir`, and `curl`.
|
|
19
|
+
|
|
20
|
+
# Installation
|
|
21
|
+
|
|
22
|
+
npm i cdk-drizzle-migrate
|
|
23
|
+
|
|
24
|
+
You probably will be very unhappy if you don't have esbuild, so as
|
|
25
|
+
usual in a cdk typescript project make sure that is installed too:
|
|
26
|
+
|
|
27
|
+
npm i esbuild
|
|
28
|
+
|
|
29
|
+
And obviously drizzle-kit and drizzle-orm should be available if you
|
|
30
|
+
actually want to create migrations.
|
|
31
|
+
|
|
32
|
+
# Usage
|
|
33
|
+
|
|
34
|
+
Have an RDS database and a secret that stores your db
|
|
35
|
+
credentials. Usually this will be the root secret for your RDS
|
|
36
|
+
database:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { DrizzleMigrate } from "@berenddeboer/cdk-drizzle-migrate"
|
|
40
|
+
|
|
41
|
+
// Create the DrizzleMigrate construct
|
|
42
|
+
const migrator = new DrizzleMigrate(this, "DrizzleMigration", {
|
|
43
|
+
dbSecret: database.secret!,
|
|
44
|
+
migrationsPath: "migrations",
|
|
45
|
+
vpc: vpc,
|
|
46
|
+
vpcSubnets: {
|
|
47
|
+
subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
|
|
48
|
+
},
|
|
49
|
+
cluster: database, // Pass the database instance to allow automatic security group configuration
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Your secret should look like the standard one created by CDK:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"password": "some-password",
|
|
58
|
+
"dbname": "testdb",
|
|
59
|
+
"engine": "postgres",
|
|
60
|
+
"port": 5432,
|
|
61
|
+
"dbInstanceIdentifier": "some-name",
|
|
62
|
+
"host": "some-name.cvabql2flhit.us-east-1.rds.amazonaws.com",
|
|
63
|
+
"username": "postgres"
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Specify the path where the migrations are stored, `migrations` in this case.
|
|
68
|
+
|
|
69
|
+
When this resource is deployed, it will run `drizzle-kit migrate` for
|
|
70
|
+
you in the lambda.
|
|
71
|
+
|
|
72
|
+
The default timeout is 5 minutes, you need to increase this if your
|
|
73
|
+
migration takes more time.
|
|
74
|
+
|
|
75
|
+
Passing your database cluster is optional. If supplied, the lambda's
|
|
76
|
+
security group will be added as allowed source to the database
|
|
77
|
+
security group if no security group is present in
|
|
78
|
+
`handlerProps.securityGroups`.
|
|
79
|
+
|
|
80
|
+
If you do not pass a cluster, make sure to pass in a security group in
|
|
81
|
+
`handlerProps.securityGroups` which can connect to your database.
|
|
82
|
+
|
|
83
|
+
Also if you do not pass a cluster you, but still create a database,
|
|
84
|
+
you may wish to add a dependency to make sure the database is created,
|
|
85
|
+
before the migration is run:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
migrator.resource.node.addDependency(cluster)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
# Potential pitfalls
|
|
92
|
+
|
|
93
|
+
1. The lambda can only run for 15 minutes. If your migrations take
|
|
94
|
+
longer, this solution will not work.
|
|
95
|
+
|
|
96
|
+
# Working on this code
|
|
97
|
+
|
|
98
|
+
1. Install packages: `npm i`
|
|
99
|
+
|
|
100
|
+
2. Bootstrap CDK if not done: `npx cdk bootstrap
|
|
101
|
+
aws://123456/us-east-1`. Replace 123456 with your AWS account.
|
|
102
|
+
|
|
103
|
+
## Handler notes
|
|
104
|
+
|
|
105
|
+
When making changes to the Lambda handler code in `lambda/index.ts`, you need to transpile it to JavaScript:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npx projen build:handler
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This will generate `src/handler/handler.js` which is used by the CDK
|
|
112
|
+
construct.
|
|
113
|
+
|
|
114
|
+
This technique is used to avoid having to bundle nodejs dependencies
|
|
115
|
+
as that doesn't work well in this case.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CustomResource } from "aws-cdk-lib";
|
|
2
|
+
import * as ec2 from "aws-cdk-lib/aws-ec2";
|
|
3
|
+
import { NodejsFunction, NodejsFunctionProps } from "aws-cdk-lib/aws-lambda-nodejs";
|
|
4
|
+
import * as rds from "aws-cdk-lib/aws-rds";
|
|
5
|
+
import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";
|
|
6
|
+
import { Construct } from "constructs";
|
|
7
|
+
/**
|
|
8
|
+
* Properties for DrizzleMigrate
|
|
9
|
+
*/
|
|
10
|
+
export interface DrizzleMigrateProps {
|
|
11
|
+
/**
|
|
12
|
+
* The database secret containing connection details
|
|
13
|
+
* Must contain standard CDK database secret properties: username, password, host, port, engine, etc.
|
|
14
|
+
*/
|
|
15
|
+
readonly dbSecret: secretsmanager.ISecret;
|
|
16
|
+
/**
|
|
17
|
+
* The path to the migrations directory
|
|
18
|
+
* This directory will be bundled with the Lambda function
|
|
19
|
+
*/
|
|
20
|
+
readonly migrationsPath: string;
|
|
21
|
+
/**
|
|
22
|
+
* Optional properties to customize the Lambda function
|
|
23
|
+
* Excludes runtime, entry, and handler which are managed by the construct
|
|
24
|
+
* @default - Default Lambda configuration is used
|
|
25
|
+
*/
|
|
26
|
+
readonly handlerProps?: NodejsFunctionProps;
|
|
27
|
+
/**
|
|
28
|
+
* The VPC where the Lambda function will be deployed
|
|
29
|
+
* Required to allow the Lambda function to connect to the database
|
|
30
|
+
*/
|
|
31
|
+
readonly vpc: ec2.IVpc;
|
|
32
|
+
/**
|
|
33
|
+
* Optional subnet selection to deploy the Lambda function
|
|
34
|
+
* @default - PRIVATE_WITH_EGRESS subnets
|
|
35
|
+
*/
|
|
36
|
+
readonly vpcSubnets?: ec2.SubnetSelection;
|
|
37
|
+
/**
|
|
38
|
+
* Optional database cluster or instance
|
|
39
|
+
* If provided and a new security group is created, the security group will be
|
|
40
|
+
* configured to allow access to the database
|
|
41
|
+
* @default - No database connection is configured
|
|
42
|
+
*/
|
|
43
|
+
readonly cluster?: rds.IDatabaseCluster | rds.IDatabaseInstance;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A custom resource that runs Drizzle migrations
|
|
47
|
+
*/
|
|
48
|
+
export declare class DrizzleMigrate extends Construct {
|
|
49
|
+
/**
|
|
50
|
+
* The custom resource that was created
|
|
51
|
+
*/
|
|
52
|
+
readonly resource: CustomResource;
|
|
53
|
+
/**
|
|
54
|
+
* The Lambda function that executes the migrations
|
|
55
|
+
*/
|
|
56
|
+
readonly handler: NodejsFunction;
|
|
57
|
+
constructor(scope: Construct, id: string, props: DrizzleMigrateProps);
|
|
58
|
+
}
|