The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Keyspace, Table } from "@alchemy.run/aws/Keyspaces"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as keyspaces from "@distilled.cloud/aws/keyspaces"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | const getTable = (keyspaceName: string, tableName: string) => |
| 11 | keyspaces |
| 12 | .getTable({ keyspaceName, tableName }) |
| 13 | .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined))); |
| 14 | |
| 15 | test.provider( |
| 16 | "create, add column, delete Keyspaces table", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | yield* stack.destroy(); |
| 20 | |
| 21 | const ksName = "alchemy_tbl_test_ks"; |
| 22 | |
| 23 | // create keyspace + table |
| 24 | const created = yield* stack.deploy( |
| 25 | Effect.gen(function* () { |
| 26 | const keyspace = yield* Keyspace("Ks", { keyspaceName: ksName }); |
| 27 | const table = yield* Table("Events", { |
| 28 | keyspaceName: keyspace.keyspaceName, |
| 29 | tableName: "events", |
| 30 | columns: [ |
| 31 | { name: "device", type: "text" }, |
| 32 | { name: "ts", type: "timestamp" }, |
| 33 | { name: "payload", type: "blob" }, |
| 34 | ], |
| 35 | partitionKeys: ["device"], |
| 36 | clusteringKeys: [{ name: "ts", orderBy: "DESC" }], |
| 37 | pointInTimeRecovery: true, |
| 38 | }); |
| 39 | return { table }; |
| 40 | }), |
| 41 | ); |
| 42 | |
| 43 | expect(created.table.tableName).toEqual("events"); |
| 44 | expect(created.table.status).toEqual("ACTIVE"); |
| 45 | |
| 46 | // out-of-band verification |
| 47 | const observed = yield* getTable(ksName, "events"); |
| 48 | expect(observed?.status).toEqual("ACTIVE"); |
| 49 | expect(observed?.pointInTimeRecovery?.status).toEqual("ENABLED"); |
| 50 | const cols = new Set((observed?.schemaDefinition?.allColumns ?? []).map((c) => c.name)); |
| 51 | expect(cols.has("device")).toBe(true); |
| 52 | expect(cols.has("payload")).toBe(true); |
| 53 | |
| 54 | // update: add a column in place |
| 55 | yield* stack.deploy( |
| 56 | Effect.gen(function* () { |
| 57 | const keyspace = yield* Keyspace("Ks", { keyspaceName: ksName }); |
| 58 | const table = yield* Table("Events", { |
| 59 | keyspaceName: keyspace.keyspaceName, |
| 60 | tableName: "events", |
| 61 | columns: [ |
| 62 | { name: "device", type: "text" }, |
| 63 | { name: "ts", type: "timestamp" }, |
| 64 | { name: "payload", type: "blob" }, |
| 65 | { name: "region", type: "text" }, |
| 66 | ], |
| 67 | partitionKeys: ["device"], |
| 68 | clusteringKeys: [{ name: "ts", orderBy: "DESC" }], |
| 69 | pointInTimeRecovery: true, |
| 70 | }); |
| 71 | return { table }; |
| 72 | }), |
| 73 | ); |
| 74 | const reobserved = yield* getTable(ksName, "events"); |
| 75 | const reCols = new Set((reobserved?.schemaDefinition?.allColumns ?? []).map((c) => c.name)); |
| 76 | expect(reCols.has("region")).toBe(true); |
| 77 | |
| 78 | // delete |
| 79 | yield* stack.destroy(); |
| 80 | const gone = yield* getTable(ksName, "events"); |
| 81 | expect(gone).toBeUndefined(); |
| 82 | }), |
| 83 | { |
| 84 | tags: ["provider:aws", "provider:aws:keyspaces", "live"], |
| 85 | timeout: 300_000, |
| 86 | }, |
| 87 | ); |