mirror of
https://github.com/swissmakers/swiss-datashare.git
synced 2026-04-11 10:27:01 +02:00
feat: add setup wizard
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `firstName` on the `User` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `lastName` on the `User` table. All the data in the column will be lost.
|
||||
- Added the required column `username` to the `User` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- CreateTable
|
||||
CREATE TABLE "Config" (
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
"key" TEXT NOT NULL PRIMARY KEY,
|
||||
"type" TEXT NOT NULL,
|
||||
"value" TEXT NOT NULL,
|
||||
"description" TEXT NOT NULL,
|
||||
"secret" BOOLEAN NOT NULL DEFAULT true,
|
||||
"locked" BOOLEAN NOT NULL DEFAULT false
|
||||
);
|
||||
|
||||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_User" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
"username" TEXT NOT NULL,
|
||||
"email" TEXT NOT NULL,
|
||||
"password" TEXT NOT NULL,
|
||||
"isAdmin" BOOLEAN NOT NULL DEFAULT false
|
||||
);
|
||||
INSERT INTO "new_User" ("createdAt", "email", "id", "password", "updatedAt") SELECT "createdAt", "email", "id", "password", "updatedAt" FROM "User";
|
||||
DROP TABLE "User";
|
||||
ALTER TABLE "new_User" RENAME TO "User";
|
||||
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
|
||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
||||
@@ -12,11 +12,10 @@ model User {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
email String @unique
|
||||
password String
|
||||
isAdministrator Boolean @default(false)
|
||||
firstName String?
|
||||
lastName String?
|
||||
username String @unique
|
||||
email String @unique
|
||||
password String
|
||||
isAdmin Boolean @default(false)
|
||||
|
||||
shares Share[]
|
||||
refreshTokens RefreshToken[]
|
||||
@@ -81,10 +80,10 @@ model ShareSecurity {
|
||||
model Config {
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
key String @id
|
||||
type String
|
||||
value String?
|
||||
default String
|
||||
secret Boolean @default(true)
|
||||
locked Boolean @default(false)
|
||||
key String @id
|
||||
type String
|
||||
value String
|
||||
description String
|
||||
secret Boolean @default(true)
|
||||
locked Boolean @default(false)
|
||||
}
|
||||
|
||||
@@ -1,79 +1,8 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import configVariables from "../../src/configVariables";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const configVariables = [
|
||||
{
|
||||
key: "setupFinished",
|
||||
type: "boolean",
|
||||
default: "false",
|
||||
secret: false,
|
||||
locked: true
|
||||
},
|
||||
{
|
||||
key: "appUrl",
|
||||
type: "string",
|
||||
default: "http://localhost:3000",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "showHomePage",
|
||||
type: "boolean",
|
||||
default: "true",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "allowRegistration",
|
||||
type: "boolean",
|
||||
default: "true",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "allowUnauthenticatedShares",
|
||||
type: "boolean",
|
||||
default: "false",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "maxFileSize",
|
||||
type: "number",
|
||||
default: "1000000000",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "jwtSecret",
|
||||
type: "string",
|
||||
default: "long-random-string",
|
||||
locked: true
|
||||
},
|
||||
{
|
||||
key: "emailRecipientsEnabled",
|
||||
type: "boolean",
|
||||
default: "false",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "smtpHost",
|
||||
type: "string",
|
||||
default: "",
|
||||
},
|
||||
{
|
||||
key: "smtpPort",
|
||||
type: "number",
|
||||
default: "",
|
||||
},
|
||||
{
|
||||
key: "smtpEmail",
|
||||
type: "string",
|
||||
default: "",
|
||||
},
|
||||
{
|
||||
key: "smtpPassword",
|
||||
type: "string",
|
||||
default: "",
|
||||
},
|
||||
];
|
||||
|
||||
async function main() {
|
||||
for (const variable of configVariables) {
|
||||
const existingConfigVariable = await prisma.config.findUnique({
|
||||
@@ -85,14 +14,6 @@ async function main() {
|
||||
await prisma.config.create({
|
||||
data: variable,
|
||||
});
|
||||
} else {
|
||||
// Update the config variable if the default value has changed
|
||||
if (existingConfigVariable.default != variable.default) {
|
||||
await prisma.config.update({
|
||||
where: { key: variable.key },
|
||||
data: { default: variable.default },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user