From 7fd7adabd265dc2849eae8760026fa5a65e03247 Mon Sep 17 00:00:00 2001 From: Lucas Dale Date: Tue, 12 Nov 2024 22:22:59 -0500 Subject: [PATCH] Remove unneeded migration strategy --- .github/workflows/stage.yaml | 6 +---- cli/migrator.ts | 51 ------------------------------------ lib/secrets.ts | 25 ------------------ package.json | 2 +- pnpm-lock.yaml | 10 ------- 5 files changed, 2 insertions(+), 92 deletions(-) delete mode 100644 cli/migrator.ts delete mode 100644 lib/secrets.ts diff --git a/.github/workflows/stage.yaml b/.github/workflows/stage.yaml index 137f04b..98e95ca 100644 --- a/.github/workflows/stage.yaml +++ b/.github/workflows/stage.yaml @@ -39,13 +39,9 @@ jobs: - name: Set SST Config Secret run: | npx sst secret set DATABASE_URL ${{ secrets.DATABASE_URL_STAGING }} --stage staging - npx sst secret set NEXT_PUBLIC_SITE_URL ${{ secrets.NEXT_PUBLIC_SITE_URL_STAGING }} --stage staging + npx sst secret set NEXT_PUBLIC_URL ${{ secrets.NEXT_PUBLIC_URL_STAGING }} --stage staging npx sst secret set COMMIT_SHA ${{ github.sha }} --stage staging - - name: Run staging DB Migrations - run: | - STAGE=staging npx tsx cli/migrator.ts - - name: Deploy with SST run: pnpm run deploy:stage diff --git a/cli/migrator.ts b/cli/migrator.ts deleted file mode 100644 index 378f41f..0000000 --- a/cli/migrator.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { migrate } from "drizzle-orm/postgres-js/migrator"; -import { drizzle } from "drizzle-orm/neon-serverless"; -import { Pool, neonConfig } from "@neondatabase/serverless"; -import ws from "ws"; - -import * as schema from "../lib/schema"; -import getSecret from "../lib/secrets"; - -async function performMigration() { - const dbUrlResponse = await getSecret("DATABASE_URL"); - const dbUrl = dbUrlResponse?.Parameter?.Value; - if (!dbUrl) { - console.error("DATABASE_URL not found"); - return; - } - - neonConfig.webSocketConstructor = ws; // <-- this is the key bit - - const pool = new Pool({ connectionString: dbUrl }); - pool.on("error", (err) => console.error(err)); // deal with e.g. re-connect - - const client = await pool.connect(); - - try { - await client.query("BEGIN"); - const db = await drizzle(client, { schema }); - await migrate(db, { migrationsFolder: "src/migrations" }); - await client.query("COMMIT"); - } catch (err) { - await client.query("ROLLBACK"); - throw err; - } finally { - client.release(); - } - - await pool.end(); -} - -if (require.main === module) { - console.log("Running migrations"); - - performMigration() - .then((val) => { - console.log("Migration performed"); - process.exit(0); - }) - .catch((err) => { - console.log("err", err); - process.exit(1); - }); -} diff --git a/lib/secrets.ts b/lib/secrets.ts deleted file mode 100644 index 42d1c9d..0000000 --- a/lib/secrets.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { GetParameterCommand, SSMClient } from "@aws-sdk/client-ssm"; - -//Grab Secrets from AWS Parameter Store -const STAGE = process.env.STAGE ? process.env.STAGE : "production"; -const PROJECT = "letusdev"; -const REGION = "us-east-1"; - -export default async function getSecret(secretName: string) { - if (!secretName) { - throw new Error("Secret name is required"); - } - - const client = new SSMClient({ region: REGION }); - const paramName = `/sst/${PROJECT}/${STAGE}/Secret/${secretName}/value`; - - const paramOptions = { - Name: paramName, - WithDecryption: true, - }; - - const command = new GetParameterCommand(paramOptions); - const response = await client.send(command); - - return response; -} diff --git a/package.json b/package.json index 725d574..5f7d72f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "dev": "next dev", "start": "next start", "deploy": "sst deploy --stage production", - "migrate": "tsx cli/migrator.ts", "deploy:stage": "sst deploy --stage staging", "takeDown": "npx sst remove --stage production", "generate": "npx drizzle-kit generate", @@ -45,6 +44,7 @@ "tailwindcss": "3.4.1", "tailwindcss-animate": "^1.0.7", "typescript": "5.3.3", + "ws": "^8.18.0", "zod": "^3.23.8" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c91efb..0e2f595 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -114,9 +114,6 @@ importers: '@types/react-dom': specifier: 18.2.18 version: 18.2.18 - '@types/ws': - specifier: ^8.5.13 - version: 8.5.13 aws-cdk-lib: specifier: 2.142.1 version: 2.142.1(constructs@10.4.2) @@ -1954,9 +1951,6 @@ packages: '@types/uuid@9.0.8': resolution: {integrity: sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==} - '@types/ws@8.5.13': - resolution: {integrity: sha512-osM/gWBTPKgHV8XkTunnegTRIsvF6owmf5w+JtAfOw472dptdm0dlGv4xCt6GwQRcC2XVOvvRE/0bAoQcL2QkA==} - '@ungap/structured-clone@1.2.0': resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} @@ -5855,10 +5849,6 @@ snapshots: '@types/uuid@9.0.8': {} - '@types/ws@8.5.13': - dependencies: - '@types/node': 20.11.5 - '@ungap/structured-clone@1.2.0': {} abbrev@2.0.0: {}