Files
Palmr/apps/server/prisma/seed.js
Daniel Luiz Alves d40ef51695 chore: add Dockerfile, docker-compose, and .dockerignore for multi-service setup
Introduce a Dockerfile for building the Palmr application with multi-stage builds for both server and web components. Update docker-compose.yaml to consolidate services under a single 'palmr' service, ensuring proper health checks and environment variable configurations. Add a .dockerignore file to optimize Docker builds by excluding unnecessary files. Include a Makefile for simplified build and deployment commands.
2025-05-27 00:50:46 -03:00

169 lines
3.5 KiB
JavaScript

/* eslint-disable no-undef */
const { PrismaClient } = require('@prisma/client');
const crypto = require('crypto');
const prisma = new PrismaClient();
const defaultConfigs = [
// General Configurations
{
key: "appName",
value: "Palmr. ",
type: "string",
group: "general",
},
{
key: "showHomePage",
value: "true",
type: "boolean",
group: "general",
},
{
key: "appDescription",
value: "Secure and simple file sharing - Your personal cloud",
type: "string",
group: "general",
},
{
key: "appLogo",
value: "https://i.ibb.co/V0hdRtjV/logo.png",
type: "string",
group: "general",
},
{
key: "firstUserAccess",
value: "true",
type: "boolean",
group: "general",
},
// Storage Configurations
{
key: "maxFileSize",
value: process.env.MAX_FILESIZE || "1073741824", // default 1GiB in bytes
type: "bigint",
group: "storage",
},
{
key: "maxTotalStoragePerUser",
value: "10737418240", // 10GB in bytes
type: "bigint",
group: "storage",
},
// Security Configurations
{
key: "jwtSecret",
value: crypto.randomBytes(64).toString("hex"),
type: "string",
group: "security",
},
{
key: "maxLoginAttempts",
value: "5",
type: "number",
group: "security",
},
{
key: "loginBlockDuration",
value: "600", // 10 minutes in seconds
type: "number",
group: "security",
},
{
key: "passwordMinLength",
value: "8",
type: "number",
group: "security",
},
// Email Configurations
{
key: "smtpEnabled",
value: "false",
type: "boolean",
group: "email",
},
{
key: "smtpHost",
value: "smtp.gmail.com",
type: "string",
group: "email",
},
{
key: "smtpPort",
value: "587",
type: "number",
group: "email",
},
{
key: "smtpUser",
value: "your-email@gmail.com",
type: "string",
group: "email",
},
{
key: "smtpPass",
value: "your-app-specific-password",
type: "string",
group: "email",
},
{
key: "smtpFromName",
value: "Palmr",
type: "string",
group: "email",
},
{
key: "smtpFromEmail",
value: "noreply@palmr.app",
type: "string",
group: "email",
},
{
key: "passwordResetTokenExpiration",
value: "3600",
type: "number",
group: "security",
}
];
async function main() {
console.log("🌱 Starting app configurations seed...");
console.log("🛡️ Protected mode: Only creates missing configurations");
let createdCount = 0;
let skippedCount = 0;
for (const config of defaultConfigs) {
// Check if configuration already exists
const existingConfig = await prisma.appConfig.findUnique({
where: { key: config.key },
});
if (existingConfig) {
console.log(`⏭️ Configuration '${config.key}' already exists, skipping...`);
skippedCount++;
continue;
}
// Only create if it doesn't exist
await prisma.appConfig.create({
data: config,
});
console.log(`✅ Created configuration: ${config.key}`);
createdCount++;
}
console.log("\n📊 Seed Summary:");
console.log(` ✅ Created: ${createdCount} configurations`);
console.log(` ⏭️ Skipped: ${skippedCount} configurations`);
console.log("🎉 App configurations seeded successfully!");
}
main()
.catch((error) => {
console.error("Error during seed:", error);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});