Initial commit: LACA parking management system

This commit is contained in:
2025-08-13 10:05:36 +07:00
commit 8b07467b61
275 changed files with 66828 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
-- CreateEnum
CREATE TYPE "Language" AS ENUM ('vi', 'en');
-- CreateEnum
CREATE TYPE "Gender" AS ENUM ('Male', 'Female', 'LGBT');
-- CreateEnum
CREATE TYPE "BookingStatus" AS ENUM ('done', 'pending', 'reject', 'cancel');
-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"email" TEXT NOT NULL,
"phone" TEXT,
"username" TEXT,
"fullname" TEXT,
"dob" TIMESTAMP(3),
"gender" "Gender" NOT NULL DEFAULT 'Female',
"language" "Language" NOT NULL DEFAULT 'vi',
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(3) NOT NULL,
"deleted_at" TIMESTAMPTZ(3),
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Booking" (
"id" SERIAL NOT NULL,
"path" TEXT,
"image" TEXT,
"public" BOOLEAN NOT NULL DEFAULT true,
"user_id" INTEGER NOT NULL,
"status" "BookingStatus" NOT NULL DEFAULT 'pending',
"slot_id" INTEGER NOT NULL,
"start_at" TIMESTAMPTZ(3) NOT NULL,
"end_at" TIMESTAMPTZ(3),
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(3) NOT NULL,
"deleted_at" TIMESTAMPTZ(3),
CONSTRAINT "Booking_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Slot" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"lat" DOUBLE PRECISION NOT NULL,
"lng" DOUBLE PRECISION NOT NULL,
"address" TEXT NOT NULL,
"district" TEXT NOT NULL,
"ward" TEXT NOT NULL,
"city" TEXT NOT NULL,
"destination" TEXT,
"total" INTEGER NOT NULL,
"empty" INTEGER NOT NULL,
"published" BOOLEAN NOT NULL DEFAULT false,
"tenantId" INTEGER NOT NULL,
"distance" DOUBLE PRECISION NOT NULL,
"duration" DOUBLE PRECISION NOT NULL,
"directions" JSONB NOT NULL,
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(3) NOT NULL,
"deleted_at" TIMESTAMPTZ(3),
CONSTRAINT "Slot_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Admin" (
"id" SERIAL NOT NULL,
"username" TEXT NOT NULL,
"password" TEXT NOT NULL,
"password_confirmation" TEXT NOT NULL,
"street" TEXT,
"city" TEXT,
"province" TEXT,
"first_name" TEXT NOT NULL,
"last_name" TEXT NOT NULL,
"phone" TEXT NOT NULL,
"dob" TIMESTAMP(3),
"language" "Language" NOT NULL DEFAULT 'vi',
"last_login_at" TIMESTAMP(3),
"current_login_at" TIMESTAMP(3),
"last_login_failed_at" TIMESTAMP(3),
"consecutive_login_penalty" INTEGER NOT NULL DEFAULT 0,
"avatarUrl" TEXT,
"active" BOOLEAN NOT NULL DEFAULT true,
"last_lockout_at" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Admin_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Tenant" (
"id" SERIAL NOT NULL,
"email" TEXT,
"username" TEXT NOT NULL,
"password" TEXT NOT NULL,
"password_confirmation" TEXT,
"street" TEXT,
"city" TEXT,
"province" TEXT,
"postal_code" TEXT,
"first_name" TEXT NOT NULL,
"last_name" TEXT NOT NULL,
"phone" TEXT NOT NULL,
"language" "Language" NOT NULL DEFAULT 'vi',
"last_login_at" TIMESTAMP(3),
"current_login_at" TIMESTAMP(3),
"last_login_failed_at" TIMESTAMP(3),
"consecutive_login_penalty" INTEGER NOT NULL DEFAULT 0,
"avatarUrl" TEXT,
"active" BOOLEAN NOT NULL DEFAULT true,
"last_lockout_at" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Tenant_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "History" (
"id" SERIAL NOT NULL,
CONSTRAINT "History_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
-- CreateIndex
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
-- CreateIndex
CREATE INDEX "User_id_email_idx" ON "User"("id", "email");
-- CreateIndex
CREATE INDEX "Booking_user_id_id_idx" ON "Booking"("user_id", "id");
-- CreateIndex
CREATE INDEX "Slot_id_idx" ON "Slot"("id");
-- CreateIndex
CREATE UNIQUE INDEX "Admin_username_key" ON "Admin"("username");
-- CreateIndex
CREATE UNIQUE INDEX "Tenant_email_key" ON "Tenant"("email");
-- CreateIndex
CREATE UNIQUE INDEX "Tenant_username_key" ON "Tenant"("username");
-- AddForeignKey
ALTER TABLE "Booking" ADD CONSTRAINT "Booking_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Booking" ADD CONSTRAINT "Booking_slot_id_fkey" FOREIGN KEY ("slot_id") REFERENCES "Slot"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Slot" ADD CONSTRAINT "Slot_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -0,0 +1,10 @@
-- AlterTable
ALTER TABLE "Admin" ALTER COLUMN "password_confirmation" DROP NOT NULL;
-- AlterTable
ALTER TABLE "Slot" ALTER COLUMN "distance" DROP NOT NULL,
ALTER COLUMN "duration" DROP NOT NULL,
ALTER COLUMN "directions" DROP NOT NULL;
-- AlterTable
ALTER TABLE "User" ADD COLUMN "password" TEXT;

View File

@@ -0,0 +1,17 @@
/*
Warnings:
- Added the required column `contact` to the `Booking` table without a default value. This is not possible if the table is not empty.
- Added the required column `license_plates` to the `Booking` table without a default value. This is not possible if the table is not empty.
- Added the required column `owner` to the `Booking` table without a default value. This is not possible if the table is not empty.
- Made the column `end_at` on table `Booking` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterEnum
ALTER TYPE "BookingStatus" ADD VALUE 'out';
-- AlterTable
ALTER TABLE "Booking" ADD COLUMN "contact" TEXT NOT NULL,
ADD COLUMN "license_plates" TEXT NOT NULL,
ADD COLUMN "owner" TEXT NOT NULL,
ALTER COLUMN "end_at" SET NOT NULL;

View File

@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Booking" ADD COLUMN "pricing" INTEGER;
-- AlterTable
ALTER TABLE "Slot" ADD COLUMN "pricing_per_hour" INTEGER NOT NULL DEFAULT 0;

View File

@@ -0,0 +1,13 @@
-- CreateEnum
CREATE TYPE "SlotType" AS ENUM ('Car', 'Mortorbike');
-- CreateEnum
CREATE TYPE "BookingType" AS ENUM ('fulltime', 'parttime', 'all');
-- AlterTable
ALTER TABLE "Booking" ADD COLUMN "alow_booking_type" "BookingType" DEFAULT 'all',
ADD COLUMN "slot_type" "SlotType" DEFAULT 'Car';
-- AlterTable
ALTER TABLE "Slot" ADD COLUMN "booking_type" "BookingType" DEFAULT 'all',
ADD COLUMN "image" TEXT;

View File

@@ -0,0 +1,20 @@
/*
Warnings:
- You are about to drop the column `alow_booking_type` on the `Booking` table. All the data in the column will be lost.
- You are about to drop the column `slot_type` on the `Booking` table. All the data in the column will be lost.
- You are about to drop the column `booking_type` on the `Slot` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Booking" DROP COLUMN "alow_booking_type",
DROP COLUMN "slot_type";
-- AlterTable
ALTER TABLE "Slot" DROP COLUMN "booking_type";
-- DropEnum
DROP TYPE "BookingType";
-- DropEnum
DROP TYPE "SlotType";

View File

@@ -0,0 +1,13 @@
-- CreateEnum
CREATE TYPE "SlotType" AS ENUM ('Car', 'Mortorbike', 'Orther');
-- CreateEnum
CREATE TYPE "BookingType" AS ENUM ('Fulltime', 'Parttime', 'All');
-- AlterTable
ALTER TABLE "Booking" ADD COLUMN "booking_type" "BookingType" DEFAULT 'All',
ADD COLUMN "slot_type" "SlotType" DEFAULT 'Car';
-- AlterTable
ALTER TABLE "Slot" ADD COLUMN "alow_booking_type" "BookingType" DEFAULT 'All',
ADD COLUMN "slot_type" "SlotType" DEFAULT 'Car';

View File

@@ -0,0 +1,26 @@
/*
Warnings:
- You are about to drop the column `image` on the `Slot` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Slot" DROP COLUMN "image",
ADD COLUMN "close" VARCHAR,
ADD COLUMN "images" TEXT[] DEFAULT ARRAY[]::TEXT[],
ADD COLUMN "open" VARCHAR;
-- CreateTable
CREATE TABLE "File" (
"id" SERIAL NOT NULL,
"path" TEXT NOT NULL,
"slot_id" INTEGER,
"user_id" INTEGER,
"size" INTEGER NOT NULL,
"mine_type" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"deletedAt" TIMESTAMP(3),
CONSTRAINT "File_pkey" PRIMARY KEY ("id")
);

View File

@@ -0,0 +1,21 @@
/*
Warnings:
- You are about to alter the column `close` on the `Slot` table. The data in that column could be lost. The data in that column will be cast from `VarChar` to `VarChar(1)`.
- You are about to alter the column `open` on the `Slot` table. The data in that column could be lost. The data in that column will be cast from `VarChar` to `VarChar(1)`.
*/
-- DropForeignKey
ALTER TABLE "Slot" DROP CONSTRAINT "Slot_tenantId_fkey";
-- AlterTable
ALTER TABLE "Slot" ADD COLUMN "userId" INTEGER,
ALTER COLUMN "tenantId" DROP NOT NULL,
ALTER COLUMN "close" SET DATA TYPE VARCHAR(5),
ALTER COLUMN "open" SET DATA TYPE VARCHAR(5);
-- AddForeignKey
ALTER TABLE "Slot" ADD CONSTRAINT "Slot_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Slot" ADD CONSTRAINT "Slot_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@@ -0,0 +1,34 @@
-- CreateTable
CREATE TABLE "Comment" (
"id" SERIAL NOT NULL,
"slot_id" INTEGER NOT NULL,
"content" TEXT,
"tenantId" INTEGER,
"userId" INTEGER,
CONSTRAINT "Comment_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Like" (
"id" SERIAL NOT NULL,
"commentId" INTEGER NOT NULL,
"userId" INTEGER,
CONSTRAINT "Like_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_slot_id_fkey" FOREIGN KEY ("slot_id") REFERENCES "Slot"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Like" ADD CONSTRAINT "Like_commentId_fkey" FOREIGN KEY ("commentId") REFERENCES "Comment"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Like" ADD CONSTRAINT "Like_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@@ -0,0 +1,16 @@
-- CreateTable
CREATE TABLE "Vote" (
"id" SERIAL NOT NULL,
"commentId" INTEGER NOT NULL,
"userId" INTEGER,
"source" INTEGER NOT NULL DEFAULT 0,
"type" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "Vote_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_commentId_fkey" FOREIGN KEY ("commentId") REFERENCES "Comment"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@@ -0,0 +1,19 @@
/*
Warnings:
- You are about to drop the column `commentId` on the `Vote` table. All the data in the column will be lost.
- Added the required column `slot_id` to the `Vote` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "Vote" DROP CONSTRAINT "Vote_commentId_fkey";
-- AlterTable
ALTER TABLE "User" ALTER COLUMN "email" DROP NOT NULL;
-- AlterTable
ALTER TABLE "Vote" DROP COLUMN "commentId",
ADD COLUMN "slot_id" INTEGER NOT NULL;
-- AddForeignKey
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_slot_id_fkey" FOREIGN KEY ("slot_id") REFERENCES "Slot"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -0,0 +1 @@
CREATE EXTENSION IF NOT EXISTS unaccent;

View File

@@ -0,0 +1,12 @@
/*
Warnings:
- A unique constraint covering the columns `[lat,lng]` on the table `Slot` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[phone]` on the table `User` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "Slot" ADD COLUMN "phone" TEXT;
-- CreateIndex
CREATE UNIQUE INDEX "User_phone_key" ON "User"("phone");

View File

@@ -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"