-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description Added SQLite database and schema + seeding with prisma. ## Type of change Please delete options that are not relevant. - [ ] New feature (non-breaking change which adds functionality) # Checklist: - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix or my feature works - [ ] New and existing tests pass locally with my changes - [ ] My changes contain no console logs
- Loading branch information
1 parent
a3f4d47
commit 7530194
Showing
16 changed files
with
915 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ cypress-artifacts | |
.env | ||
/cypress/videos/ | ||
/cypress/screenshots/ | ||
/prisma/mnestix-database.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- CreateTable | ||
CREATE TABLE "ConnectionType" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"typeName" TEXT NOT NULL | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "MnestixConnection" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"url" TEXT NOT NULL, | ||
"typeId" TEXT NOT NULL, | ||
CONSTRAINT "MnestixConnection_typeId_fkey" FOREIGN KEY ("typeId") REFERENCES "ConnectionType" ("id") ON DELETE RESTRICT ON UPDATE CASCADE | ||
); | ||
|
||
--- CHANGED MANUALLY --- | ||
-- Insert ConnectionType Enum values as SQLite does not support Enums | ||
-- Create a new migration if you need to expand this Enum! | ||
INSERT INTO "ConnectionType" (id, typeName) | ||
VALUES (0, 'AAS_REPOSITORY'), | ||
(1, 'AAS_REGISTRY'), | ||
(2, 'SUBMODEL_REPOSITORY'), | ||
(3, 'SUBMODEL_REGISTRY'), | ||
(4, 'DISCOVERY_SERVICE'), | ||
(5, 'CONCEPT_DESCRIPTION'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This is our Prisma schema file. | ||
// Changing the schema requires a new migration to apply those changes to all database instances. | ||
// Migrations can be generated by prisma. | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "sqlite" | ||
url = "file:./database/mnestix-database.db" | ||
} | ||
|
||
model ConnectionType { | ||
id String @id @default(cuid()) | ||
typeName String | ||
connection MnestixConnection[] | ||
} | ||
|
||
model MnestixConnection { | ||
id String @id @default(cuid()) | ||
url String | ||
type ConnectionType @relation(fields: [typeId], references: [id]) | ||
typeId String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/app/[locale]/settings/_components/mnestix-connections/MnestixConnectionsCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { CardHeading } from 'components/basics/CardHeading'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { messages } from 'lib/i18n/localization'; | ||
import { Box } from '@mui/material'; | ||
|
||
export function MnestixConnectionsCard() { | ||
return ( | ||
<Box sx={{p: 3, width: '100%'}}> | ||
<CardHeading | ||
title={<FormattedMessage {...messages.mnestix.mnestixConnections} />} | ||
subtitle={<FormattedMessage {...messages.mnestix.mnestixConnectionsExplanation} />} | ||
/> | ||
<Box minHeight='300px'> | ||
todo: content will follow | ||
</Box> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { prisma } from 'lib/database/prisma'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export async function GET() { | ||
try { | ||
const mnestixConnections = await prisma.mnestixConnection.findMany({include: {type: true}}) | ||
|
||
return Response.json(mnestixConnections); | ||
} catch (error) { | ||
return Response.json({ error: (error as Error).message }); | ||
} | ||
} | ||
|
||
export async function POST(req: NextRequest) { | ||
const mnestixConnectionRequest = await req.json() | ||
|
||
if (!mnestixConnectionRequest.url || !mnestixConnectionRequest.type) { | ||
return Response.json({ error: 'Url and type are required' }); | ||
} | ||
|
||
try { | ||
const mnestixType = await prisma.connectionType.findFirst({ where: { typeName: mnestixConnectionRequest.type } }) | ||
if (!mnestixType) { | ||
return Response.json({ error: 'Invalid type' }) | ||
} | ||
await prisma.mnestixConnection.create({ | ||
data: { | ||
url: mnestixConnectionRequest.url, | ||
typeId: mnestixType.id | ||
} | ||
}) | ||
return Response.json({ message: 'MnestixConnection created' }); | ||
} catch (error) { | ||
return Response.json({ error: (error as Error).message }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
/** | ||
* For using prisma with Next.js, it is recommended to use the PrismaClient as Singleton. | ||
*/ | ||
const prismaClientSingleton = () => { | ||
return new PrismaClient(); | ||
}; | ||
|
||
declare global { | ||
// eslint-disable-next-line | ||
var prisma: undefined | ReturnType<typeof prismaClientSingleton>; | ||
} | ||
|
||
export const prisma = globalThis.prisma ?? prismaClientSingleton(); | ||
|
||
if (process.env.NODE_ENV !== 'production') globalThis.prisma = prisma; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.