Skip to content

Commit

Permalink
fix local DB
Browse files Browse the repository at this point in the history
  • Loading branch information
revmischa committed Jul 2, 2024
1 parent 0e04062 commit 4a24b6c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Edit `sst.config.ts` and set your default AWS profile and region.
```shell
npm i -g pnpm # install pnpm globally
pnpm i # install dependencies + generate types from DB and GQL schemas
pnpm db:migrate # run DB migrations
pnpm dev # start local dev server
```

Expand Down
2 changes: 1 addition & 1 deletion bin/startLocalDb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ if [[ -n "${CI}" ]]; then
else
echo "Starting DB"
docker-compose --project-directory "${SCRIPT_DIR}/.." up -d --remove-orphans
"$SCRIPT_DIR/waitForPg.sh"
"$SCRIPT_DIR/waitForPg.sh" || (echo "Failed to start DB" && exit 1)
fi

2 changes: 1 addition & 1 deletion bin/waitForPg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -ex

function testcmd {
docker-compose exec -T sst-local-db psql -U postgres -c "select 'postgres is alive'"
docker-compose exec -T database psql -U postgres -c "select 'postgres is alive'"
}

TRIES=0
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
local-db:
database:
container_name: local-pg
image: postgres:16
command: -c 'max_connections=200' # -c 'log_statement=all'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"db:migrate:test": "pnpm db:start && pnpm -C backend migrate:test",
"db:start": "bin/startLocalDb.sh",
"db:stop": "docker-compose down",
"clean": "tsc --clean && rm -rf .build .sst dist common/graphql/generated && pnpm run --recursive --if-present clean"
"clean": "tsc --clean && rm -rf .build .sst common/generated graphql/generated && pnpm run --recursive --if-present clean"
},
"dependencies": {
"desm": "^1.3.0",
Expand Down
9 changes: 8 additions & 1 deletion stacks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Secrets } from './secrets';
// deal with dynamic imports of node built-ins (e.g. "crypto")
// from https://github.com/evanw/esbuild/pull/2067#issuecomment-1073039746
// and hardcode __dirname for https://github.com/prisma/prisma/issues/14484
export const ESM_REQUIRE_SHIM = `await(async()=>{let{dirname:e}=await import("path"),{fileURLToPath:i}=await import("url");if(typeof globalThis.__filename>"u"&&(globalThis.__filename=i(import.meta.url)),typeof globalThis.__dirname>"u"&&(globalThis.__dirname='/var/task'),typeof globalThis.require>"u"){let{default:a}=await import("module");globalThis.require=a.createRequire(import.meta.url)}})();`;
export const ESM_REQUIRE_SHIM = `const require = (await import("node:module")).createRequire(import.meta.url);const __filename = (await import("node:url")).fileURLToPath(import.meta.url);globalThis.__dirname='/var/task';`;

export const RUNTIME = Runtime.NODEJS_20_X;

Expand All @@ -30,6 +30,13 @@ export default function main(app: sst.App) {
tracing: 'active',
nodejs: {
sourcemap: true,
esbuild: {
mainFields: ['module', 'main'],
minify: true,
banner: {
js: ESM_REQUIRE_SHIM,
},
},
},

// N.B. bundle settings are defined in Layers
Expand Down
2 changes: 1 addition & 1 deletion stacks/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function Web({ stack, app }: StackContext) {
const dns = use(Dns);
const isLocal = app.local;

if (!isLocal && !WEB_URL) {
if (!isLocal && !process.env.SST_STAGE && !WEB_URL) {
console.warn(`Please set WEB_URL in .env.${app.stage} to the URL of your frontend site.`);
}

Expand Down

0 comments on commit 4a24b6c

Please sign in to comment.