The ServiciosYa API stores all persistent state — users, companies, services, service requests, payments, and audit trails — in a SQL Server database namedDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/CodexaCP/SERVICIOS-BACK/llms.txt
Use this file to discover all available pages before exploring further.
EncomiendasDB. All business rules are enforced by a set of stored procedures that the API calls through Dapper; there is no ORM-generated schema. This guide walks you through creating the database and running every migration in the correct order.
Prerequisites
- SQL Server — Express edition or full. SQL Server 2019 or later is recommended.
- Client tooling — either SQL Server Management Studio (SSMS) or the
sqlcmdcommand-line utility. - The migration files located in
Database/Migrations/of the repository.
Step 1 — Create the database
Connect to your SQL Server instance and run:Trusted_Connection=True with a dedicated SQL login. See the Production note at the bottom of this page.Step 2 — Run migrations in order
Run each file withsqlcmd:
EncomiendasDB, and execute.
Migration files
2026-04-20_auth_customer.sql — User authentication and customer tables
RegisterCustomerUser and ChangeUserPassword stored procedures. Establishes the baseline user-registration logic, SHA-256 password hashing, and the initial audit hook to dbo.InsertAuditLog.2026-04-20_services_hardening.sql — Services and service-request hardening
MustChangePassword column to dbo.[User] and soft-delete columns (IsDeleted, DeletedAt, DeletedBy) to dbo.Services. Creates or replaces the core stored procedures: Auth_Login, CreateService, UpdateService, ToggleServiceStatus, DeleteService, GetServices, GetServicesByCategory, CreateServiceRequest, GetUserServiceRequests, GetServiceRequestsAdmin, GetServiceRequestById, CreateServiceRequestAttachment, UpdateServiceRequestStatus, and ValidateServiceRequestPayment.2026-04-21_company1_default_services.sql — Base ServiciosYa company and default services
2026-04-21_internal_user_registration.sql — Internal user registration stored procedure
ADMIN_GENERAL, GESTOR_SUPREMO, GESTOR, CUSTOMER) with role-hierarchy enforcement.2026-04-22_role_hierarchy.sql — Final role hierarchy setup
SUPER_ADMIN, ADMIN_GENERAL, GESTOR_SUPREMO, GESTOR, CUSTOMER) exist in dbo.Role and creates the initial SUPER_ADMIN account if none is present.2026-04-26_cancellation_refund_notifications.sql — Cancellation and refund notifications
2026-04-26_cancelled_user_payments.sql — Cancelled-user payment tracking
PENDIENTE_DEVOLUCION → REINTEGRADO refund flow.2026-04-26_invoice_requirement.sql — Invoice requirement flag
RequiresInvoice, RazonSocial, and RUC fields to dbo.ServiceRequests so customers can request an invoice at the time of submission.2026-04-26_payment_action_and_service_delete_rules.sql — Payment action and service delete rules
2026-04-27_audit_pro_and_diagnostics.sql — AuditEvents and AuditChanges tables
dbo.AuditEvents and dbo.AuditChanges plus five covering indexes (IX_AuditEvents_TimestampUtc, IX_AuditEvents_CompanyId_TimestampUtc, IX_AuditEvents_UserId_TimestampUtc, IX_AuditEvents_CorrelationId, IX_AuditEvents_IsVisibleForAdmins_TimestampUtc). This migration is idempotent — it uses IF OBJECT_ID(...) IS NULL guards.2026-04-28_fix_getauditlogs_cte_scope.sql — Fix GetAuditLogs CTE scope
dbo.GetAuditLogs stored procedure to eliminate a CTE-reuse bug. The revised version materialises filtered rows into a temporary table (#AuditFiltered) before counting and paging, which is required by SQL Server.2026-04-30_production_versioning_and_user_deletion.sql — Production versioning and user deletion
PendingDeletion instead of being removed immediately.2026-05-25_role_hierarchy_alignment.sql — Role hierarchy alignment
2026-05-25_service_request_snapshots.sql — Service request snapshots
2026-05-26_custom_service_requests.sql — Custom service requests
2026-05-31_tramiya_default_user_registration.sql — Tramiya default user registration
company1_default_services.sql.2026-06-01_service_request_delivery_attachment.sql — Delivery attachment
DeliveryAttachmentUrl column to dbo.ServiceRequests and the stored procedure that sets it, used by the POST /api/servicerequests/{id}/delivery-attachment endpoint.Key stored procedures
The following stored procedures are the primary interface between the API and the database. All are created or replaced by the migrations above.| Stored Procedure | Module | Description |
|---|---|---|
Auth_Login | Auth | Validates credentials, returns user/role/company, logs audit entry |
RegisterCustomerUser | Auth | Self-registration or actor-driven customer creation |
ChangeUserPassword | Auth | Changes password after verifying the current one |
CreateService | Services | Creates a new service; enforces role and name uniqueness |
UpdateService | Services | Updates service fields; preserves old values in audit log |
ToggleServiceStatus | Services | Flips IsActive; records status-change audit entry |
DeleteService | Services | Logical delete (IsDeleted = 1); only SUPER_ADMIN |
GetServices | Services | Paginated admin list with search and active filter |
GetServicesByCategory | Services | Active services filtered by category, for customer use |
CreateServiceRequest | Requests | Creates request + ServiceRequestPayments with PENDIENTE status |
GetUserServiceRequests | Requests | Customer’s own request history |
GetServiceRequestsAdmin | Requests | Paginated admin view with user and service join |
GetServiceRequestById | Requests | Full detail for a single request |
CreateServiceRequestAttachment | Requests | Attaches an optional file; enforces PermiteAdjunto = 1 |
UpdateServiceRequestStatus | Requests | State-machine transitions enforced by role |
ValidateServiceRequestPayment | Payments | Approves or rejects payment; advances or cancels request |
InsertAuditLog | Audit | Writes a legacy audit row; called internally by all other procs |
sqlcmd one-liner for a single migration
Production note
AvoidTrusted_Connection in production. Create a dedicated SQL login with the minimum permissions required:
appsettings.json: