-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mnes 1186 add sqlite db #69
Merged
GailMelanie
merged 18 commits into
feat(repositry-settings)
from
MNES-1186-add-sqlite-db
Aug 26, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b8b597d
MNES-1186 add simple sqlite db
GailMelanie 4ac5518
MNES-1186
GailMelanie 74cac16
MNES-1186 use prisma
GailMelanie b9ac6dc
MNES-1186 rename table
GailMelanie 012a128
MNES-1186 run db in docker dev env
GailMelanie 7ecd23a
MNES-1186
GailMelanie b374a54
MNES-1186 revert compose changes
GailMelanie 4a8c947
MNES-1186 eslint
GailMelanie 4f32ffa
Mnes-1186
GailMelanie a165d6f
MNES-1186 fix lock file
GailMelanie 928a4d8
MNES-1186 remove ts-node
GailMelanie f7937aa
MNES-1186
GailMelanie b281a22
MNES-1186 try tsx
GailMelanie 59d645f
Revert "MNES-1186 try tsx"
GailMelanie 33dcb18
MNES-1186 add enum during first migration, hardcode database url
GailMelanie cf8d8d3
MNES-1202 set up settings page layout (#70)
GailMelanie e40879e
MNES-1186 return enum value and extend start command
GailMelanie 74eeb43
Merge branch 'MNES-1186-add-sqlite-db' of https://github.com/mnestix/…
GailMelanie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, but do we really want to use the formal "Sie" instead of just "Definiere, welche [...]"?