Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/juescoryisus/QualityDocD/llms.txt

Use this file to discover all available pages before exploring further.

QualityDocD uses three databases, each serving a distinct purpose. SQL Server 2022 is the primary relational store for documents, users, approval workflows, and audit logs. PostgreSQL 16 holds the structured audit trail and is also used by the Node.js API for companies, users, and document versioning via Drizzle ORM. MongoDB 7 stores rich document metadata and powers full-text search. All three engines are defined in docker-compose.infra.yml, start with health checks, and persist data in named Docker volumes. The application layer handles schema creation automatically on first startup — no manual SQL is required for a standard deployment.

Databases

Container Details

PropertyValue
Container namequalitydoc_sqlserver
Imagemcr.microsoft.com/mssql/server:2022-latest
Host port1433
Edition (MSSQL_PID)Express (default)
Named volumesqlserver_data/var/opt/mssql
Performance SQL dir/docker-entrypoint-sql/ (mounted from ./db/sql)

Automatic Migration

The .NET application (qualitydoc_app) calls db.Database.MigrateAsync() in Program.cs on every startup. EF Core checks the __EFMigrationsHistory table and applies any pending migrations automatically — no manual steps needed on first run.The initial migration is located at:
QualityDocD/Migrations/SqlServer/20260606202353_InitialSqlServer.cs
It creates the following tables in the QualityDocDB database:
  • Users — accounts with roles (VIEWER, COMMENTER, CONTRIBUTOR, OPERATOR, COMPANY_ADMIN, SUPER_ADMIN)
  • Documents — document records with status, versioning, file metadata, and category
  • DocumentApprovals — approval workflow entries linking documents and reviewers
  • AuditLogs — change history for document lifecycle events
The seed data script (db/sql/01_sqlserver_speed.sql) is mounted read-only into the container at /docker-entrypoint-sql/ for manual use. It inserts test users, ten sample documents across all statuses, approval records, and audit log entries.

Manual Migration Command

If you need to apply migrations outside of Docker (e.g., targeting a remote SQL Server), run:
dotnet ef database update --context AppDbContext

Health Check

healthcheck:
  test: ["CMD-SHELL", "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P '${SQLSERVER_SA_PASSWORD}' -Q 'SELECT 1' -No -C"]
  interval: 15s
  timeout:  10s
  retries:  8
  start_period: 30s
SQL Server takes longer to initialize than the other engines. The 30-second start_period and 8 retries allow up to ~150 seconds total before Docker marks the container unhealthy.

Verify Connectivity

docker exec qualitydoc_sqlserver \
  /opt/mssql-tools18/bin/sqlcmd \
  -S localhost -U sa -P 'QualityDoc2026!' \
  -Q 'SELECT name FROM sys.databases' -No -C

Backup and Restore

# Using sqlcmd inside the container
docker exec qualitydoc_sqlserver \
  /opt/mssql-tools18/bin/sqlcmd \
  -S localhost -U sa -P 'QualityDoc2026!' \
  -Q "BACKUP DATABASE QualityDocDB TO DISK='/var/opt/mssql/QualityDocDB.bak' WITH FORMAT"
You can also connect to localhost,1433 with SQL Server Management Studio (SSMS) or Azure Data Studio using sa and the password from your .env file.

Roles Migration

db/sql/03_roles_update.sql expands the Users.Role constraint from 3 legacy values (Admin, Manager, Reviewer) to the current 6-role model. Run it manually after deploying an environment that was initialized with an older schema:
-- db/sql/03_roles_update.sql
USE QualityDocDB;
GO

ALTER TABLE Users DROP CONSTRAINT IF EXISTS CK_Users_Role;
GO

ALTER TABLE Users ADD CONSTRAINT CK_Users_Role
  CHECK (Role IN ('VIEWER','COMMENTER','CONTRIBUTOR','OPERATOR','COMPANY_ADMIN','SUPER_ADMIN'));
GO

UPDATE Users SET Role = 'SUPER_ADMIN'   WHERE Role = 'Admin';
UPDATE Users SET Role = 'COMPANY_ADMIN' WHERE Role = 'Manager';
UPDATE Users SET Role = 'OPERATOR'      WHERE Role = 'Reviewer';
UPDATE Users SET Role = 'CONTRIBUTOR'   WHERE Role = 'Editor';
UPDATE Users SET Role = 'VIEWER'        WHERE Role = 'Viewer';
GO
docker exec -i qualitydoc_sqlserver \
  /opt/mssql-tools18/bin/sqlcmd \
  -S localhost -U sa -P 'QualityDoc2026!' \
  -i /docker-entrypoint-sql/03_roles_update.sql -No -C

Migration Summary

DatabaseMigration toolTriggered byMigration location
SQL Server (QualityDocDB)EF Core (AppDbContext).NET app startup (MigrateAsync)QualityDocD/Migrations/SqlServer/
PostgreSQL (qualitydoc_audit)EF Core (AuditDbContext).NET app startup (MigrateAsync)QualityDocD/Migrations/AuditDb/
PostgreSQL (Node.js tables)Drizzle ORMManual: npm run db:pushnode-api/schema/
MongoDB (qualitydoc_meta)Init scriptFirst container startdb/mongodb/init.js

Resetting All Data

The command below permanently deletes all three database volumes (sqlserver_data, postgres_data, mongodb_data). Every table, collection, and stored file reference will be erased. There is no undo — make a backup first if you need to preserve any data.
# Stop infra and delete all named volumes
docker compose -f docker-compose.infra.yml down -v

# Optionally also stop the app layer first
docker compose -f docker-compose.apps.yml down
docker compose -f docker-compose.portal.yml down

# Then restart everything from scratch
docker compose -f docker-compose.infra.yml up -d
docker compose -f docker-compose.apps.yml up -d
docker compose -f docker-compose.portal.yml up -d
On next startup, EF Core migrations re-create all SQL Server and PostgreSQL schemas, and the MongoDB init script re-creates the document_metadata collection with all indexes. The .NET app also re-seeds the default test users into SQL Server. Using setup.ps1 on Windows, the equivalent is:
.\setup.ps1 -Mode All -ResetData

Build docs developers (and LLMs) love