A simple web application for managing freelancers, built with Next.js, React, TypeScript, Tailwind CSS, and PostgreSQL.
Light Theme | Dark Theme |
---|---|
- Add new freelancers
- Edit existing freelancers
- Delete freelancers
- View list of freelancers
- Each freelancers should have unique username, mail, and phone number
- Light/Dark theme
- Utilizes Vercel PostgreSQL for data storage
- Next.js
- React
- TypeScript
- Tailwind CSS
- PostgreSQL
- Drizzle Kit
The database model for the user entity is created using Drizzle ORM. It defines the structure of the data stored in the PostgreSQL database. The model includes fields such as id
, name
, mail
, phoneNumber
, skillsets
, and hobby
. This file will be kept under the directory of src/data/db/schemas
.
import { InferType, date, object, string } from "yup";
export const UserSchema = object({
id: string().uuid(),
username: string().required(),
mail: string().email().required(),
phoneNumber: string()
.matches(/^(60|0)(1|11)\d{8}$/g, "Please enter a valid phone number")
.required(),
skillsets: string(),
hobbies: string(),
createdAt: date(),
updatedAt: date()
});
export type User = InferType<typeof UserSchema>;
The form validation model is created using Yup. It defines the validation schema for adding or editing a user. The model ensures that the required fields are present and that the phone number is in a valid format.
import { InferType, date, object, string } from "yup";
export const UserSchema = object({
id: string().uuid(),
username: string().required(),
mail: string().email().required(),
phoneNumber: string()
.matches(/^(60|0)(1|11)\d{8}$/g, "Please enter a valid phone number")
.required(),
skillsets: string(),
hobbies: string(),
createdAt: date(),
updatedAt: date()
});
export type User = InferType<typeof UserSchema>;
The application is deployed on Vercel and is publicly accessible at https://freelancers-management-system.vercel.app/.
To get a local copy up and running follow these simple steps.
- Node.js
- npm
-
Clone the repo
git clone https://github.com/sky3742/freelancers-management-system.git
-
Install NPM packages
npm install
-
Copy the
.env.example
to.env
cp .env.example .env
-
Update the
.env
file with your PostgreSQL connection detailsUpdate the following values in the
.env
file with your PostgreSQL connection details:POSTGRES_DATABASE=your_postgres_database POSTGRES_HOST=your_postgres_host POSTGRES_PASSWORD=your_postgres_password POSTGRES_URL=your_postgres_url POSTGRES_URL_NON_POOLING=your_postgres_url_non_pooling POSTGRES_URL_NO_SSL=your_postgres_url_no_ssl POSTGRES_USER=your_postgres_user
-
Start the development server
npm run dev
-
Open your browser and navigate to
http://localhost:3000
- Click on the "New" button to add a new freelancer.
- Click on the pencil icon to edit a freelancer.
- Click on the trash icon to delete a freelancer.
To migrate your Vercel PostgreSQL database, follow these steps:
-
Generate SQL Migration Files
Run the following command to compare and generate the differences in the model schema into SQL files in the
drizzle
folder:npm run db-generate
-
Run Migration
Once the SQL migration files are generated, run the following command to utilize the built-in
migrate
function fromvercel-postgres/migrator
to migrate the database using the SQL files in thedrizzle
folder:npm run db-migrate
-
Open Database Viewer
To open the database viewer provided by Drizzle Kit, run the following command:
npm run db-studio
-
Verify Migration
After the migration is complete, verify that the migration was successful by checking your database schema and ensuring that your data is intact.
When the Vercel PostgreSQL database is idle, the initial deployment may fail due to connection timeout issues. This is because the database needs to "wake up" from its idle state. Reference
To resolve this issue, you will need to ping the database before the deployment. This will "wake up" the database and ensure that the deployment succeeds.
Sky - [email protected]