start migrationg to prisma-orm

This commit is contained in:
Rdeisenroth 2025-11-06 22:53:08 +01:00
parent 9a8d7a36b9
commit ae2cd5e61f
No known key found for this signature in database
GPG key ID: 197008FA42DE7127
18 changed files with 374 additions and 200 deletions

View file

@ -0,0 +1,29 @@
-- CreateTable
CREATE TABLE "users" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"email" TEXT NOT NULL,
"password" TEXT NOT NULL
);
-- CreateTable
CREATE TABLE "jobs" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"user_id" INTEGER NOT NULL,
"date_created" DATETIME NOT NULL,
"status" TEXT NOT NULL DEFAULT 'not started',
"num_files" INTEGER NOT NULL DEFAULT 0,
CONSTRAINT "jobs_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "file_names" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"job_id" INTEGER NOT NULL,
"file_name" TEXT NOT NULL,
"output_file_name" TEXT NOT NULL,
"status" TEXT NOT NULL DEFAULT 'not started',
CONSTRAINT "file_names_job_id_fkey" FOREIGN KEY ("job_id") REFERENCES "jobs" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");

View file

@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "sqlite"

65
prisma/schema.prisma Normal file
View file

@ -0,0 +1,65 @@
// 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 = "sqlite"
url = "file:../data/mydb.sqlite"
}
/// A user of the application
model User {
/// The unique identifier for the user
id Int @id @default(autoincrement())
/// The email address of the user
email String @unique
/// The password of the user
password String
/// The jobs associated with the user
jobs Job[]
@@map("users")
}
/// A job created by a user
model Job {
/// The unique identifier for the job
id Int @id @default(autoincrement())
/// The ID of the user who created the job
userId Int @map("user_id")
/// The date and time when the job was created
dateCreated DateTime @map("date_created")
/// The current status of the job
status String @default("not started")
/// The number of files associated with the job
numFiles Int @default(0) @map("num_files")
/// The files associated with the job
files FileName[]
/// The user who created the job
user User @relation(fields: [userId], references: [id])
@@map("jobs")
}
/// A file associated with a job
model FileName {
/// The unique identifier for the file
id Int @id @default(autoincrement())
/// The ID of the job this file belongs to
jobId Int @map("job_id")
/// The name of the input file
fileName String @map("file_name")
/// The name of the output file
outputFileName String @map("output_file_name")
/// The current status of the file
status String @default("not started")
/// The job this file belongs to
job Job @relation(fields: [jobId], references: [id])
@@map("file_names")
}