docs: add visible slice local workflow
Document the migration/seed/API/web workflow in a root README, add an API e2e smoke test that always checks /api/health and additionally exercises the real DatabaseModule/seeded data plus the arrivesAt validation rejection when DATABASE_URL is available, and add a `test:e2e` root script. Also fix `.env` loading so the documented root-level `.env` is actually found: `main.ts` never loaded dotenv at all, and `data-source.ts` loaded it relative to `process.cwd()`, which is `apps/api` (not the repo root) whenever npm runs a `--workspace` script. Both now resolve the repo-root `.env` explicitly. Also narrowed the CLI migrations glob to numeric-prefixed files so it no longer tries to load the colocated `*.migration.spec.ts` as a migration. Verified end-to-end against a real PostgreSQL instance: migrate, seed twice (idempotent), start the API, and exercise every documented route including a rejected POST /api/travel body containing arrivesAt. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import 'dotenv/config';
|
||||
import { config } from 'dotenv';
|
||||
import { resolve } from 'path';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
// npm workspace scripts (`db:migrate`, `db:seed`) run with this file's
|
||||
// workspace (`apps/api`) as the current working directory, not the repo
|
||||
// root where the documented `.env` lives. Resolve it explicitly so the
|
||||
// documented `npm run db:migrate` / `npm run db:seed` flow works regardless
|
||||
// of the caller's working directory.
|
||||
config({ path: resolve(__dirname, '../../../../.env') });
|
||||
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
|
||||
if (!databaseUrl?.trim()) {
|
||||
@@ -11,6 +19,6 @@ export const AppDataSource = new DataSource({
|
||||
type: 'postgres',
|
||||
url: databaseUrl,
|
||||
entities: [__dirname + '/../**/*.entity.{ts,js}'],
|
||||
migrations: [__dirname + '/migrations/*.{ts,js}'],
|
||||
migrations: [__dirname + '/migrations/[0-9]*.{ts,js}'],
|
||||
synchronize: false,
|
||||
});
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import { config } from 'dotenv';
|
||||
import { resolve } from 'path';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { configureApplication } from './app.config';
|
||||
|
||||
// `dev:api` runs via the `apps/api` npm workspace, so process.cwd() is
|
||||
// `apps/api`, not the repo root where the documented `.env` lives. Resolve
|
||||
// it explicitly so `npm run dev:api` picks up `DATABASE_URL` after
|
||||
// `Copy-Item .env.example .env` as documented in the README.
|
||||
config({ path: resolve(__dirname, '..', '..', '..', '.env') });
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
configureApplication(app);
|
||||
|
||||
Reference in New Issue
Block a user