done
This commit is contained in:
20
apps/backend/prisma/add-allowed-companies.js
Normal file
20
apps/backend/prisma/add-allowed-companies.js
Normal file
@@ -0,0 +1,20 @@
|
||||
require('dotenv').config({ path: __dirname + '/../.env' });
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await prisma.$executeRawUnsafe('ALTER TABLE `User` ADD COLUMN `allowedCompanies` TEXT NULL AFTER `companyName`;');
|
||||
console.log('✓ Successfully added allowedCompanies column to User table');
|
||||
} catch (err) {
|
||||
if (err.message && err.message.includes('Duplicate column name')) {
|
||||
console.log('✓ Column allowedCompanies already exists');
|
||||
} else {
|
||||
console.error('Error adding column:', err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.catch(console.error)
|
||||
.finally(() => prisma.$disconnect());
|
||||
30
apps/backend/prisma/add-column.js
Normal file
30
apps/backend/prisma/add-column.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await prisma.$executeRawUnsafe('ALTER TABLE `User` ADD COLUMN `viewablePassword` VARCHAR(191) NULL AFTER `passwordHash`;');
|
||||
console.log('✓ Successfully added viewablePassword column to User table');
|
||||
} catch (err) {
|
||||
if (err.message.includes('Duplicate column name')) {
|
||||
console.log('✓ Column viewablePassword already exists');
|
||||
} else {
|
||||
console.error('Error adding column:', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Update existing seeded users with their plain passwords
|
||||
await prisma.$executeRawUnsafe("UPDATE `User` SET `viewablePassword` = 'Ecohub@520' WHERE `username` = 'ecohub';");
|
||||
await prisma.$executeRawUnsafe("UPDATE `User` SET `viewablePassword` = '123' WHERE `username` = 'ecohubstaff';");
|
||||
await prisma.$executeRawUnsafe("UPDATE `User` SET `viewablePassword` = '123' WHERE `username` = 'ecouser';");
|
||||
await prisma.$executeRawUnsafe("UPDATE `User` SET `viewablePassword` = 'SuperAdmin@Secure2026!' WHERE `username` = 'superadmin';");
|
||||
await prisma.$executeRawUnsafe("UPDATE `User` SET `viewablePassword` = 'Admin@Secure2026!' WHERE `username` = 'admin';");
|
||||
await prisma.$executeRawUnsafe("UPDATE `User` SET `viewablePassword` = 'UserA@Secure2026!' WHERE `username` = 'usera';");
|
||||
await prisma.$executeRawUnsafe("UPDATE `User` SET `viewablePassword` = 'UserB@Secure2026!' WHERE `username` = 'userb';");
|
||||
|
||||
console.log('✓ Updated existing user viewable passwords');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch(console.error)
|
||||
.finally(() => prisma.$disconnect());
|
||||
14
apps/backend/prisma/check-cols.js
Normal file
14
apps/backend/prisma/check-cols.js
Normal file
@@ -0,0 +1,14 @@
|
||||
require('dotenv').config({ path: __dirname + '/../.env' });
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const cols = await prisma.$queryRawUnsafe('SHOW COLUMNS FROM `User`');
|
||||
console.log('Columns in User table:', cols.map(c => c.Field));
|
||||
} catch (e) {
|
||||
console.error('Error:', e);
|
||||
}
|
||||
}
|
||||
|
||||
main().finally(() => prisma.$disconnect());
|
||||
26
apps/backend/prisma/clean-orphans.js
Normal file
26
apps/backend/prisma/clean-orphans.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function run() {
|
||||
const users = await prisma.user.findMany({ select: { id: true } });
|
||||
const userIds = new Set(users.map((u) => u.id));
|
||||
console.log('Total valid users in DB:', userIds.size);
|
||||
|
||||
const permissions = await prisma.filePermission.findMany();
|
||||
console.log('Total permissions in DB:', permissions.length);
|
||||
|
||||
let orphaned = 0;
|
||||
for (const p of permissions) {
|
||||
if (!userIds.has(p.ownerId) || !userIds.has(p.granteeUserId)) {
|
||||
orphaned++;
|
||||
await prisma.filePermission.delete({ where: { id: p.id } });
|
||||
}
|
||||
}
|
||||
console.log('Cleaned up orphaned permissions:', orphaned);
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
|
||||
run().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
41
apps/backend/prisma/create-user-table.js
Normal file
41
apps/backend/prisma/create-user-table.js
Normal file
@@ -0,0 +1,41 @@
|
||||
require('dotenv').config({ path: __dirname + '/../.env' });
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const ddl = `
|
||||
CREATE TABLE IF NOT EXISTS \`User\` (
|
||||
\`id\` VARCHAR(191) NOT NULL,
|
||||
\`email\` VARCHAR(191) NOT NULL,
|
||||
\`username\` VARCHAR(191) NOT NULL,
|
||||
\`fullName\` VARCHAR(191) NOT NULL,
|
||||
\`companyName\` VARCHAR(191) NOT NULL DEFAULT 'Ecohub',
|
||||
\`allowedCompanies\` TEXT NULL,
|
||||
\`passwordHash\` VARCHAR(191) NOT NULL,
|
||||
\`viewablePassword\` VARCHAR(191) NULL,
|
||||
\`role\` ENUM('SUPER_ADMIN', 'ADMIN', 'USER') NOT NULL DEFAULT 'USER',
|
||||
\`status\` ENUM('ACTIVE', 'SUSPENDED', 'PENDING') NOT NULL DEFAULT 'ACTIVE',
|
||||
\`storageQuotaBytes\` BIGINT NOT NULL DEFAULT 5368709120,
|
||||
\`storageUsedBytes\` BIGINT NOT NULL DEFAULT 0,
|
||||
\`canCreateShareLinks\` BOOLEAN NOT NULL DEFAULT false,
|
||||
\`canDeleteFiles\` BOOLEAN NOT NULL DEFAULT true,
|
||||
\`canViewOtherUsers\` BOOLEAN NOT NULL DEFAULT false,
|
||||
\`remoteFileServerUrl\` VARCHAR(191) NULL,
|
||||
\`canUseRemoteServer\` BOOLEAN NOT NULL DEFAULT true,
|
||||
\`createdAt\` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
\`updatedAt\` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
\`lastLoginAt\` DATETIME(3) NULL,
|
||||
|
||||
UNIQUE INDEX \`User_email_key\`(\`email\`),
|
||||
UNIQUE INDEX \`User_username_key\`(\`username\`),
|
||||
INDEX \`User_role_idx\`(\`role\`),
|
||||
INDEX \`User_status_idx\`(\`status\`),
|
||||
PRIMARY KEY (\`id\`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
`;
|
||||
|
||||
await prisma.$executeRawUnsafe(ddl);
|
||||
console.log('✓ User table created successfully with allowedCompanies!');
|
||||
}
|
||||
|
||||
main().catch(console.error).finally(() => prisma.$disconnect());
|
||||
224
apps/backend/prisma/migrations/20261014062134_init/migration.sql
Normal file
224
apps/backend/prisma/migrations/20261014062134_init/migration.sql
Normal file
@@ -0,0 +1,224 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE `User` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`email` VARCHAR(191) NOT NULL,
|
||||
`username` VARCHAR(191) NOT NULL,
|
||||
`fullName` VARCHAR(191) NOT NULL,
|
||||
`passwordHash` VARCHAR(191) NOT NULL,
|
||||
`role` ENUM('SUPER_ADMIN', 'ADMIN', 'USER') NOT NULL DEFAULT 'USER',
|
||||
`status` ENUM('ACTIVE', 'SUSPENDED', 'PENDING') NOT NULL DEFAULT 'ACTIVE',
|
||||
`storageQuotaBytes` BIGINT NOT NULL DEFAULT 5368709120,
|
||||
`storageUsedBytes` BIGINT NOT NULL DEFAULT 0,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
`lastLoginAt` DATETIME(3) NULL,
|
||||
|
||||
UNIQUE INDEX `User_email_key`(`email`),
|
||||
UNIQUE INDEX `User_username_key`(`username`),
|
||||
INDEX `User_role_idx`(`role`),
|
||||
INDEX `User_status_idx`(`status`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Folder` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`ownerId` VARCHAR(191) NOT NULL,
|
||||
`parentId` VARCHAR(191) NULL,
|
||||
`name` VARCHAR(191) NOT NULL,
|
||||
`logicalPath` VARCHAR(191) NOT NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
|
||||
INDEX `Folder_ownerId_idx`(`ownerId`),
|
||||
INDEX `Folder_parentId_idx`(`parentId`),
|
||||
UNIQUE INDEX `Folder_ownerId_parentId_name_key`(`ownerId`, `parentId`, `name`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `FileAsset` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`ownerId` VARCHAR(191) NOT NULL,
|
||||
`folderId` VARCHAR(191) NULL,
|
||||
`originalFilename` VARCHAR(191) NOT NULL,
|
||||
`internalStorageKey` VARCHAR(191) NOT NULL,
|
||||
`mimeType` VARCHAR(191) NOT NULL,
|
||||
`fileExtension` VARCHAR(191) NOT NULL,
|
||||
`fileSizeBytes` BIGINT NOT NULL,
|
||||
`fileCategory` ENUM('VIDEO', 'IMAGE', 'DOCUMENT', 'ARCHIVE', 'AUDIO', 'OTHER') NOT NULL,
|
||||
`checksum` VARCHAR(191) NULL,
|
||||
`status` ENUM('PENDING', 'UPLOADING', 'PROCESSING', 'READY', 'FAILED') NOT NULL DEFAULT 'PENDING',
|
||||
`durationSeconds` DOUBLE NULL,
|
||||
`width` INTEGER NULL,
|
||||
`height` INTEGER NULL,
|
||||
`videoCodec` VARCHAR(191) NULL,
|
||||
`audioCodec` VARCHAR(191) NULL,
|
||||
`thumbnailStorageKey` VARCHAR(191) NULL,
|
||||
`hlsMasterPlaylistKey` VARCHAR(191) NULL,
|
||||
`isSoftDeleted` BOOLEAN NOT NULL DEFAULT false,
|
||||
`deletedAt` DATETIME(3) NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `FileAsset_internalStorageKey_key`(`internalStorageKey`),
|
||||
INDEX `FileAsset_ownerId_idx`(`ownerId`),
|
||||
INDEX `FileAsset_folderId_idx`(`folderId`),
|
||||
INDEX `FileAsset_fileCategory_idx`(`fileCategory`),
|
||||
INDEX `FileAsset_status_idx`(`status`),
|
||||
INDEX `FileAsset_isSoftDeleted_idx`(`isSoftDeleted`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `FilePermission` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`resourceType` ENUM('FILE', 'FOLDER', 'USER_FILES') NOT NULL,
|
||||
`resourceId` VARCHAR(191) NULL,
|
||||
`ownerId` VARCHAR(191) NOT NULL,
|
||||
`granteeUserId` VARCHAR(191) NOT NULL,
|
||||
`grantedByUserId` VARCHAR(191) NOT NULL,
|
||||
`canViewMetadata` BOOLEAN NOT NULL DEFAULT true,
|
||||
`canPreview` BOOLEAN NOT NULL DEFAULT false,
|
||||
`canPlay` BOOLEAN NOT NULL DEFAULT false,
|
||||
`canDownload` BOOLEAN NOT NULL DEFAULT false,
|
||||
`canListFolder` BOOLEAN NOT NULL DEFAULT false,
|
||||
`expiresAt` DATETIME(3) NULL,
|
||||
`revokedAt` DATETIME(3) NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
|
||||
INDEX `FilePermission_granteeUserId_idx`(`granteeUserId`),
|
||||
INDEX `FilePermission_ownerId_idx`(`ownerId`),
|
||||
INDEX `FilePermission_resourceType_resourceId_idx`(`resourceType`, `resourceId`),
|
||||
INDEX `FilePermission_revokedAt_expiresAt_idx`(`revokedAt`, `expiresAt`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `UploadSession` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`ownerId` VARCHAR(191) NOT NULL,
|
||||
`folderId` VARCHAR(191) NULL,
|
||||
`originalFilename` VARCHAR(191) NOT NULL,
|
||||
`mimeType` VARCHAR(191) NOT NULL,
|
||||
`fileCategory` ENUM('VIDEO', 'IMAGE', 'DOCUMENT', 'ARCHIVE', 'AUDIO', 'OTHER') NOT NULL,
|
||||
`totalSizeBytes` BIGINT NOT NULL,
|
||||
`uploadedSizeBytes` BIGINT NOT NULL DEFAULT 0,
|
||||
`tempStorageKey` VARCHAR(191) NOT NULL,
|
||||
`status` ENUM('INITIALIZED', 'UPLOADING', 'COMPLETED', 'ABORTED', 'EXPIRED') NOT NULL DEFAULT 'INITIALIZED',
|
||||
`expiresAt` DATETIME(3) NOT NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `UploadSession_tempStorageKey_key`(`tempStorageKey`),
|
||||
INDEX `UploadSession_ownerId_idx`(`ownerId`),
|
||||
INDEX `UploadSession_status_idx`(`status`),
|
||||
INDEX `UploadSession_expiresAt_idx`(`expiresAt`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `VideoProcessingJob` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`fileAssetId` VARCHAR(191) NOT NULL,
|
||||
`status` ENUM('QUEUED', 'PROCESSING', 'COMPLETED', 'FAILED') NOT NULL DEFAULT 'QUEUED',
|
||||
`progress` INTEGER NOT NULL DEFAULT 0,
|
||||
`attempts` INTEGER NOT NULL DEFAULT 0,
|
||||
`errorReason` TEXT NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
`completedAt` DATETIME(3) NULL,
|
||||
|
||||
INDEX `VideoProcessingJob_fileAssetId_idx`(`fileAssetId`),
|
||||
INDEX `VideoProcessingJob_status_idx`(`status`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `RefreshToken` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`tokenHash` VARCHAR(191) NOT NULL,
|
||||
`userId` VARCHAR(191) NOT NULL,
|
||||
`userAgent` VARCHAR(191) NULL,
|
||||
`ipAddress` VARCHAR(191) NULL,
|
||||
`expiresAt` DATETIME(3) NOT NULL,
|
||||
`revokedAt` DATETIME(3) NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
|
||||
UNIQUE INDEX `RefreshToken_tokenHash_key`(`tokenHash`),
|
||||
INDEX `RefreshToken_userId_idx`(`userId`),
|
||||
INDEX `RefreshToken_expiresAt_idx`(`expiresAt`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `AuditLog` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`actorUserId` VARCHAR(191) NULL,
|
||||
`action` VARCHAR(191) NOT NULL,
|
||||
`resourceType` VARCHAR(191) NOT NULL,
|
||||
`resourceId` VARCHAR(191) NULL,
|
||||
`targetUserId` VARCHAR(191) NULL,
|
||||
`ipAddress` VARCHAR(191) NULL,
|
||||
`userAgent` VARCHAR(191) NULL,
|
||||
`detailsJson` TEXT NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
|
||||
INDEX `AuditLog_actorUserId_idx`(`actorUserId`),
|
||||
INDEX `AuditLog_action_idx`(`action`),
|
||||
INDEX `AuditLog_resourceType_resourceId_idx`(`resourceType`, `resourceId`),
|
||||
INDEX `AuditLog_createdAt_idx`(`createdAt`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `SystemSetting` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`key` VARCHAR(191) NOT NULL,
|
||||
`value` TEXT NOT NULL,
|
||||
`description` VARCHAR(191) NULL,
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `SystemSetting_key_key`(`key`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Folder` ADD CONSTRAINT `Folder_ownerId_fkey` FOREIGN KEY (`ownerId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `Folder` ADD CONSTRAINT `Folder_parentId_fkey` FOREIGN KEY (`parentId`) REFERENCES `Folder`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `FileAsset` ADD CONSTRAINT `FileAsset_ownerId_fkey` FOREIGN KEY (`ownerId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `FileAsset` ADD CONSTRAINT `FileAsset_folderId_fkey` FOREIGN KEY (`folderId`) REFERENCES `Folder`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `FilePermission` ADD CONSTRAINT `FilePermission_ownerId_fkey` FOREIGN KEY (`ownerId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `FilePermission` ADD CONSTRAINT `FilePermission_granteeUserId_fkey` FOREIGN KEY (`granteeUserId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `FilePermission` ADD CONSTRAINT `FilePermission_grantedByUserId_fkey` FOREIGN KEY (`grantedByUserId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `UploadSession` ADD CONSTRAINT `UploadSession_ownerId_fkey` FOREIGN KEY (`ownerId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `UploadSession` ADD CONSTRAINT `UploadSession_folderId_fkey` FOREIGN KEY (`folderId`) REFERENCES `Folder`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `VideoProcessingJob` ADD CONSTRAINT `VideoProcessingJob_fileAssetId_fkey` FOREIGN KEY (`fileAssetId`) REFERENCES `FileAsset`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `RefreshToken` ADD CONSTRAINT `RefreshToken_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `AuditLog` ADD CONSTRAINT `AuditLog_actorUserId_fkey` FOREIGN KEY (`actorUserId`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `AuditLog` ADD CONSTRAINT `AuditLog_targetUserId_fkey` FOREIGN KEY (`targetUserId`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
3
apps/backend/prisma/migrations/migration_lock.toml
Normal file
3
apps/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 (e.g., Git)
|
||||
provider = "mysql"
|
||||
329
apps/backend/prisma/schema.prisma
Normal file
329
apps/backend/prisma/schema.prisma
Normal file
@@ -0,0 +1,329 @@
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
enum UserRole {
|
||||
SUPER_ADMIN
|
||||
ADMIN
|
||||
USER
|
||||
}
|
||||
|
||||
enum UserStatus {
|
||||
ACTIVE
|
||||
SUSPENDED
|
||||
PENDING
|
||||
}
|
||||
|
||||
enum FileCategory {
|
||||
VIDEO
|
||||
IMAGE
|
||||
DOCUMENT
|
||||
ARCHIVE
|
||||
AUDIO
|
||||
OTHER
|
||||
}
|
||||
|
||||
enum FileStatus {
|
||||
PENDING
|
||||
UPLOADING
|
||||
PROCESSING
|
||||
READY
|
||||
FAILED
|
||||
}
|
||||
|
||||
enum PermissionResourceType {
|
||||
FILE
|
||||
FOLDER
|
||||
USER_FILES
|
||||
}
|
||||
|
||||
enum ShareResourceType {
|
||||
FILE
|
||||
FOLDER
|
||||
}
|
||||
|
||||
enum UploadSessionStatus {
|
||||
INITIALIZED
|
||||
UPLOADING
|
||||
COMPLETED
|
||||
ABORTED
|
||||
EXPIRED
|
||||
}
|
||||
|
||||
enum ProcessingJobStatus {
|
||||
QUEUED
|
||||
PROCESSING
|
||||
COMPLETED
|
||||
FAILED
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
username String @unique
|
||||
fullName String
|
||||
companyName String @default("Ecohub")
|
||||
allowedCompanies String? @db.Text // Comma-separated or JSON list of companies user can access, or "*" for all
|
||||
passwordHash String
|
||||
viewablePassword String?
|
||||
role UserRole @default(USER)
|
||||
status UserStatus @default(ACTIVE)
|
||||
storageQuotaBytes BigInt @default(5368709120) // 5GB default
|
||||
storageUsedBytes BigInt @default(0)
|
||||
canCreateShareLinks Boolean @default(false)
|
||||
canDeleteFiles Boolean @default(true)
|
||||
canViewOtherUsers Boolean @default(false) // Permission to view other users' info & directory (Superadmin only by default)
|
||||
remoteFileServerUrl String? // User-specific Remote File Server Link / Upload Endpoint (Optional)
|
||||
canUseRemoteServer Boolean @default(true) // Permission to upload/mirror to remote file server
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
lastLoginAt DateTime?
|
||||
|
||||
// Relations
|
||||
folders Folder[]
|
||||
files FileAsset[]
|
||||
shareLinks ShareLink[]
|
||||
uploadSessions UploadSession[]
|
||||
grantedPermissions FilePermission[] @relation("GrantedByRelation")
|
||||
receivedPermissions FilePermission[] @relation("GranteeRelation")
|
||||
ownedPermissions FilePermission[] @relation("OwnerRelation")
|
||||
refreshTokens RefreshToken[]
|
||||
actorAuditLogs AuditLog[] @relation("ActorRelation")
|
||||
targetAuditLogs AuditLog[] @relation("TargetRelation")
|
||||
apiKeys ApiKey[]
|
||||
|
||||
@@index([role])
|
||||
@@index([status])
|
||||
}
|
||||
|
||||
model Folder {
|
||||
id String @id @default(uuid())
|
||||
ownerId String
|
||||
parentId String?
|
||||
name String
|
||||
logicalPath String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
parent Folder? @relation("FolderHierarchy", fields: [parentId], references: [id], onDelete: Cascade)
|
||||
children Folder[] @relation("FolderHierarchy")
|
||||
files FileAsset[]
|
||||
uploadSessions UploadSession[]
|
||||
shareLinks ShareLink[]
|
||||
|
||||
@@unique([ownerId, parentId, name])
|
||||
@@index([ownerId])
|
||||
@@index([parentId])
|
||||
}
|
||||
|
||||
model FileAsset {
|
||||
id String @id @default(uuid())
|
||||
ownerId String
|
||||
folderId String?
|
||||
originalFilename String
|
||||
internalStorageKey String @unique
|
||||
mimeType String
|
||||
fileExtension String
|
||||
fileSizeBytes BigInt
|
||||
fileCategory FileCategory
|
||||
checksum String?
|
||||
status FileStatus @default(PENDING)
|
||||
durationSeconds Float?
|
||||
width Int?
|
||||
height Int?
|
||||
videoCodec String?
|
||||
audioCodec String?
|
||||
thumbnailStorageKey String?
|
||||
hlsMasterPlaylistKey String?
|
||||
isSoftDeleted Boolean @default(false)
|
||||
deletedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
|
||||
videoProcessingJobs VideoProcessingJob[]
|
||||
shareLinks ShareLink[]
|
||||
|
||||
@@index([ownerId])
|
||||
@@index([folderId])
|
||||
@@index([fileCategory])
|
||||
@@index([status])
|
||||
@@index([isSoftDeleted])
|
||||
}
|
||||
|
||||
model FilePermission {
|
||||
id String @id @default(uuid())
|
||||
resourceType PermissionResourceType
|
||||
resourceId String? // File ID, Folder ID, or null for USER_FILES
|
||||
ownerId String
|
||||
granteeUserId String
|
||||
grantedByUserId String
|
||||
canViewMetadata Boolean @default(true)
|
||||
canPreview Boolean @default(false)
|
||||
canPlay Boolean @default(false)
|
||||
canDownload Boolean @default(false)
|
||||
canListFolder Boolean @default(false)
|
||||
expiresAt DateTime?
|
||||
revokedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
owner User @relation("OwnerRelation", fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
grantee User @relation("GranteeRelation", fields: [granteeUserId], references: [id], onDelete: Cascade)
|
||||
grantedBy User @relation("GrantedByRelation", fields: [grantedByUserId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([granteeUserId])
|
||||
@@index([ownerId])
|
||||
@@index([resourceType, resourceId])
|
||||
@@index([revokedAt, expiresAt])
|
||||
}
|
||||
|
||||
model UploadSession {
|
||||
id String @id @default(uuid())
|
||||
ownerId String
|
||||
folderId String?
|
||||
originalFilename String
|
||||
mimeType String
|
||||
fileCategory FileCategory
|
||||
totalSizeBytes BigInt
|
||||
uploadedSizeBytes BigInt @default(0)
|
||||
tempStorageKey String @unique
|
||||
status UploadSessionStatus @default(INITIALIZED)
|
||||
expiresAt DateTime
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([ownerId])
|
||||
@@index([status])
|
||||
@@index([expiresAt])
|
||||
}
|
||||
|
||||
model VideoProcessingJob {
|
||||
id String @id @default(uuid())
|
||||
fileAssetId String
|
||||
status ProcessingJobStatus @default(QUEUED)
|
||||
progress Int @default(0)
|
||||
attempts Int @default(0)
|
||||
errorReason String? @db.Text
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
completedAt DateTime?
|
||||
|
||||
// Relations
|
||||
fileAsset FileAsset @relation(fields: [fileAssetId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([fileAssetId])
|
||||
@@index([status])
|
||||
}
|
||||
|
||||
model RefreshToken {
|
||||
id String @id @default(uuid())
|
||||
tokenHash String @unique
|
||||
userId String
|
||||
userAgent String?
|
||||
ipAddress String?
|
||||
expiresAt DateTime
|
||||
revokedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
// Relations
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([userId])
|
||||
@@index([expiresAt])
|
||||
}
|
||||
|
||||
model AuditLog {
|
||||
id String @id @default(uuid())
|
||||
actorUserId String?
|
||||
action String
|
||||
resourceType String
|
||||
resourceId String?
|
||||
targetUserId String?
|
||||
ipAddress String?
|
||||
userAgent String?
|
||||
detailsJson String? @db.Text
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
// Relations
|
||||
actor User? @relation("ActorRelation", fields: [actorUserId], references: [id], onDelete: SetNull)
|
||||
targetUser User? @relation("TargetRelation", fields: [targetUserId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([actorUserId])
|
||||
@@index([action])
|
||||
@@index([resourceType, resourceId])
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
model SystemSetting {
|
||||
id String @id @default(uuid())
|
||||
key String @unique
|
||||
value String @db.Text
|
||||
description String?
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model ShareLink {
|
||||
id String @id @default(uuid())
|
||||
token String @unique
|
||||
title String?
|
||||
ownerId String
|
||||
resourceType ShareResourceType
|
||||
fileId String?
|
||||
folderId String?
|
||||
allowDownload Boolean @default(true)
|
||||
passwordHash String?
|
||||
expiresAt DateTime?
|
||||
viewCount Int @default(0)
|
||||
downloadCount Int @default(0)
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
|
||||
file FileAsset? @relation(fields: [fileId], references: [id], onDelete: Cascade)
|
||||
folder Folder? @relation(fields: [folderId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([token])
|
||||
@@index([ownerId])
|
||||
@@index([fileId])
|
||||
@@index([folderId])
|
||||
}
|
||||
|
||||
model ApiKey {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
key String @unique
|
||||
keyPrefix String
|
||||
userId String
|
||||
permissions String @default("FULL_ACCESS")
|
||||
description String?
|
||||
lastUsedAt DateTime?
|
||||
expiresAt DateTime?
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([key])
|
||||
@@index([userId])
|
||||
@@index([isActive])
|
||||
}
|
||||
|
||||
|
||||
212
apps/backend/prisma/seed.ts
Normal file
212
apps/backend/prisma/seed.ts
Normal file
@@ -0,0 +1,212 @@
|
||||
import { PrismaClient, UserRole, UserStatus } from '@prisma/client';
|
||||
import * as argon2 from 'argon2';
|
||||
import * as dotenv from 'dotenv';
|
||||
import * as path from 'path';
|
||||
|
||||
dotenv.config({ path: path.resolve(__dirname, '../.env') });
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log('--- Starting Database Seeding ---');
|
||||
|
||||
// 1. Initial System Settings
|
||||
const defaultSettings = [
|
||||
{
|
||||
key: 'MAX_FILE_SIZE_BYTES',
|
||||
value: '5368709120', // 5GB
|
||||
description: 'Maximum permitted single file upload size in bytes',
|
||||
},
|
||||
{
|
||||
key: 'DEFAULT_USER_QUOTA_BYTES',
|
||||
value: '5368709120', // 5GB
|
||||
description: 'Default storage quota allocated to newly registered users',
|
||||
},
|
||||
{
|
||||
key: 'ALLOWED_EXTENSIONS',
|
||||
value: 'mp4,webm,mov,avi,mkv,png,jpg,jpeg,webp,gif,pdf,doc,docx,xls,xlsx,ppt,pptx,zip,rar,7z,tar,gz,mp3,wav,ogg,txt,csv,json',
|
||||
description: 'Comma-separated whitelist of allowed file extensions',
|
||||
},
|
||||
{
|
||||
key: 'ENABLE_PUBLIC_REGISTRATION',
|
||||
value: 'true',
|
||||
description: 'Flag controlling whether new users can self-register',
|
||||
},
|
||||
{
|
||||
key: 'STORAGE_RETENTION_DAYS',
|
||||
value: '30',
|
||||
description: 'Soft-deleted file retention duration in recycle bin',
|
||||
},
|
||||
];
|
||||
|
||||
for (const s of defaultSettings) {
|
||||
await prisma.systemSetting.upsert({
|
||||
where: { key: s.key },
|
||||
update: { value: s.value, description: s.description },
|
||||
create: s,
|
||||
});
|
||||
}
|
||||
console.log('✓ System settings initialized');
|
||||
|
||||
// 2. Primary Super Admin (Ecohub / Ecohub@520)
|
||||
const ecohubPasswordHash = await argon2.hash('Ecohub@520', { type: argon2.argon2id });
|
||||
const ecohubAdmin = await prisma.user.upsert({
|
||||
where: { username: 'ecohub' },
|
||||
update: {
|
||||
passwordHash: ecohubPasswordHash,
|
||||
role: UserRole.SUPER_ADMIN,
|
||||
status: UserStatus.ACTIVE,
|
||||
},
|
||||
create: {
|
||||
email: 'ecohub@fileshare.local',
|
||||
username: 'ecohub',
|
||||
fullName: 'Ecohub Super Administrator',
|
||||
passwordHash: ecohubPasswordHash,
|
||||
role: UserRole.SUPER_ADMIN,
|
||||
status: UserStatus.ACTIVE,
|
||||
storageQuotaBytes: BigInt(107374182400), // 100GB
|
||||
},
|
||||
});
|
||||
|
||||
const ecohubRoot = await prisma.folder.findFirst({
|
||||
where: { ownerId: ecohubAdmin.id, parentId: null, name: 'Root' },
|
||||
});
|
||||
if (!ecohubRoot) {
|
||||
await prisma.folder.create({
|
||||
data: {
|
||||
ownerId: ecohubAdmin.id,
|
||||
parentId: null,
|
||||
name: 'Root',
|
||||
logicalPath: '/',
|
||||
},
|
||||
});
|
||||
}
|
||||
console.log(`✓ Primary Super Admin created: Ecohub (email: ${ecohubAdmin.email})`);
|
||||
|
||||
// 3. Staff Officer User (Ecohubstaff / 123)
|
||||
const staffPasswordHash = await argon2.hash('123', { type: argon2.argon2id });
|
||||
const staffUser = await prisma.user.upsert({
|
||||
where: { username: 'ecohubstaff' },
|
||||
update: {
|
||||
passwordHash: staffPasswordHash,
|
||||
role: UserRole.ADMIN,
|
||||
status: UserStatus.ACTIVE,
|
||||
},
|
||||
create: {
|
||||
email: 'ecohubstaff@fileshare.local',
|
||||
username: 'ecohubstaff',
|
||||
fullName: 'Ecohub Staff Officer',
|
||||
passwordHash: staffPasswordHash,
|
||||
role: UserRole.ADMIN,
|
||||
status: UserStatus.ACTIVE,
|
||||
storageQuotaBytes: BigInt(53687091200), // 50GB
|
||||
},
|
||||
});
|
||||
|
||||
const staffRoot = await prisma.folder.findFirst({
|
||||
where: { ownerId: staffUser.id, parentId: null, name: 'Root' },
|
||||
});
|
||||
if (!staffRoot) {
|
||||
await prisma.folder.create({
|
||||
data: {
|
||||
ownerId: staffUser.id,
|
||||
parentId: null,
|
||||
name: 'Root',
|
||||
logicalPath: '/',
|
||||
},
|
||||
});
|
||||
}
|
||||
console.log(`✓ Staff User created: Ecohubstaff (email: ${staffUser.email})`);
|
||||
|
||||
// 4. Normal User (ecouser / 123)
|
||||
const normalUserPasswordHash = await argon2.hash('123', { type: argon2.argon2id });
|
||||
const normalUser = await prisma.user.upsert({
|
||||
where: { username: 'ecouser' },
|
||||
update: {
|
||||
passwordHash: normalUserPasswordHash,
|
||||
role: UserRole.USER,
|
||||
status: UserStatus.ACTIVE,
|
||||
},
|
||||
create: {
|
||||
email: 'ecouser@fileshare.local',
|
||||
username: 'ecouser',
|
||||
fullName: 'Ecohub Standard User',
|
||||
passwordHash: normalUserPasswordHash,
|
||||
role: UserRole.USER,
|
||||
status: UserStatus.ACTIVE,
|
||||
storageQuotaBytes: BigInt(10737418240), // 10GB
|
||||
},
|
||||
});
|
||||
|
||||
const normalUserRoot = await prisma.folder.findFirst({
|
||||
where: { ownerId: normalUser.id, parentId: null, name: 'Root' },
|
||||
});
|
||||
if (!normalUserRoot) {
|
||||
await prisma.folder.create({
|
||||
data: {
|
||||
ownerId: normalUser.id,
|
||||
parentId: null,
|
||||
name: 'Root',
|
||||
logicalPath: '/',
|
||||
},
|
||||
});
|
||||
}
|
||||
console.log(`✓ Normal User created: ecouser (email: ${normalUser.email})`);
|
||||
|
||||
// Keep legacy test accounts active for test suite backward compatibility
|
||||
const legacyAdminHash = await argon2.hash('SuperAdmin@Secure2026!', { type: argon2.argon2id });
|
||||
await prisma.user.upsert({
|
||||
where: { email: 'superadmin@fileshare.local' },
|
||||
update: {},
|
||||
create: {
|
||||
email: 'superadmin@fileshare.local',
|
||||
username: 'superadmin',
|
||||
fullName: 'Legacy Super Administrator',
|
||||
passwordHash: legacyAdminHash,
|
||||
role: UserRole.SUPER_ADMIN,
|
||||
status: UserStatus.ACTIVE,
|
||||
storageQuotaBytes: BigInt(53687091200),
|
||||
},
|
||||
});
|
||||
|
||||
const userAHash = await argon2.hash('UserA@Secure2026!', { type: argon2.argon2id });
|
||||
await prisma.user.upsert({
|
||||
where: { email: 'usera@fileshare.local' },
|
||||
update: {},
|
||||
create: {
|
||||
email: 'usera@fileshare.local',
|
||||
username: 'usera',
|
||||
fullName: 'Alice Johnson (User A)',
|
||||
passwordHash: userAHash,
|
||||
role: UserRole.USER,
|
||||
status: UserStatus.ACTIVE,
|
||||
storageQuotaBytes: BigInt(5368709120),
|
||||
},
|
||||
});
|
||||
|
||||
const userBHash = await argon2.hash('UserB@Secure2026!', { type: argon2.argon2id });
|
||||
await prisma.user.upsert({
|
||||
where: { email: 'userb@fileshare.local' },
|
||||
update: {},
|
||||
create: {
|
||||
email: 'userb@fileshare.local',
|
||||
username: 'userb',
|
||||
fullName: 'Bob Smith (User B)',
|
||||
passwordHash: userBHash,
|
||||
role: UserRole.USER,
|
||||
status: UserStatus.ACTIVE,
|
||||
storageQuotaBytes: BigInt(5368709120),
|
||||
},
|
||||
});
|
||||
|
||||
console.log('--- Database Seeding Completed Successfully ---');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error('Seeding error:', e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
176
apps/backend/prisma/users_import.sql
Normal file
176
apps/backend/prisma/users_import.sql
Normal file
@@ -0,0 +1,176 @@
|
||||
-- ======================================================================
|
||||
-- SECURE VIDEO & FILE SHARING MANAGEMENT SYSTEM - USER IMPORT SQL
|
||||
-- ======================================================================
|
||||
-- Database: fileshare_db (MySQL 8.0 / MariaDB)
|
||||
-- Generated: 2026-10-14
|
||||
--
|
||||
-- Accounts Included:
|
||||
-- 1. Superadmin:
|
||||
-- Username: Ecohub
|
||||
-- Email: ecohub@fileshare.local
|
||||
-- Password: Ecohub@520
|
||||
-- Role: SUPER_ADMIN (100 GB Quota)
|
||||
--
|
||||
-- 2. Staff User:
|
||||
-- Username: Ecohubstaff
|
||||
-- Email: ecohubstaff@fileshare.local
|
||||
-- Password: 123
|
||||
-- Role: ADMIN (50 GB Quota)
|
||||
--
|
||||
-- 3. Normal User:
|
||||
-- Username: ecouser
|
||||
-- Email: ecouser@fileshare.local
|
||||
-- Password: 123
|
||||
-- Role: USER (10 GB Quota)
|
||||
-- ======================================================================
|
||||
|
||||
-- Ensure target database is selected
|
||||
CREATE DATABASE IF NOT EXISTS `fileshare_db` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
USE `fileshare_db`;
|
||||
|
||||
-- Temporarily disable foreign key checks during import
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- 1. INSERT OR UPDATE USERS (Table: `User`)
|
||||
-- ----------------------------------------------------------------------
|
||||
INSERT INTO `User` (
|
||||
`id`,
|
||||
`email`,
|
||||
`username`,
|
||||
`fullName`,
|
||||
`companyName`,
|
||||
`passwordHash`,
|
||||
`viewablePassword`,
|
||||
`role`,
|
||||
`status`,
|
||||
`storageQuotaBytes`,
|
||||
`storageUsedBytes`,
|
||||
`canCreateShareLinks`,
|
||||
`canDeleteFiles`,
|
||||
`canViewOtherUsers`,
|
||||
`remoteFileServerUrl`,
|
||||
`canUseRemoteServer`,
|
||||
`createdAt`,
|
||||
`updatedAt`
|
||||
) VALUES
|
||||
-- 1. Superadmin: Ecohub / Ecohub@520
|
||||
(
|
||||
'ecohub-superadmin-uuid-2026-0001',
|
||||
'ecohub@fileshare.local',
|
||||
'ecohub',
|
||||
'Ecohub Super Administrator',
|
||||
'Ecohub Technologies',
|
||||
'$argon2id$v=19$m=65536,t=3,p=4$fmAQcJ4zAtKrzBNnfdWneQ$d3WbQGHsQ+CSwTiOL363uKudXfsFGgS4wFd/jPbenVw',
|
||||
'Ecohub@520',
|
||||
'SUPER_ADMIN',
|
||||
'ACTIVE',
|
||||
107374182400,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
NULL,
|
||||
1,
|
||||
NOW(3),
|
||||
NOW(3)
|
||||
),
|
||||
|
||||
-- 2. Staff Officer: Ecohubstaff / 123
|
||||
(
|
||||
'ecohubstaff-admin-uuid-2026-0002',
|
||||
'ecohubstaff@fileshare.local',
|
||||
'ecohubstaff',
|
||||
'Ecohub Staff Officer',
|
||||
'Ecohub Media & Ops',
|
||||
'$argon2id$v=19$m=65536,t=3,p=4$Mws8SMfU7v9D1Cs8zsN1BA$clCgpd4T/Os+Mp1AGpg61jqIL/UFwnzFivEGd8MWs4k',
|
||||
'123',
|
||||
'ADMIN',
|
||||
'ACTIVE',
|
||||
53687091200,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
NULL,
|
||||
1,
|
||||
NOW(3),
|
||||
NOW(3)
|
||||
),
|
||||
|
||||
-- 3. Normal User: ecouser / 123
|
||||
(
|
||||
'ecouser-normal-uuid-2026-0003',
|
||||
'ecouser@fileshare.local',
|
||||
'ecouser',
|
||||
'Ecohub Standard User',
|
||||
'Ecohub Client Org',
|
||||
'$argon2id$v=19$m=65536,t=3,p=4$Mws8SMfU7v9D1Cs8zsN1BA$clCgpd4T/Os+Mp1AGpg61jqIL/UFwnzFivEGd8MWs4k',
|
||||
'123',
|
||||
'USER',
|
||||
'ACTIVE',
|
||||
10737418240,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
NULL,
|
||||
1,
|
||||
NOW(3),
|
||||
NOW(3)
|
||||
)
|
||||
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`passwordHash` = VALUES(`passwordHash`),
|
||||
`viewablePassword` = VALUES(`viewablePassword`),
|
||||
`role` = VALUES(`role`),
|
||||
`status` = VALUES(`status`),
|
||||
`fullName` = VALUES(`fullName`),
|
||||
`companyName` = VALUES(`companyName`),
|
||||
`storageQuotaBytes` = VALUES(`storageQuotaBytes`),
|
||||
`canCreateShareLinks` = VALUES(`canCreateShareLinks`),
|
||||
`canDeleteFiles` = VALUES(`canDeleteFiles`),
|
||||
`canViewOtherUsers` = VALUES(`canViewOtherUsers`),
|
||||
`remoteFileServerUrl` = VALUES(`remoteFileServerUrl`),
|
||||
`canUseRemoteServer` = VALUES(`canUseRemoteServer`),
|
||||
`updatedAt` = NOW(3);
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- 2. ENSURE ROOT STORAGE FOLDERS EXIST (Table: `Folder`)
|
||||
-- ----------------------------------------------------------------------
|
||||
INSERT INTO `Folder` (
|
||||
`id`,
|
||||
`ownerId`,
|
||||
`parentId`,
|
||||
`name`,
|
||||
`logicalPath`,
|
||||
`createdAt`,
|
||||
`updatedAt`
|
||||
) VALUES
|
||||
('root-folder-ecohub-0001', 'ecohub-superadmin-uuid-2026-0001', NULL, 'Root', '/', NOW(3), NOW(3)),
|
||||
('root-folder-ecohubstaff-0002', 'ecohubstaff-admin-uuid-2026-0002', NULL, 'Root', '/', NOW(3), NOW(3)),
|
||||
('root-folder-ecouser-0003', 'ecouser-normal-uuid-2026-0003', NULL, 'Root', '/', NOW(3), NOW(3))
|
||||
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`logicalPath` = VALUES(`logicalPath`);
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- 3. INITIALIZE DEFAULT SYSTEM SETTINGS (Table: `SystemSetting`)
|
||||
-- ----------------------------------------------------------------------
|
||||
INSERT INTO `SystemSetting` (`id`, `key`, `value`, `description`, `updatedAt`) VALUES
|
||||
(UUID(), 'MAX_FILE_SIZE_BYTES', '5368709120', 'Maximum permitted single file upload size in bytes (5 GB)', NOW(3)),
|
||||
(UUID(), 'DEFAULT_USER_QUOTA_BYTES', '10737418240', 'Default storage quota allocated to newly registered users (10 GB)', NOW(3)),
|
||||
(UUID(), 'ALLOWED_EXTENSIONS', 'mp4,webm,mov,avi,mkv,png,jpg,jpeg,webp,gif,pdf,doc,docx,xls,xlsx,ppt,pptx,zip,rar,7z,tar,gz,mp3,wav,ogg,txt,csv,json', 'Allowed file extensions whitelist', NOW(3)),
|
||||
(UUID(), 'ENABLE_PUBLIC_REGISTRATION', 'true', 'Flag controlling whether new users can self-register', NOW(3)),
|
||||
(UUID(), 'STORAGE_RETENTION_DAYS', '30', 'Soft-deleted file retention duration in recycle bin', NOW(3)),
|
||||
(UUID(), 'STORAGE_BASE_PATH', './storage', 'Dynamic local storage directory location (can be changed by Superadmin anytime)', NOW(3)),
|
||||
(UUID(), 'REMOTE_FILE_SERVER_URL', '', 'Optional Remote File Server Link / URL for external video uploads and mirroring', NOW(3))
|
||||
|
||||
ON DUPLICATE KEY UPDATE
|
||||
`value` = VALUES(`value`);
|
||||
|
||||
-- Re-enable foreign key checks
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
-- Output confirmation notice
|
||||
SELECT 'Ecohub user accounts imported and activated successfully!' AS `Status`;
|
||||
Reference in New Issue
Block a user