Move to zenstack for table inheritance
This commit is contained in:
+112
-9
@@ -1,17 +1,120 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE //
|
||||
// This file is automatically generated by ZenStack CLI and should not be manually updated. //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = env("DATABASE_URL")
|
||||
enum DrinkType {
|
||||
Drink
|
||||
Beer
|
||||
Wine
|
||||
Soda
|
||||
}
|
||||
|
||||
enum ContainerType {
|
||||
BeerBottle
|
||||
WineBottle
|
||||
PlasticBottle
|
||||
Can
|
||||
Carton
|
||||
}
|
||||
|
||||
/// @@delegate(type)
|
||||
/// @@allow('all', true)
|
||||
model Drink {
|
||||
id Int @id() @default(autoincrement())
|
||||
slug String @unique()
|
||||
manufacturer_id Int
|
||||
manufacturer Manufacturer @relation(fields: [manufacturer_id], references: [id])
|
||||
type DrinkType
|
||||
name String @unique()
|
||||
description String
|
||||
abv Float
|
||||
image String?
|
||||
containers Container[]
|
||||
delegate_aux_beer Beer?
|
||||
delegate_aux_wine Wine?
|
||||
delegate_aux_soda Soda?
|
||||
}
|
||||
|
||||
/// @@allow('all', true)
|
||||
/// @@allow('all', true)
|
||||
model Beer {
|
||||
id String @id @default(uuid())
|
||||
name String @unique
|
||||
abv Float
|
||||
}
|
||||
id Int @id()
|
||||
style_id Int
|
||||
style BeerStyle @relation(fields: [style_id], references: [id])
|
||||
ibu Float?
|
||||
delegate_aux_drink Drink @relation(fields: [id], references: [id], onDelete: Cascade, onUpdate: Cascade)
|
||||
}
|
||||
|
||||
/// @@allow('all', true)
|
||||
model BeerStyle {
|
||||
id Int @id() @default(autoincrement())
|
||||
name String @unique()
|
||||
beers Beer[]
|
||||
}
|
||||
|
||||
/// @@allow('all', true)
|
||||
/// @@allow('all', true)
|
||||
model Wine {
|
||||
id Int @id()
|
||||
style_id Int
|
||||
style WineStyle @relation(fields: [style_id], references: [id])
|
||||
heavy_score Int?
|
||||
tannine_score Int?
|
||||
dry_score Int?
|
||||
fresh_score Int?
|
||||
notes String?
|
||||
delegate_aux_drink Drink @relation(fields: [id], references: [id], onDelete: Cascade, onUpdate: Cascade)
|
||||
}
|
||||
|
||||
/// @@allow('all', true)
|
||||
model WineStyle {
|
||||
id Int @id() @default(autoincrement())
|
||||
name String @unique()
|
||||
wines Wine[]
|
||||
}
|
||||
|
||||
/// @@allow('all', true)
|
||||
/// @@allow('all', true)
|
||||
model Soda {
|
||||
id Int @id()
|
||||
carbonated Boolean
|
||||
delegate_aux_drink Drink @relation(fields: [id], references: [id], onDelete: Cascade, onUpdate: Cascade)
|
||||
}
|
||||
|
||||
/// @@allow('all', true)
|
||||
model Container {
|
||||
barcode String @id()
|
||||
drink_id Int
|
||||
drink Drink @relation(fields: [drink_id], references: [id])
|
||||
type ContainerType
|
||||
volume Int
|
||||
portions Int?
|
||||
inventory Int @default(0)
|
||||
}
|
||||
|
||||
/// @@allow('all', true)
|
||||
model Manufacturer {
|
||||
id Int @id() @default(autoincrement())
|
||||
country_id String
|
||||
country Country @relation(fields: [country_id], references: [code])
|
||||
name String @unique()
|
||||
image String?
|
||||
drinks Drink[]
|
||||
}
|
||||
|
||||
/// @@allow('all', true)
|
||||
model Country {
|
||||
code String @id()
|
||||
name String
|
||||
manufacturers Manufacturer[]
|
||||
}
|
||||
|
||||
+143
-12
@@ -1,35 +1,166 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
const db = new PrismaClient();
|
||||
import { ContainerType, PrismaClient } from "@prisma/client";
|
||||
import { enhance } from "@zenstackhq/runtime";
|
||||
import { BeerStyle, Country, Manufacturer } from "@zenstackhq/runtime/models";
|
||||
const pr = new PrismaClient();
|
||||
const db = enhance(pr);
|
||||
|
||||
async function seed() {
|
||||
|
||||
await db.container.deleteMany({});
|
||||
await db.beer.deleteMany({});
|
||||
await db.beerStyle.deleteMany({});
|
||||
await db.manufacturer.deleteMany({});
|
||||
await db.country.deleteMany({});
|
||||
|
||||
await Promise.all(
|
||||
getCountries().map((country) => {
|
||||
return db.country.create({ data: country });
|
||||
})
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
getManufacturers().map((man) => {
|
||||
return db.manufacturer.create({ data: man });
|
||||
})
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
getBeerStyles().map((style) => {
|
||||
return db.beerStyle.create({ data: style });
|
||||
})
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
getBeers().map((beer) => {
|
||||
return db.beer.create({ data: beer });
|
||||
})
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
getContainers().map((container) => {
|
||||
return db.container.create({ data: container });
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
seed();
|
||||
|
||||
function getBeers() {
|
||||
// shout-out to https://icanhazdadjoke.com/
|
||||
interface BeerQuery {
|
||||
slug: string;
|
||||
manufacturer: any;
|
||||
name: string;
|
||||
description: string;
|
||||
abv: number;
|
||||
style: any;
|
||||
ibu: number | null;
|
||||
}
|
||||
|
||||
interface ContainerQuery {
|
||||
barcode: string;
|
||||
drink: any;
|
||||
type: ContainerType;
|
||||
volume: number;
|
||||
portions: number | null;
|
||||
}
|
||||
|
||||
function getCountries() : Country[]{
|
||||
return [
|
||||
{
|
||||
name: "Ginger Paradise",
|
||||
abv: 6.2
|
||||
code: "nl",
|
||||
name: "Netherlands"
|
||||
},
|
||||
{
|
||||
name: "Hertog Jan Pilsener",
|
||||
abv: 5.1
|
||||
code: "de",
|
||||
name: "Germany"
|
||||
},
|
||||
{
|
||||
name: "Hertog Jan Weizener",
|
||||
abv: 5.7
|
||||
code: "be",
|
||||
name: "Belgium"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function getManufacturers() : Manufacturer[] {
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
country_id: "nl",
|
||||
name: "Hertog Jan",
|
||||
image: null
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
country_id: "nl",
|
||||
name: "Heineken",
|
||||
image: null
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
country_id: "nl",
|
||||
name: "Jupiler",
|
||||
image: null
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
country_id: "nl",
|
||||
name: "Brouwerij Het IJ",
|
||||
image: null
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function getBeerStyles() : BeerStyle[] {
|
||||
return [
|
||||
{
|
||||
id: 1,
|
||||
name: "Pilsener",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "Dubbel"
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "Tripel"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function getBeers() : BeerQuery[] {
|
||||
return [
|
||||
{
|
||||
slug: "ginger_paradise",
|
||||
name: "Ginger Paradise",
|
||||
abv: 6.2,
|
||||
ibu: 5,
|
||||
|
||||
manufacturer: {connect: { id: 4}},
|
||||
style: {connect: { id: 3}},
|
||||
|
||||
description: "Some desciption on why this beer is so great and it has this and that flavour",
|
||||
},
|
||||
{
|
||||
slug: "ginger_paradise",
|
||||
name: "Ginger Paradise",
|
||||
abv: 6.2,
|
||||
ibu: 5,
|
||||
|
||||
manufacturer: {connect: { id: 4}},
|
||||
style: {connect: { id: 3}},
|
||||
|
||||
description: "Some desciption on why this beer is so great and it has this and that flavour",
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function getContainers() : ContainerQuery[] {
|
||||
return [
|
||||
{
|
||||
name: "Leffe Blond 0,0%",
|
||||
abv: 0.0
|
||||
barcode: "temporary1",
|
||||
drink: {connect: { slug: "ginger_paradise"}},
|
||||
type: ContainerType.BeerBottle,
|
||||
volume: 330,
|
||||
portions: 1
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user