-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Added server initialization code.
π Fixed server close callback. π Improved error handling. π¦ Updated dependencies. π Initial commit for server setup.
- Loading branch information
1 parent
f4de5be
commit 2746880
Showing
7 changed files
with
136 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true, | ||
"source.fixAll.tslint": true, | ||
"source.organizeImports": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1 @@ | ||
# University Management Core Service | ||
This guide will walk you through the process of setting up the University Management Core Service Starter project. By following these steps, you will clone the project, install dependencies, and configure Prisma for database management. Let's get started! | ||
|
||
|
||
## Installation Steps | ||
### Follow these steps to clone and set up starter project: | ||
|
||
1. `Clone the project:` Open your terminal or command prompt and run the following command to clone the project repository: | ||
|
||
```bash | ||
git clone https://github.com/Programming-Hero-Next-Level-Development/university-management-core-service-starter.git university-management-core-service | ||
``` | ||
|
||
2. `Navigate into the project directory:` Use the cd command to navigate into the project directory: | ||
|
||
```bash | ||
cd university-management-core-service | ||
``` | ||
|
||
3. `Install project dependencies:` Next, install the project dependencies by running the following command: | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
4. Configure Prisma and the database connection: | ||
|
||
- Add Prisma as a development dependency by running the following command: | ||
```bash | ||
yarn add prisma --save-dev | ||
``` | ||
|
||
- Set up your Prisma project by creating the Prisma schema file using the following command: | ||
```bash | ||
npx prisma init | ||
``` | ||
|
||
- Open the prisma/schema.prisma file and configure your database connection details. | ||
|
||
```bash | ||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
} | ||
``` | ||
|
||
- Create a .env file in the project root directory and set the DATABASE_URL environment variable. Replace the placeholders with your database connection details: | ||
```bash | ||
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=SCHEMA" | ||
``` | ||
|
||
5. Creating the database schema | ||
6. Migrate the database schema: Use the following command to create and apply the initial database schema: | ||
|
||
```bash | ||
npx prisma migrate dev --name init | ||
``` | ||
This command creates a new migration file based on your schema changes and applies it to your database. | ||
|
||
6. `Install Prisma Client:` Install the Prisma Client library by running the following command: | ||
```bash | ||
yarn add @prisma/client | ||
``` | ||
|
||
This command installs the Prisma Client, which provides an interface to interact with your database. | ||
|
||
That's it! You have successfully set up the University Management Core Service Starter project. You can now start exploring and working with the codebase. Refer to the project documentation or README for further instructions on how to run and use the core service. | ||
|
||
Happy coding! | ||
## Full-Stack-Booking-Management |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" SERIAL NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"email" TEXT NOT NULL, | ||
|
||
CONSTRAINT "User_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Post" ( | ||
"id" SERIAL NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"content" TEXT, | ||
"published" BOOLEAN NOT NULL DEFAULT false, | ||
"authorId" INTEGER NOT NULL, | ||
|
||
CONSTRAINT "Post_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Comment" ( | ||
"id" SERIAL NOT NULL, | ||
"text" TEXT NOT NULL, | ||
"postId" INTEGER NOT NULL, | ||
"authorId" INTEGER NOT NULL, | ||
|
||
CONSTRAINT "Comment_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Post"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
|
||
|
||
|
||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
email String @unique | ||
posts Post[] | ||
comments Comment[] | ||
} | ||
|
||
model Post { | ||
id Int @id @default(autoincrement()) | ||
title String | ||
content String? | ||
published Boolean @default(false) | ||
authorId Int | ||
author User @relation(fields: [authorId], references: [id]) | ||
comments Comment[] | ||
} | ||
|
||
model Comment { | ||
id Int @id @default(autoincrement()) | ||
text String | ||
postId Int | ||
post Post @relation(fields: [postId], references: [id]) | ||
authorId Int | ||
author User @relation(fields: [authorId], references: [id]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Server } from 'http'; | ||
import app from './app'; | ||
import config from './config'; | ||
|
||
|
||
async function bootstrap() { | ||
|
||
const server: Server = app.listen(config.port, () => { | ||
console.log(`Server running on port ${config.port}`); | ||
}); | ||
|
||
const exitHandler = () => { | ||
|
||
if (server) { | ||
server.close(() => { | ||
console.log('Server closed'); | ||
}); | ||
} | ||
process.exit(1); | ||
}; | ||
|
||
const unexpectedErrorHandler = (error: unknown) => { | ||
console.error(error); | ||
exitHandler(); | ||
}; | ||
|
||
process.on('uncaughtException', unexpectedErrorHandler); | ||
process.on('unhandledRejection', unexpectedErrorHandler); | ||
|
||
process.on('SIGTERM', () => { | ||
console.log('SIGTERM received'); | ||
if (server) { | ||
server.close(); | ||
} | ||
}); | ||
} | ||
|
||
bootstrap(); |