WIP2
This commit is contained in:
@@ -0,0 +1,205 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "SystemSetting" (
|
||||
"hashKey" TEXT NOT NULL PRIMARY KEY,
|
||||
"hashValueType" TEXT NOT NULL,
|
||||
"hashValue" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "SystemPostMigration" (
|
||||
"name" TEXT NOT NULL PRIMARY KEY,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "AuthRealm" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"name" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "AuthOauth2Client" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"realmId" INTEGER NOT NULL,
|
||||
"clientId" TEXT NOT NULL,
|
||||
"clientSecret" TEXT,
|
||||
"consentRequired" BOOLEAN NOT NULL DEFAULT false,
|
||||
"authorizationCodeFlowEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"resourceOwnerPasswordCredentialsFlowEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"clientCredentialsFlowEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"idTokenEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"refreshTokenEnabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
CONSTRAINT "AuthOauth2Client_realmId_fkey" FOREIGN KEY ("realmId") REFERENCES "AuthRealm" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "AuthOauth2Scope" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"realmId" INTEGER NOT NULL,
|
||||
"scope" TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "AuthOauth2ClientToAuthOauth2Scope" (
|
||||
"clientId" INTEGER NOT NULL,
|
||||
"scopeId" INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY ("clientId", "scopeId"),
|
||||
CONSTRAINT "AuthOauth2ClientToAuthOauth2Scope_clientId_fkey" FOREIGN KEY ("clientId") REFERENCES "AuthOauth2Client" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT "AuthOauth2ClientToAuthOauth2Scope_scopeId_fkey" FOREIGN KEY ("scopeId") REFERENCES "AuthOauth2Scope" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "AuthOauth2ScopeToIdentityProfileAttributeName" (
|
||||
"scopeId" INTEGER NOT NULL,
|
||||
"claimName" TEXT NOT NULL,
|
||||
"attributeId" INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY ("scopeId", "attributeId"),
|
||||
CONSTRAINT "AuthOauth2ScopeToIdentityProfileAttributeName_scopeId_fkey" FOREIGN KEY ("scopeId") REFERENCES "AuthOauth2Scope" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT "AuthOauth2ScopeToIdentityProfileAttributeName_attributeId_fkey" FOREIGN KEY ("attributeId") REFERENCES "IdentityProfileAttributeName" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "AuthRole" (
|
||||
"realmId" INTEGER NOT NULL,
|
||||
"roleName" TEXT NOT NULL,
|
||||
|
||||
PRIMARY KEY ("realmId", "roleName"),
|
||||
CONSTRAINT "AuthRole_realmId_fkey" FOREIGN KEY ("realmId") REFERENCES "AuthRealm" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "AuthAccessAttempt" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"username" TEXT NOT NULL,
|
||||
"ip" TEXT NOT NULL,
|
||||
"userAgent" TEXT NOT NULL,
|
||||
"requestPath" TEXT NOT NULL,
|
||||
"valid" BOOLEAN NOT NULL,
|
||||
"attemptedOn" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "EnumIdentityGroupRole" (
|
||||
"enumValue" TEXT NOT NULL PRIMARY KEY
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "IdentityGroup" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"realmId" INTEGER NOT NULL,
|
||||
"role" TEXT NOT NULL,
|
||||
"name" TEXT,
|
||||
CONSTRAINT "IdentityGroup_realmId_fkey" FOREIGN KEY ("realmId") REFERENCES "AuthRealm" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT "IdentityGroup_role_fkey" FOREIGN KEY ("role") REFERENCES "EnumIdentityGroupRole" ("enumValue") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "IdentityGroupToIdentityUser" (
|
||||
"groupId" INTEGER NOT NULL,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"userIsGroupAdmin" BOOLEAN NOT NULL DEFAULT false,
|
||||
|
||||
PRIMARY KEY ("groupId", "userId"),
|
||||
CONSTRAINT "IdentityGroupToIdentityUser_groupId_fkey" FOREIGN KEY ("groupId") REFERENCES "IdentityGroup" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT "IdentityGroupToIdentityUser_userId_fkey" FOREIGN KEY ("userId") REFERENCES "IdentityUser" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "IdentityUser" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"externalId" TEXT NOT NULL,
|
||||
"username" TEXT NOT NULL,
|
||||
"realmId" INTEGER NOT NULL,
|
||||
CONSTRAINT "IdentityUser_realmId_fkey" FOREIGN KEY ("realmId") REFERENCES "AuthRealm" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "IdentityProfileAttributeName" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"realmId" INTEGER NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
CONSTRAINT "IdentityProfileAttributeName_realmId_fkey" FOREIGN KEY ("realmId") REFERENCES "AuthRealm" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "IdentityProfileNonNormalized" (
|
||||
"userId" INTEGER NOT NULL,
|
||||
"attributeNameId" INTEGER NOT NULL,
|
||||
"attributeValue" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
PRIMARY KEY ("userId", "attributeNameId"),
|
||||
CONSTRAINT "IdentityProfileNonNormalized_userId_fkey" FOREIGN KEY ("userId") REFERENCES "IdentityUser" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT "IdentityProfileNonNormalized_attributeNameId_fkey" FOREIGN KEY ("attributeNameId") REFERENCES "IdentityProfileAttributeName" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "IdentityUserEmails" (
|
||||
"email" TEXT NOT NULL PRIMARY KEY,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"verified" BOOLEAN NOT NULL DEFAULT false,
|
||||
"default" BOOLEAN NOT NULL DEFAULT false,
|
||||
CONSTRAINT "IdentityUserEmails_userId_fkey" FOREIGN KEY ("userId") REFERENCES "IdentityUser" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "EnumIdentityAuthDeviceType" (
|
||||
"enumValue" TEXT NOT NULL PRIMARY KEY
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "IdentityAuthDevice" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"deviceType" TEXT NOT NULL,
|
||||
"attributes" TEXT NOT NULL,
|
||||
"preferred" BOOLEAN NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "IdentityAuthDevice_userId_fkey" FOREIGN KEY ("userId") REFERENCES "IdentityUser" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT "IdentityAuthDevice_deviceType_fkey" FOREIGN KEY ("deviceType") REFERENCES "EnumIdentityAuthDeviceType" ("enumValue") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "EnumCloudDavResourceType" (
|
||||
"enumValue" TEXT NOT NULL PRIMARY KEY
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "CloudDavResource" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"identityGroupId" INTEGER NOT NULL,
|
||||
"resourceType" TEXT NOT NULL,
|
||||
"attributes" TEXT NOT NULL,
|
||||
CONSTRAINT "CloudDavResource_identityGroupId_fkey" FOREIGN KEY ("identityGroupId") REFERENCES "IdentityGroup" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT "CloudDavResource_resourceType_fkey" FOREIGN KEY ("resourceType") REFERENCES "EnumCloudDavResourceType" ("enumValue") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "AuthRealm_name_key" ON "AuthRealm"("name");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "AuthOauth2Client_realmId_clientId_key" ON "AuthOauth2Client"("realmId", "clientId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "AuthOauth2Scope_realmId_scope_key" ON "AuthOauth2Scope"("realmId", "scope");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "AuthOauth2ScopeToIdentityProfileAttributeName_scopeId_claimName_key" ON "AuthOauth2ScopeToIdentityProfileAttributeName"("scopeId", "claimName");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "IdentityUser_externalId_key" ON "IdentityUser"("externalId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "IdentityUser_username_key" ON "IdentityUser"("username");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "IdentityAuthDevice_userId_idx" ON "IdentityAuthDevice"("userId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "IdentityAuthDevice_userId_deviceType_idx" ON "IdentityAuthDevice"("userId", "deviceType");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "CloudDavResource_identityGroupId_idx" ON "CloudDavResource"("identityGroupId");
|
||||
3
monolithic-backend/prisma/migrations/migration_lock.toml
Normal file
3
monolithic-backend/prisma/migrations/migration_lock.toml
Normal 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"
|
||||
242
monolithic-backend/prisma/schema.prisma
Normal file
242
monolithic-backend/prisma/schema.prisma
Normal file
@@ -0,0 +1,242 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "sqlite"
|
||||
url = "file:../../data/core.db"
|
||||
}
|
||||
|
||||
//
|
||||
// Namespace: System
|
||||
//
|
||||
model SystemSetting {
|
||||
hashKey String @id
|
||||
hashValueType String
|
||||
hashValue String
|
||||
}
|
||||
|
||||
model SystemPostMigration {
|
||||
name String @id
|
||||
createdAt DateTime @default(now())
|
||||
}
|
||||
|
||||
//
|
||||
// Namespace: Auth
|
||||
//
|
||||
model AuthRealm {
|
||||
id Int @id @default(autoincrement())
|
||||
name String @unique
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
oauth2Clients AuthOauth2Client[]
|
||||
groups IdentityGroup[]
|
||||
users IdentityUser[]
|
||||
profileAttributeNames IdentityProfileAttributeName[]
|
||||
roles AuthRole[]
|
||||
}
|
||||
|
||||
model AuthOauth2Client {
|
||||
id Int @id @default(autoincrement())
|
||||
|
||||
realmId Int
|
||||
realm AuthRealm @relation(fields: [realmId], references: [id])
|
||||
|
||||
clientId String
|
||||
clientSecret String?
|
||||
|
||||
consentRequired Boolean @default(false)
|
||||
authorizationCodeFlowEnabled Boolean @default(false)
|
||||
resourceOwnerPasswordCredentialsFlowEnabled Boolean @default(false)
|
||||
clientCredentialsFlowEnabled Boolean @default(false)
|
||||
idTokenEnabled Boolean @default(false)
|
||||
refreshTokenEnabled Boolean @default(false)
|
||||
|
||||
scopeMappings AuthOauth2ClientToAuthOauth2Scope[]
|
||||
|
||||
@@unique([realmId, clientId])
|
||||
}
|
||||
|
||||
model AuthOauth2Scope {
|
||||
id Int @id @default(autoincrement())
|
||||
realmId Int
|
||||
scope String
|
||||
|
||||
profileAttributeMappings AuthOauth2ScopeToIdentityProfileAttributeName[]
|
||||
clientMappings AuthOauth2ClientToAuthOauth2Scope[]
|
||||
|
||||
@@unique([realmId, scope])
|
||||
}
|
||||
|
||||
model AuthOauth2ClientToAuthOauth2Scope {
|
||||
clientId Int
|
||||
oauth2Client AuthOauth2Client @relation(fields: [clientId], references: [id])
|
||||
|
||||
scopeId Int
|
||||
scope AuthOauth2Scope @relation(fields: [scopeId], references: [id])
|
||||
|
||||
@@id([clientId, scopeId])
|
||||
}
|
||||
|
||||
model AuthOauth2ScopeToIdentityProfileAttributeName {
|
||||
scopeId Int
|
||||
scope AuthOauth2Scope @relation(fields: [scopeId], references: [id])
|
||||
|
||||
claimName String
|
||||
|
||||
attributeId Int
|
||||
attributes IdentityProfileAttributeName @relation(fields: [attributeId], references: [id])
|
||||
|
||||
@@id([scopeId, attributeId])
|
||||
@@unique([scopeId, claimName])
|
||||
}
|
||||
|
||||
model AuthRole {
|
||||
realmId Int
|
||||
realm AuthRealm @relation(fields: [realmId], references: [id])
|
||||
|
||||
roleName String
|
||||
|
||||
@@id([realmId, roleName])
|
||||
}
|
||||
|
||||
model AuthAccessAttempt {
|
||||
id String @id @default(uuid())
|
||||
username String
|
||||
ip String
|
||||
userAgent String
|
||||
requestPath String
|
||||
valid Boolean
|
||||
attemptedOn DateTime @default(now())
|
||||
}
|
||||
|
||||
//
|
||||
// Namespace: Identity
|
||||
//
|
||||
model EnumIdentityGroupRole {
|
||||
enumValue String @id
|
||||
|
||||
groups IdentityGroup[]
|
||||
}
|
||||
|
||||
model IdentityGroup {
|
||||
id Int @id @default(autoincrement())
|
||||
|
||||
realmId Int
|
||||
realm AuthRealm @relation(fields: [realmId], references: [id])
|
||||
|
||||
role String
|
||||
roleRelation EnumIdentityGroupRole @relation(fields: [role], references: [enumValue])
|
||||
|
||||
name String?
|
||||
|
||||
users IdentityGroupToIdentityUser[]
|
||||
davResources CloudDavResource[]
|
||||
}
|
||||
|
||||
model IdentityGroupToIdentityUser {
|
||||
groupId Int
|
||||
group IdentityGroup @relation(fields: [groupId], references: [id])
|
||||
|
||||
userId Int
|
||||
user IdentityUser @relation(fields: [userId], references: [id])
|
||||
|
||||
userIsGroupAdmin Boolean @default(false)
|
||||
|
||||
@@id([groupId, userId])
|
||||
}
|
||||
|
||||
model IdentityUser {
|
||||
id Int @id @default(autoincrement())
|
||||
externalId String @unique @default(uuid())
|
||||
username String @unique
|
||||
|
||||
realmId Int
|
||||
realm AuthRealm @relation(fields: [realmId], references: [id])
|
||||
|
||||
groups IdentityGroupToIdentityUser[]
|
||||
profileHashMapPairs IdentityProfileNonNormalized[]
|
||||
emails IdentityUserEmails[]
|
||||
authDevices IdentityAuthDevice[]
|
||||
}
|
||||
|
||||
model IdentityProfileAttributeName {
|
||||
id Int @id @default(autoincrement())
|
||||
|
||||
realmId Int
|
||||
realm AuthRealm @relation(fields: [realmId], references: [id])
|
||||
|
||||
name String
|
||||
|
||||
attributeUses IdentityProfileNonNormalized[]
|
||||
scopeMappings AuthOauth2ScopeToIdentityProfileAttributeName[]
|
||||
}
|
||||
|
||||
model IdentityProfileNonNormalized {
|
||||
userId Int
|
||||
user IdentityUser @relation(fields: [userId], references: [id])
|
||||
|
||||
attributeNameId Int
|
||||
attributeName IdentityProfileAttributeName @relation(fields: [attributeNameId], references: [id])
|
||||
|
||||
attributeValue String
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@id([userId, attributeNameId])
|
||||
}
|
||||
|
||||
model IdentityUserEmails {
|
||||
email String @id
|
||||
|
||||
userId Int
|
||||
user IdentityUser @relation(fields: [userId], references: [id])
|
||||
|
||||
verified Boolean @default(false)
|
||||
default Boolean @default(false)
|
||||
}
|
||||
|
||||
model EnumIdentityAuthDeviceType {
|
||||
enumValue String @id
|
||||
|
||||
authDevices IdentityAuthDevice[]
|
||||
}
|
||||
|
||||
model IdentityAuthDevice {
|
||||
id String @id @default(uuid())
|
||||
|
||||
userId Int
|
||||
user IdentityUser @relation(fields: [userId], references: [id])
|
||||
|
||||
deviceType String
|
||||
deviceTypeRelation EnumIdentityAuthDeviceType @relation(fields: [deviceType], references: [enumValue])
|
||||
|
||||
attributes String
|
||||
preferred Boolean
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([userId])
|
||||
@@index([userId, deviceType])
|
||||
}
|
||||
|
||||
//
|
||||
// Namespace: cloud-dav
|
||||
//
|
||||
model EnumCloudDavResourceType {
|
||||
enumValue String @id
|
||||
|
||||
davResources CloudDavResource[]
|
||||
}
|
||||
|
||||
model CloudDavResource {
|
||||
id String @id @default(uuid())
|
||||
|
||||
identityGroupId Int
|
||||
IdentityGroup IdentityGroup @relation(fields: [identityGroupId], references: [id])
|
||||
|
||||
resourceType String
|
||||
resourceTypeRelation EnumCloudDavResourceType @relation(fields: [resourceType], references: [enumValue])
|
||||
|
||||
attributes String
|
||||
|
||||
@@index([identityGroupId])
|
||||
}
|
||||
Reference in New Issue
Block a user