diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..65852fc --- /dev/null +++ b/.env.example @@ -0,0 +1,14 @@ +# Database Configuration +DB_USER=desker +DB_PASSWORD=desker +DB_NAME=desker +DB_PORT_EXTERNAL=5433 + +# API Configuration +API_PORT_EXTERNAL=3891 +JWT_SECRET=super-secret-change-me-for-security +WEB_ORIGIN=http://localhost:3890 + +# Web Application Configuration +WEB_PORT_EXTERNAL=3890 +VITE_API_BASE_URL=http://localhost:3891 diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 72d4449..f7d774d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,13 +6,6 @@ - - - - - - - diff --git a/DOCKER_SETUP.md b/DOCKER_SETUP.md index cf12479..3452ee6 100644 --- a/DOCKER_SETUP.md +++ b/DOCKER_SETUP.md @@ -24,16 +24,17 @@ Create a `.env` file in the root directory. The following variables are supporte ## Deployment Steps -1. **Build and start the containers:** +1. **Copy the environment variables template:** + ```bash + cp .env.example .env + ``` + *(Ensure you have a `.env.example` or create one from the table above)*. + +2. **Build and start the containers:** ```bash docker-compose up -d --build ``` - -2. **Run Database Migrations:** - Since the API uses Prisma, you need to run migrations to set up the database schema: - ```bash - docker exec -it hotdesking_api npx prisma migrate deploy - ``` + PostgreSQL and the API will start. The API will automatically run migrations during startup. 3. **(Optional) Seed the Database:** If you have a seed script defined in `apps/api/prisma/seed.ts`: @@ -41,6 +42,18 @@ Create a `.env` file in the root directory. The following variables are supporte docker exec -it hotdesking_api npx prisma db seed ``` +## Important Note: PostgreSQL Initial Configuration +When you run `docker-compose up` for the **first time**, the PostgreSQL container uses the `DB_USER`, `DB_PASSWORD`, and `DB_NAME` values to initialize the database. These values are stored in a persistent volume (`postgres_data`). + +If you change these environment variables **after** the first run, the database will **not** be re-initialized. This can cause connection errors (like `role "desker" does not exist`). + +To apply new database credentials, you must remove the volume and start over: +```bash +docker-compose down -v +docker-compose up -d +``` +**Warning: This will delete all data in your database.** + 4. **Access the Applications:** - Web App: [http://localhost:5173](http://localhost:5173) - API: [http://localhost:3000](http://localhost:3000) diff --git a/apps/api/prisma/migrations/20260328180000_add_organization_details/migration.sql b/apps/api/prisma/migrations/20260328180000_add_organization_details/migration.sql index 51a0fcf..2766174 100644 --- a/apps/api/prisma/migrations/20260328180000_add_organization_details/migration.sql +++ b/apps/api/prisma/migrations/20260328180000_add_organization_details/migration.sql @@ -1,3 +1,14 @@ +-- CreateTable +CREATE TABLE "Asset" ( + "id" TEXT NOT NULL, + "data" BYTEA NOT NULL, + "mimeType" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Asset_pkey" PRIMARY KEY ("id") +); + -- AlterTable ALTER TABLE "Organization" ADD COLUMN "language" TEXT NOT NULL DEFAULT 'en', ADD COLUMN "logoId" TEXT, @@ -8,3 +19,36 @@ CREATE UNIQUE INDEX "Organization_logoId_key" ON "Organization"("logoId"); -- AddForeignKey ALTER TABLE "Organization" ADD CONSTRAINT "Organization_logoId_fkey" FOREIGN KEY ("logoId") REFERENCES "Asset"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- Also add missing columns for other models that are in schema.prisma but not in init +ALTER TABLE "Building" ADD COLUMN "description" TEXT, ADD COLUMN "imageUrl" TEXT, ADD COLUMN "imageId" TEXT; +CREATE UNIQUE INDEX "Building_imageId_key" ON "Building"("imageId"); +ALTER TABLE "Building" ADD CONSTRAINT "Building_imageId_fkey" FOREIGN KEY ("imageId") REFERENCES "Asset"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +ALTER TABLE "Floor" ADD COLUMN "planImageUrl" TEXT, ADD COLUMN "name" TEXT, ADD COLUMN "planImageId" TEXT; +CREATE UNIQUE INDEX "Floor_planImageId_key" ON "Floor"("planImageId"); +ALTER TABLE "Floor" ADD CONSTRAINT "Floor_planImageId_fkey" FOREIGN KEY ("planImageId") REFERENCES "Asset"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +ALTER TABLE "Space" ADD COLUMN "height" DOUBLE PRECISION, ADD COLUMN "width" DOUBLE PRECISION, ADD COLUMN "rotation" DOUBLE PRECISION DEFAULT 0; + +ALTER TABLE "User" ADD COLUMN "name" TEXT, ADD COLUMN "avatarUrl" TEXT, ADD COLUMN "avatarId" TEXT; +CREATE UNIQUE INDEX "User_avatarId_key" ON "User"("avatarId"); +ALTER TABLE "User" ADD CONSTRAINT "User_avatarId_fkey" FOREIGN KEY ("avatarId") REFERENCES "Asset"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- CreateTable +CREATE TABLE "Reservation" ( + "id" TEXT NOT NULL, + "startTime" TIMESTAMP(3) NOT NULL, + "endTime" TIMESTAMP(3) NOT NULL, + "userId" TEXT, + "spaceId" TEXT NOT NULL, + "note" TEXT, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Reservation_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "Reservation" ADD CONSTRAINT "Reservation_spaceId_fkey" FOREIGN KEY ("spaceId") REFERENCES "Space"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "Reservation" ADD CONSTRAINT "Reservation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;