Skip to content

Commit

Permalink
Database configuration and companies endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
paweld-iRonin committed Oct 21, 2023
1 parent ef29648 commit 51e1a41
Show file tree
Hide file tree
Showing 18 changed files with 929 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DATABASE_HOST=db
DATABASE_USER=postgres
DATABASE_NAME=nestjs
DATABASE_PORT=5432
DATABASE_PASSWORD=
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ lerna-debug.log*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json
.env
20 changes: 20 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use the official Node.js 16 image as the base image
FROM node:16

# Set the working directory in the container
WORKDIR /app

# Copy the package.json and package-lock.json to the working directory
COPY package*.json ./

# Install Node.js dependencies
RUN npm install

# Copy the rest of the application code to the container
COPY . .

# Expose the port your Nest.js app will run on
EXPOSE 3000

# Start the Nest.js application
CMD ["npm", "run", "start:dev"]
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.7'
services:
db:
image: postgres
volumes:
- 'postgres:/var/lib/postgresql/data'
environment:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_DB: nestjs
web:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
volumes:
- .:/app
command: npm run start:dev
env_file:
- .env
depends_on:
- postgres

volumes:
postgres:
37 changes: 37 additions & 0 deletions migrations/1697905863173-createCompany.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
MigrationInterface,
QueryRunner,
Table,
} from "typeorm"

export class CreateCompany1697905863173 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: "company",
columns: [
{
name: "id",
type: "int",
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: "name",
type: "varchar",
},
{
name: "location",
type: "varchar",
},
],
}),
true,
)
}

async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable("company")
}
}
Loading

0 comments on commit 51e1a41

Please sign in to comment.