initial commit - code moved to separate repo

This commit is contained in:
Dobromir Popov
2024-02-22 04:19:38 +02:00
commit 560d503219
240 changed files with 105125 additions and 0 deletions

36
prisma/custom.sql Normal file
View File

@ -0,0 +1,36 @@
-- create cart user with cartpw password and add permissions to cart database. also allow root to connect from any host
CREATE USER 'cart' @'%' IDENTIFIED BY 'cartpw';
GRANT ALL PRIVILEGES ON `cart`.* TO 'cart' @'%';
FLUSH PRIVILEGES;
GRANT CREATE, ALTER, DROP, REFERENCES ON *.* TO 'cart' @'%';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root' @'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
-- fix Access denied for user 'root'@'192.168.48.4' (using password: YES)
--To allow the root user to connect from any host, you need to create a new root user with the host set to '%'. Heres how to do it:
CREATE USER 'root' @'%' IDENTIFIED BY '7isg3FCqP1e9aSFw';
-- Then grant the new user full access to all databases:
GRANT ALL PRIVILEGES ON *.* TO 'root' @'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
-- revoke login from everywhere as ROOT:
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'root' @'%';
FLUSH PRIVILEGES;
--7isg3FCqP1e9aSFw
ALTER USER 'cart' @'%' IDENTIFIED BY 'cartpw2024';
GRANT ALL PRIVILEGES ON `cart`.* TO 'cart' @'%';
FLUSH PRIVILEGES;

View File

@ -0,0 +1,80 @@
-- CreateTable
CREATE TABLE `Publisher` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`firstName` VARCHAR(191) NOT NULL,
`lastName` VARCHAR(191) NOT NULL,
`email` VARCHAR(191) NOT NULL,
`phone` VARCHAR(191) NULL,
`isactive` BOOLEAN NOT NULL DEFAULT true,
`age` INTEGER NULL,
UNIQUE INDEX `Publisher_email_key`(`email`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Availability` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`publisherId` INTEGER NOT NULL,
`name` VARCHAR(191) NOT NULL,
`dayofweek` ENUM('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday') NOT NULL,
`startTime` DATETIME(3) NOT NULL,
`endTime` DATETIME(3) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `CartEvent` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`startTime` DATETIME(3) NOT NULL,
`endTime` DATETIME(3) NOT NULL,
`dayofweek` ENUM('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday') NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Shift` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`cartEventId` INTEGER NOT NULL,
`name` VARCHAR(191) NOT NULL,
`startTime` DATETIME(3) NOT NULL,
`endTime` DATETIME(3) NOT NULL,
`isactive` BOOLEAN NOT NULL DEFAULT true,
`requiresTransport` BOOLEAN NOT NULL DEFAULT false,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Location` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,
`address` VARCHAR(191) NOT NULL,
`isactive` BOOLEAN NOT NULL DEFAULT true,
`dayofweek` ENUM('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday') NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `_PublisherToShift` (
`A` INTEGER NOT NULL,
`B` INTEGER NOT NULL,
UNIQUE INDEX `_PublisherToShift_AB_unique`(`A`, `B`),
INDEX `_PublisherToShift_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `Availability` ADD CONSTRAINT `Availability_publisherId_fkey` FOREIGN KEY (`publisherId`) REFERENCES `Publisher`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Shift` ADD CONSTRAINT `Shift_cartEventId_fkey` FOREIGN KEY (`cartEventId`) REFERENCES `CartEvent`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `_PublisherToShift` ADD CONSTRAINT `_PublisherToShift_A_fkey` FOREIGN KEY (`A`) REFERENCES `Publisher`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `_PublisherToShift` ADD CONSTRAINT `_PublisherToShift_B_fkey` FOREIGN KEY (`B`) REFERENCES `Shift`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,17 @@
/*
Warnings:
- Added the required column `locationId` to the `CartEvent` table without a default value. This is not possible if the table is not empty.
- Added the required column `shiftDuration` to the `CartEvent` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `Availability` ADD COLUMN `isactive` BOOLEAN NOT NULL DEFAULT true;
-- AlterTable
ALTER TABLE `CartEvent` ADD COLUMN `isactive` BOOLEAN NOT NULL DEFAULT true,
ADD COLUMN `locationId` INTEGER NOT NULL,
ADD COLUMN `shiftDuration` INTEGER NOT NULL;
-- AddForeignKey
ALTER TABLE `CartEvent` ADD CONSTRAINT `CartEvent_locationId_fkey` FOREIGN KEY (`locationId`) REFERENCES `Location`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -0,0 +1,12 @@
/*
Warnings:
- You are about to drop the column `dayofweek` on the `Location` table. All the data in the column will be lost.
- Added the required column `date` to the `Shift` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `Location` DROP COLUMN `dayofweek`;
-- AlterTable
ALTER TABLE `Shift` ADD COLUMN `date` DATETIME(3) NOT NULL;

View File

@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `date` on the `Shift` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `Shift` DROP COLUMN `date`;

View File

@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE `CartEvent` ADD COLUMN `eventType` ENUM('PW_Cart', 'KH_Cleaning') NOT NULL DEFAULT 'PW_Cart';
-- AlterTable
ALTER TABLE `Shift` ADD COLUMN `isTentaive` BOOLEAN NOT NULL DEFAULT false;

View File

@ -0,0 +1,30 @@
/*
Warnings:
- You are about to drop the `_PublisherToShift` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE `_PublisherToShift` DROP FOREIGN KEY `_PublisherToShift_A_fkey`;
-- DropForeignKey
ALTER TABLE `_PublisherToShift` DROP FOREIGN KEY `_PublisherToShift_B_fkey`;
-- DropTable
DROP TABLE `_PublisherToShift`;
-- CreateTable
CREATE TABLE `Assignment` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`shiftId` INTEGER NOT NULL,
`publisherId` INTEGER NOT NULL,
`isactive` BOOLEAN NOT NULL DEFAULT true,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `Assignment` ADD CONSTRAINT `Assignment_shiftId_fkey` FOREIGN KEY (`shiftId`) REFERENCES `Shift`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Assignment` ADD CONSTRAINT `Assignment_publisherId_fkey` FOREIGN KEY (`publisherId`) REFERENCES `Publisher`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -0,0 +1,11 @@
/*
Warnings:
- You are about to drop the column `isTentaive` on the `Shift` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `Assignment` ADD COLUMN `isTentaive` BOOLEAN NOT NULL DEFAULT false;
-- AlterTable
ALTER TABLE `Shift` DROP COLUMN `isTentaive`;

View File

@ -0,0 +1,9 @@
/*
Warnings:
- You are about to drop the column `isTentaive` on the `Assignment` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `Assignment` DROP COLUMN `isTentaive`,
ADD COLUMN `isTentative` BOOLEAN NOT NULL DEFAULT false;

View File

@ -0,0 +1,23 @@
-- DropForeignKey
ALTER TABLE `Assignment` DROP FOREIGN KEY `Assignment_publisherId_fkey`;
-- DropForeignKey
ALTER TABLE `Assignment` DROP FOREIGN KEY `Assignment_shiftId_fkey`;
-- DropForeignKey
ALTER TABLE `Availability` DROP FOREIGN KEY `Availability_publisherId_fkey`;
-- DropForeignKey
ALTER TABLE `Shift` DROP FOREIGN KEY `Shift_cartEventId_fkey`;
-- AddForeignKey
ALTER TABLE `Availability` ADD CONSTRAINT `Availability_publisherId_fkey` FOREIGN KEY (`publisherId`) REFERENCES `Publisher`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Shift` ADD CONSTRAINT `Shift_cartEventId_fkey` FOREIGN KEY (`cartEventId`) REFERENCES `CartEvent`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Assignment` ADD CONSTRAINT `Assignment_shiftId_fkey` FOREIGN KEY (`shiftId`) REFERENCES `Shift`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Assignment` ADD CONSTRAINT `Assignment_publisherId_fkey` FOREIGN KEY (`publisherId`) REFERENCES `Publisher`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,75 @@
/*
Warnings:
- The primary key for the `Publisher` table will be changed. If it partially fails, the table could be left without primary key constraint.
*/
-- DropForeignKey
ALTER TABLE `Assignment` DROP FOREIGN KEY `Assignment_publisherId_fkey`;
-- DropForeignKey
ALTER TABLE `Availability` DROP FOREIGN KEY `Availability_publisherId_fkey`;
-- AlterTable
ALTER TABLE `Assignment` MODIFY `publisherId` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `Availability` MODIFY `publisherId` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `Publisher` DROP PRIMARY KEY,
ADD COLUMN `emailVerified` DATETIME(3) NULL,
MODIFY `id` VARCHAR(191) NOT NULL,
ADD PRIMARY KEY (`id`);
-- CreateTable
CREATE TABLE `Account` (
`id` VARCHAR(191) NOT NULL,
`userId` VARCHAR(191) NOT NULL,
`type` VARCHAR(191) NOT NULL,
`provider` VARCHAR(191) NOT NULL,
`providerAccountId` VARCHAR(191) NOT NULL,
`refresh_token` VARCHAR(191) NULL,
`access_token` VARCHAR(191) NULL,
`expires_at` INTEGER NULL,
`token_type` VARCHAR(191) NULL,
`scope` VARCHAR(191) NULL,
`id_token` VARCHAR(191) NULL,
`session_state` VARCHAR(191) NULL,
UNIQUE INDEX `Account_provider_providerAccountId_key`(`provider`, `providerAccountId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Session` (
`id` VARCHAR(191) NOT NULL,
`sessionToken` VARCHAR(191) NOT NULL,
`userId` VARCHAR(191) NOT NULL,
`expires` DATETIME(3) NOT NULL,
UNIQUE INDEX `Session_sessionToken_key`(`sessionToken`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `VerificationToken` (
`identifier` VARCHAR(191) NOT NULL,
`token` VARCHAR(191) NOT NULL,
`expires` DATETIME(3) NOT NULL,
UNIQUE INDEX `VerificationToken_token_key`(`token`),
UNIQUE INDEX `VerificationToken_identifier_token_key`(`identifier`, `token`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `Availability` ADD CONSTRAINT `Availability_publisherId_fkey` FOREIGN KEY (`publisherId`) REFERENCES `Publisher`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Assignment` ADD CONSTRAINT `Assignment_publisherId_fkey` FOREIGN KEY (`publisherId`) REFERENCES `Publisher`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Account` ADD CONSTRAINT `Account_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `Publisher`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Session` ADD CONSTRAINT `Session_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `Publisher`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,8 @@
-- AlterTable
ALTER TABLE `Availability` ADD COLUMN `dayOfMonth` INTEGER NULL;
-- AlterTable
ALTER TABLE `CartEvent` ADD COLUMN `numberOfPublishers` INTEGER NOT NULL DEFAULT 3;
-- AlterTable
ALTER TABLE `Publisher` ADD COLUMN `role` ENUM('ADMIN', 'USER') NOT NULL DEFAULT 'USER';

View File

@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE `Publisher` ADD COLUMN `desiredShiftsPerMonth` INTEGER NOT NULL DEFAULT 4,
MODIFY `role` ENUM('ADMIN', 'USER', 'EXTERNAL') NOT NULL DEFAULT 'USER';

View File

@ -0,0 +1,7 @@
-- AlterTable
ALTER TABLE `Publisher` ADD COLUMN `isMale` BOOLEAN NOT NULL DEFAULT true,
ADD COLUMN `isNameForeign` BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN `parentId` VARCHAR(191) NULL;
-- AddForeignKey
ALTER TABLE `Publisher` ADD CONSTRAINT `Publisher_parentId_fkey` FOREIGN KEY (`parentId`) REFERENCES `Publisher`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `Publisher` ADD COLUMN `isImported` BOOLEAN NOT NULL DEFAULT false;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `Shift` ADD COLUMN `notes` VARCHAR(191) NULL;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `Availability` ADD COLUMN `weekOfMonth` INTEGER NULL;

View File

@ -0,0 +1,18 @@
/*
Warnings:
- You are about to drop the column `parentId` on the `Publisher` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE `Publisher` DROP FOREIGN KEY `Publisher_parentId_fkey`;
-- AlterTable
ALTER TABLE `Assignment` ADD COLUMN `isWithTransport` BOOLEAN NOT NULL DEFAULT false;
-- AlterTable
ALTER TABLE `Publisher` DROP COLUMN `parentId`,
ADD COLUMN `familyHeadId` VARCHAR(191) NULL;
-- AddForeignKey
ALTER TABLE `Publisher` ADD CONSTRAINT `Publisher_familyHeadId_fkey` FOREIGN KEY (`familyHeadId`) REFERENCES `Publisher`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,8 @@
-- AlterTable
ALTER TABLE `Availability` ADD COLUMN `isWithTransport` BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN `type` ENUM('Weekly', 'Monthly', 'OneTime', 'PreviousAssignment') NOT NULL DEFAULT 'Weekly';
-- AlterTable
ALTER TABLE `Publisher` ADD COLUMN `comments` VARCHAR(191) NULL,
ADD COLUMN `town` VARCHAR(191) NULL,
ADD COLUMN `type` ENUM('Publisher', 'Bethelite', 'RegularPioneer', 'SpecialPioneer', 'Missionary', 'CircuitOverseer') NOT NULL DEFAULT 'Publisher';

View File

@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE `Availability` ADD COLUMN `isFromPreviousAssignment` BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN `isFromPreviousMonth` BOOLEAN NOT NULL DEFAULT false;

View File

@ -0,0 +1,42 @@
/*
Warnings:
- You are about to drop the column `emailVerified` on the `Publisher` table. All the data in the column will be lost.
- A unique constraint covering the columns `[userId]` on the table `Publisher` will be added. If there are existing duplicate values, this will fail.
*/
-- DropForeignKey
ALTER TABLE `Account` DROP FOREIGN KEY `Account_userId_fkey`;
-- DropForeignKey
ALTER TABLE `Session` DROP FOREIGN KEY `Session_userId_fkey`;
-- AlterTable
ALTER TABLE `Publisher` DROP COLUMN `emailVerified`,
ADD COLUMN `userId` VARCHAR(191) NULL;
-- CreateTable
CREATE TABLE `User` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NULL,
`email` VARCHAR(191) NULL,
`emailVerified` DATETIME(3) NULL,
`image` VARCHAR(191) NULL,
`publisherId` VARCHAR(191) NULL,
UNIQUE INDEX `User_email_key`(`email`),
UNIQUE INDEX `User_publisherId_key`(`publisherId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE UNIQUE INDEX `Publisher_userId_key` ON `Publisher`(`userId`);
-- AddForeignKey
ALTER TABLE `Publisher` ADD CONSTRAINT `Publisher_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Account` ADD CONSTRAINT `Account_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Session` ADD CONSTRAINT `Session_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,2 @@
-- This is an empty migration.
-- CREATE INDEX `Publisher_email_key` ON `Publisher` (email);

View File

@ -0,0 +1,23 @@
-- AlterTable
ALTER TABLE `Publisher` MODIFY `role` ENUM('ADMIN', 'POWERUSER', 'USER', 'EXTERNAL') NOT NULL DEFAULT 'USER';
-- CreateTable
CREATE TABLE `Report` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`date` DATETIME(3) NOT NULL,
`publisherId` VARCHAR(191) NOT NULL,
`assignmentId` INTEGER NOT NULL,
`placementCount` INTEGER NOT NULL,
`videoCount` INTEGER NOT NULL,
`returnVisitInfoCount` INTEGER NOT NULL,
`conversationCount` INTEGER NOT NULL,
`experienceInfo` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `Report` ADD CONSTRAINT `Report_publisherId_fkey` FOREIGN KEY (`publisherId`) REFERENCES `Publisher`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Report` ADD CONSTRAINT `Report_assignmentId_fkey` FOREIGN KEY (`assignmentId`) REFERENCES `Assignment`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -0,0 +1,23 @@
/*
Warnings:
- Added the required column `locationId` to the `Report` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE `Report` DROP FOREIGN KEY `Report_assignmentId_fkey`;
-- AlterTable
ALTER TABLE `Report` ADD COLUMN `locationId` INTEGER NOT NULL,
MODIFY `assignmentId` INTEGER NULL,
MODIFY `placementCount` INTEGER NULL,
MODIFY `videoCount` INTEGER NULL,
MODIFY `returnVisitInfoCount` INTEGER NULL,
MODIFY `conversationCount` INTEGER NULL,
MODIFY `experienceInfo` VARCHAR(191) NULL;
-- AddForeignKey
ALTER TABLE `Report` ADD CONSTRAINT `Report_locationId_fkey` FOREIGN KEY (`locationId`) REFERENCES `Location`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Report` ADD CONSTRAINT `Report_assignmentId_fkey` FOREIGN KEY (`assignmentId`) REFERENCES `Assignment`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `Report` MODIFY `experienceInfo` LONGTEXT NULL;

View File

@ -0,0 +1,8 @@
-- DropForeignKey
ALTER TABLE `Report` DROP FOREIGN KEY `Report_locationId_fkey`;
-- AlterTable
ALTER TABLE `Report` MODIFY `locationId` INTEGER NULL;
-- AddForeignKey
ALTER TABLE `Report` ADD CONSTRAINT `Report_locationId_fkey` FOREIGN KEY (`locationId`) REFERENCES `Location`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE `Availability` ADD COLUMN `endDate` DATETIME(3) NULL,
ADD COLUMN `repeatWeekly` BOOLEAN NULL;

View File

@ -0,0 +1,32 @@
/*
Warnings:
- You are about to drop the column `isTentative` on the `assignment` table. All the data in the column will be lost.
- You are about to drop the column `assignmentId` on the `report` table. All the data in the column will be lost.
- A unique constraint covering the columns `[publicGuid]` on the table `Assignment` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[reportId]` on the table `Shift` will be added. If there are existing duplicate values, this will fail.
*/
-- DropForeignKey
ALTER TABLE `Report` DROP FOREIGN KEY `Report_assignmentId_fkey`;
-- AlterTable
ALTER TABLE `Assignment` DROP COLUMN `isTentative`,
ADD COLUMN `isConfirmed` BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN `isMailSent` BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN `publicGuid` VARCHAR(191) NULL;
-- AlterTable
ALTER TABLE `Report` DROP COLUMN `assignmentId`;
-- AlterTable
ALTER TABLE `Shift` ADD COLUMN `reportId` INTEGER NULL;
-- CreateIndex
CREATE UNIQUE INDEX `Assignment_publicGuid_key` ON `Assignment`(`publicGuid`);
-- CreateIndex
CREATE UNIQUE INDEX `Shift_reportId_key` ON `Shift`(`reportId`);
-- AddForeignKey
ALTER TABLE `Shift` ADD CONSTRAINT `Shift_reportId_fkey` FOREIGN KEY (`reportId`) REFERENCES `Report`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,9 @@
-- AlterTable
ALTER TABLE `Location` ADD COLUMN `backupLocationId` INTEGER NULL,
ADD COLUMN `content` TEXT NULL;
-- AlterTable
ALTER TABLE `Publisher` ADD COLUMN `isTrained` BOOLEAN NOT NULL DEFAULT false;
-- AddForeignKey
ALTER TABLE `Location` ADD CONSTRAINT `Location_backupLocationId_fkey` FOREIGN KEY (`backupLocationId`) REFERENCES `Location`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -0,0 +1,12 @@
/*
Warnings:
- You are about to drop the column `isactive` on the `assignment` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `Assignment` DROP COLUMN `isactive`,
ADD COLUMN `isTentative` BOOLEAN NOT NULL DEFAULT false;
-- AlterTable
ALTER TABLE `Location` MODIFY `content` LONGTEXT NULL;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `Availability` ADD COLUMN `repeatFrequency` INTEGER NULL;

View File

@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE `Location` ADD COLUMN `picture1` VARCHAR(191) NULL,
ADD COLUMN `picture2` VARCHAR(191) NULL,
ADD COLUMN `picture3` VARCHAR(191) NULL;

View File

@ -0,0 +1,15 @@
/*
Warnings:
- You are about to drop the column `isWithTransport` on the `Availability` table. All the data in the column will be lost.
- The values [SpecialPioneer,Missionary,CircuitOverseer] on the enum `Publisher_type` will be removed. If these variants are still used in the database, this will fail.
*/
-- AlterTable
ALTER TABLE `Availability` DROP COLUMN `isWithTransport`,
ADD COLUMN `isWithTransportIn` BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN `isWithTransportOut` BOOLEAN NOT NULL DEFAULT false,
MODIFY `type` ENUM('Weekly', 'Monthly', 'OneTime', 'PreviousAssignment', 'ReplacementOnly') NOT NULL DEFAULT 'Weekly';
-- AlterTable
ALTER TABLE `Publisher` MODIFY `type` ENUM('Publisher', 'Bethelite', 'RegularPioneer', 'SpecialPioneer_Missionary') NOT NULL DEFAULT 'Publisher';

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 = "mysql"

275
prisma/schema.prisma Normal file
View File

@ -0,0 +1,275 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// // https://dev.to/connelevalsam/a-simple-crud-app-with-nextjs-prisma-sqlite-and-flutter-3oe1
// > npx prisma
// // to update prisma DB/generate migration
// >npx prisma migrate dev
// //to generate schema
// > npx prisma
// GPT
// This is a Prisma database schema definition, which describes the structure and relationships between various entities in the database. Here's a brief overview of the different models:
// Publisher: Represents a publisher, with attributes such as first name, last name, email, phone, age, and availability. A publisher can have many availabilities and assignments, and can also have multiple user accounts and sessions.
// Availability: Represents the availability of a publisher on a specific day and time range. An availability belongs to a publisher and can have a name, day of the week, day of the month, start time, and end time.
// CartEvent: Represents a cart event, which is an event that requires a certain number of publishers to work. A cart event has a start and end time, a duration, and can have multiple shifts. It also has a location and an event type.
// Shift: Represents a shift, which is a specific time period during a cart event where one or more publishers are required to work. A shift belongs to a cart event and can have a name, start and end time, and can require transport.
// Assignment: Represents an assignment of a publisher to a specific shift. An assignment belongs to a shift and a publisher and can be tentative or final.
// Location: Represents a location where a cart event can take place. A location can have a name, address, and multiple cart events.
// Overall, this schema seems to represent a system for managing publishers and their assignments to cart events, including their availabilities and locations.
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-3.0.x"]
}
// graphql schema generator
// https://github.com/prisma-korea/graphql-schema-generator
// generator graphql {
// provider = "graphql-schema-generator"
// createCRUD = "true"
// // # output = "./generated" This is default path.
// }
enum UserRole {
ADMIN
POWERUSER
USER
EXTERNAL
}
enum EventType {
PW_Cart
KH_Cleaning
}
//prisma type for day of week for sqlite db
enum DayOfWeek {
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
}
enum AvailabilityType {
Weekly
Monthly
OneTime
PreviousAssignment
ReplacementOnly
}
// Вестител
// Бетелит
// Редовен Пионер
// Специален Пионер/Мисионер
enum PublisherType {
Publisher
Bethelite
RegularPioneer
SpecialPioneer_Missionary
}
model Publisher {
id String @id @default(cuid())
firstName String
lastName String
email String @unique
phone String?
isactive Boolean @default(true)
isImported Boolean @default(false)
isTrained Boolean @default(false)
age Int?
availabilities Availability[]
assignments Assignment[]
// Optional relation to User
userId String? @unique
user User? @relation(fields: [userId], references: [id])
role UserRole @default(USER)
desiredShiftsPerMonth Int @default(4)
isMale Boolean @default(true)
isNameForeign Boolean @default(false)
familyHeadId String? // Optional familyHeadId for each family member
familyHead Publisher? @relation("FamilyMember", fields: [familyHeadId], references: [id])
familyMembers Publisher[] @relation("FamilyMember")
type PublisherType @default(Publisher)
town String?
comments String?
reports Report[]
@@map("Publisher")
}
model Availability {
id Int @id @default(autoincrement())
publisher Publisher @relation(fields: [publisherId], references: [id], onDelete: Cascade)
publisherId String
name String
dayofweek DayOfWeek
dayOfMonth Int?
weekOfMonth Int?
startTime DateTime
endTime DateTime
isactive Boolean @default(true)
type AvailabilityType @default(Weekly)
isWithTransportIn Boolean @default(false)
isWithTransportOut Boolean @default(false)
isFromPreviousAssignment Boolean @default(false)
isFromPreviousMonth Boolean @default(false)
repeatWeekly Boolean? // New field to indicate weekly repetition
repeatFrequency Int? // New field to indicate repetition frequency
endDate DateTime? // New field for the end date of repetition
@@map("Availability")
}
model CartEvent {
id Int @id @default(autoincrement())
startTime DateTime
endTime DateTime
shiftDuration Int
shifts Shift[]
dayofweek DayOfWeek
isactive Boolean @default(true)
location Location @relation(fields: [locationId], references: [id])
locationId Int
eventType EventType @default(PW_Cart)
numberOfPublishers Int @default(3)
@@map("CartEvent")
}
model Shift {
id Int @id @default(autoincrement())
cartEvent CartEvent @relation(fields: [cartEventId], references: [id], onDelete: Cascade)
cartEventId Int
assignments Assignment[]
name String
startTime DateTime
endTime DateTime
isactive Boolean @default(true)
requiresTransport Boolean @default(false)
notes String?
//date DateTime
reportId Int? @unique
Report Report? @relation(fields: [reportId], references: [id])
@@map("Shift")
}
model Assignment {
id Int @id @default(autoincrement())
shift Shift @relation(fields: [shiftId], references: [id], onDelete: Cascade)
shiftId Int
publisher Publisher @relation(fields: [publisherId], references: [id], onDelete: Cascade)
publisherId String
isTentative Boolean @default(false) // if no availability for it, when importing previous schedules
isConfirmed Boolean @default(false)
isWithTransport Boolean @default(false)
isMailSent Boolean @default(false)
publicGuid String? @unique
@@map("Assignment")
}
model Location {
id Int @id @default(autoincrement())
name String
address String
isactive Boolean @default(true)
content String? @db.LongText
cartEvents CartEvent[]
reports Report[]
picture1 String?
picture2 String?
picture3 String?
backupLocationId Int?
backupLocation Location? @relation("BackupLocation", fields: [backupLocationId], references: [id])
BackupForLocations Location[] @relation("BackupLocation")
@@map("Location")
}
model Report {
id Int @id @default(autoincrement())
date DateTime
publisherId String
publisher Publisher @relation(fields: [publisherId], references: [id], onDelete: Cascade)
locationId Int?
location Location? @relation(fields: [locationId], references: [id])
shift Shift?
placementCount Int?
videoCount Int?
returnVisitInfoCount Int?
conversationCount Int?
experienceInfo String? @db.LongText
@@map("Report")
}
//user auth and session management
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
// Optional relation to Publisher
publisherId String? @unique
publisher Publisher? @relation
}
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String?
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}

157
prisma/seed.sql Normal file
View File

@ -0,0 +1,157 @@
-- --------------------------------------------------------
-- Хост: 127.0.0.1
-- Версия на сървъра: 11.4.0-MariaDB - mariadb.org binary distribution
-- ОС на сървъра: Win64
-- HeidiSQL Версия: 12.3.0.6589
-- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */
;
/*!40101 SET NAMES utf8 */
;
/*!50503 SET NAMES utf8mb4 */
;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */
;
/*!40103 SET TIME_ZONE='+00:00' */
;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */
;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */
;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */
;
-- Дъмп данни за таблица cart.location: ~0 rows (приблизително)
DELETE FROM `Location`;
INSERT INTO
`Location` (
`id`,
`name`,
`address`,
`isactive`
)
VALUES (
1,
'Стадион Васил Левски',
'',
1
), (
2,
'Софийски Университет',
'',
1
), (3, 'Сердика', '', 1),
(4, 'Лъвов Мост', '', 1),
(5, 'ц.ж.п. Гара', '', 1),
(6, 'НДК', '', 1),
(7, 'Паметник Патриарх Евтимий', '', 1);
-- Дъмп данни за таблица cart.cartevent: ~1 rows (приблизително)
DELETE FROM `CartEvent`;
INSERT INTO
`CartEvent` (
`id`,
`startTime`,
`endTime`,
`dayofweek`,
`isactive`,
`locationId`,
`shiftDuration`,
`eventType`,
`numberOfPublishers`
)
VALUES (
1,
'2023-12-27 07:00:33.174',
'2023-12-27 16:00:33.174',
'Monday',
1,
1,
90,
'PW_Cart',
4
), (
2,
'2023-12-27 07:00:33.174',
'2023-12-27 16:00:33.174',
'Tuesday',
1,
2,
90,
'PW_Cart',
4
), (
3,
'2023-12-28 07:00:33.174',
'2023-12-28 16:00:33.174',
'Wednesday',
1,
3,
90,
'PW_Cart',
4
), (
4,
'2023-12-29 07:00:33.174',
'2023-12-29 16:00:33.174',
'Thursday',
1,
4,
90,
'PW_Cart',
4
), (
5,
'2023-12-30 07:00:33.174',
'2023-12-30 16:00:33.174',
'Friday',
0,
5,
90,
'PW_Cart',
4
), (
6,
'2023-12-27 10:00:49.048',
'2023-12-27 16:00:49.048',
'Saturday',
1,
6,
90,
'PW_Cart',
4
),
(
7,
'2023-12-30 07:00:33.174',
'2023-12-30 16:00:33.174',
'Friday',
1,
7,
90,
'PW_Cart',
4
);
/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */
;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */
;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */
;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */
;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */
;
-- INSERT INTO `cartevent` (`id`, `startTime`, `endTime`, `dayofweek`, `isactive`, `locationId`, `shiftDuration`, `eventType`, `numberOfPublishers`)
-- VALUES
-- (2, '2023-12-27 07:00:33.174', '2023-12-27 16:00:33.174', 'Tuesday', 1, 2, 90, 'PW_Cart', 4),
-- (3, '2023-12-28 07:00:33.174', '2023-12-28 16:00:33.174', 'Wednesday', 1, 3, 90, 'PW_Cart', 4),
-- (4, '2023-12-29 07:00:33.174', '2023-12-29 16:00:33.174', 'Thursday', 1, 4, 90, 'PW_Cart', 4),
-- (5, '2023-12-30 07:00:33.174', '2023-12-30 16:00:33.174', 'Friday', 1, 5, 90, 'PW_Cart', 4),
-- (6, '2023-12-31 07:00:33.174', '2023-12-31 16:00:33.174', 'Saturday', 1, 6, 90, 'PW_Cart', 4),
-- (7, '2024-01-01 07:00:33.174', '2024-01-01 16:00:33.174', 'Sunday', 1, 7, 90, 'PW_Cart', 4)