add prisma ORM with initial tables

Signed-off-by: Frieder Schlesier <frieder@fschl.de>
This commit is contained in:
Frieder Schlesier 2023-02-12 13:54:48 +01:00
parent a28803d2e3
commit 24cdde85d8
6 changed files with 90 additions and 0 deletions

7
.env Normal file
View File

@ -0,0 +1,7 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="file:./dev-test.db"

4
.gitignore vendored
View File

@ -1,3 +1,7 @@
# database
*.db
*.db-journal
# Logs
logs
*.log

View File

@ -0,0 +1,23 @@
-- CreateTable
CREATE TABLE "Event" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"titleFormatted" TEXT NOT NULL,
"locationFormatted" TEXT NOT NULL,
"descriptionDescriptionFormatted" TEXT NOT NULL,
"dateTime" TEXT NOT NULL,
"endDateTime" TEXT NOT NULL,
"isOfficial" BOOLEAN NOT NULL,
"videoUrl" TEXT NOT NULL,
"group" INTEGER NOT NULL,
"createdBy" INTEGER NOT NULL
);
-- CreateTable
CREATE TABLE "EventState" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"publishYoutube" BOOLEAN NOT NULL,
"publishFacebook" BOOLEAN NOT NULL,
"publishInstagram" BOOLEAN NOT NULL,
"eventId" INTEGER NOT NULL,
CONSTRAINT "EventState_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

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

36
prisma/schema.prisma Normal file
View File

@ -0,0 +1,36 @@
// 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 = env("DATABASE_URL")
}
model Event {
id Int @id
titleFormatted String
locationFormatted String
descriptionDescriptionFormatted String
dateTime String
endDateTime String
isOfficial Boolean
videoUrl String
group Int
createdBy Int
EventState EventState[]
}
// pub time, url/id
// TODO: add publish dates, store links
model EventState {
id Int @id @default(autoincrement())
event Event @relation(fields: [eventId], references: [id])
publishYoutube Boolean
publishFacebook Boolean
publishInstagram Boolean
eventId Int
}

17
src/db.ts Normal file
View File

@ -0,0 +1,17 @@
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
async function main() {
// ... you will write your Prisma Client queries here
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})