feat(bd): V020 permiso + V022 seed ChargeableCharConfig (PRC-001)
This commit is contained in:
33
database/migrations/V020_ROLLBACK.sql
Normal file
33
database/migrations/V020_ROLLBACK.sql
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
-- V020_ROLLBACK.sql
|
||||||
|
-- PRC-001: Reversa de V020__add_chargeable_chars_permission.sql.
|
||||||
|
--
|
||||||
|
-- Pasos:
|
||||||
|
-- 1. Elimina la asignación del permiso al rol 'admin'.
|
||||||
|
-- 2. Elimina el permiso del catálogo.
|
||||||
|
--
|
||||||
|
-- ADVERTENCIA: si algún usuario o rol tiene este permiso asignado explícitamente,
|
||||||
|
-- la FK de RolPermiso causará error. Limpiar RolPermiso primero.
|
||||||
|
-- Run on: SIGCM2 (dev), SIGCM2_Test_App, SIGCM2_Test_Api.
|
||||||
|
|
||||||
|
SET QUOTED_IDENTIFIER ON;
|
||||||
|
SET ANSI_NULLS ON;
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- 1. Eliminar asignaciones del permiso a cualquier rol.
|
||||||
|
DELETE rp
|
||||||
|
FROM dbo.RolPermiso rp
|
||||||
|
JOIN dbo.Permiso p ON p.Id = rp.PermisoId
|
||||||
|
WHERE p.Codigo = 'tasacion:caracteres_especiales:gestionar';
|
||||||
|
PRINT 'V020 rollback: RolPermiso entries for tasacion:caracteres_especiales:gestionar removed.';
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- 2. Eliminar el permiso del catálogo.
|
||||||
|
DELETE FROM dbo.Permiso
|
||||||
|
WHERE Codigo = 'tasacion:caracteres_especiales:gestionar';
|
||||||
|
PRINT 'V020 rollback: Permiso tasacion:caracteres_especiales:gestionar removed.';
|
||||||
|
GO
|
||||||
|
|
||||||
|
PRINT '';
|
||||||
|
PRINT 'V020 rollback complete.';
|
||||||
|
GO
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
-- V020__add_chargeable_chars_permission.sql
|
||||||
|
-- PRC-001: permiso RBAC para ABM de caracteres tasables.
|
||||||
|
--
|
||||||
|
-- Cambios:
|
||||||
|
-- 1. Agrega permiso 'tasacion:caracteres_especiales:gestionar' al catálogo.
|
||||||
|
-- 2. Asigna el permiso al rol 'admin'.
|
||||||
|
--
|
||||||
|
-- Convención RBAC: modulo:recurso:accion.
|
||||||
|
-- Patrón: V007 (MERGE idempotente).
|
||||||
|
-- Idempotente: seguro para re-ejecutar.
|
||||||
|
-- Reversa: V020_ROLLBACK.sql.
|
||||||
|
-- Run on: SIGCM2 (dev), SIGCM2_Test_App, SIGCM2_Test_Api.
|
||||||
|
--
|
||||||
|
-- NOTA: V020 se ejecuta ANTES de V021 (tabla) porque el permiso debe existir
|
||||||
|
-- antes de que la API arranque con [RequirePermission(...)].
|
||||||
|
-- V021 crea la tabla dbo.ChargeableCharConfig.
|
||||||
|
-- V022 siembra las 4 filas globales por defecto.
|
||||||
|
--
|
||||||
|
-- SDD Design: engram sdd/prc-001-word-counter-spike/design (D16/D17)
|
||||||
|
|
||||||
|
SET QUOTED_IDENTIFIER ON;
|
||||||
|
SET ANSI_NULLS ON;
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Agregar permiso al catálogo (idempotente via MERGE).
|
||||||
|
MERGE dbo.Permiso AS t
|
||||||
|
USING (VALUES
|
||||||
|
('tasacion:caracteres_especiales:gestionar',
|
||||||
|
N'Gestionar caracteres tasables',
|
||||||
|
N'Crear, editar precio y desactivar la configuración de caracteres especiales para tasación.',
|
||||||
|
'tasacion')
|
||||||
|
) AS s (Codigo, Nombre, Descripcion, Modulo)
|
||||||
|
ON t.Codigo = s.Codigo
|
||||||
|
WHEN NOT MATCHED BY TARGET THEN
|
||||||
|
INSERT (Codigo, Nombre, Descripcion, Modulo)
|
||||||
|
VALUES (s.Codigo, s.Nombre, s.Descripcion, s.Modulo);
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Asignar a rol 'admin' (idempotente via MERGE).
|
||||||
|
MERGE dbo.RolPermiso AS t
|
||||||
|
USING (
|
||||||
|
SELECT r.Id AS RolId, p.Id AS PermisoId
|
||||||
|
FROM dbo.Rol r
|
||||||
|
CROSS JOIN dbo.Permiso p
|
||||||
|
WHERE r.Codigo = 'admin'
|
||||||
|
AND p.Codigo = 'tasacion:caracteres_especiales:gestionar'
|
||||||
|
) AS s ON t.RolId = s.RolId AND t.PermisoId = s.PermisoId
|
||||||
|
WHEN NOT MATCHED BY TARGET THEN
|
||||||
|
INSERT (RolId, PermisoId) VALUES (s.RolId, s.PermisoId);
|
||||||
|
GO
|
||||||
|
|
||||||
|
PRINT 'V020 applied — tasacion:caracteres_especiales:gestionar added to catalog and assigned to admin.';
|
||||||
|
GO
|
||||||
23
database/migrations/V022_ROLLBACK.sql
Normal file
23
database/migrations/V022_ROLLBACK.sql
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
-- V022_ROLLBACK.sql
|
||||||
|
-- PRC-001: Reversa de V022__seed_chargeable_char_config.sql.
|
||||||
|
--
|
||||||
|
-- Elimina las 4 filas globales de seed (MedioId NULL, símbolos $/%/!/¡, ValidTo NULL).
|
||||||
|
-- Solo elimina las filas vigentes (ValidTo IS NULL) para no romper el historial temporal.
|
||||||
|
--
|
||||||
|
-- ADVERTENCIA: si alguna de estas filas fue cerrada (ValidTo SET), el rollback las ignora
|
||||||
|
-- (ya no son vigentes). La historia temporal queda intacta.
|
||||||
|
-- Run on: SIGCM2 (dev), SIGCM2_Test_App, SIGCM2_Test_Api.
|
||||||
|
|
||||||
|
SET QUOTED_IDENTIFIER ON;
|
||||||
|
SET ANSI_NULLS ON;
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
GO
|
||||||
|
|
||||||
|
DELETE FROM dbo.ChargeableCharConfig
|
||||||
|
WHERE MedioId IS NULL
|
||||||
|
AND Symbol IN (N'$', N'%', N'!', N'¡')
|
||||||
|
AND ValidTo IS NULL;
|
||||||
|
GO
|
||||||
|
|
||||||
|
PRINT 'V022 rollback complete — global seed rows ($, %, !, ¡) removed.';
|
||||||
|
GO
|
||||||
44
database/migrations/V022__seed_chargeable_char_config.sql
Normal file
44
database/migrations/V022__seed_chargeable_char_config.sql
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
-- V022__seed_chargeable_char_config.sql
|
||||||
|
-- PRC-001: seed de las 4 configuraciones globales de caracteres tasables por defecto.
|
||||||
|
--
|
||||||
|
-- Cambios:
|
||||||
|
-- 1. Inserta 4 filas globales (MedioId NULL): $, %, !, ¡ — precios placeholder 1.0000.
|
||||||
|
-- El equipo de negocio seteará los valores reales desde el CMS.
|
||||||
|
--
|
||||||
|
-- Patrón: MERGE idempotente ON (MedioId IS NULL AND Symbol AND ValidTo IS NULL).
|
||||||
|
-- Idempotente: seguro para re-ejecutar.
|
||||||
|
-- Reversa: V022_ROLLBACK.sql.
|
||||||
|
-- Run on: SIGCM2 (dev), SIGCM2_Test_App, SIGCM2_Test_Api.
|
||||||
|
--
|
||||||
|
-- Depends on: V021 (dbo.ChargeableCharConfig must exist).
|
||||||
|
--
|
||||||
|
-- Notas:
|
||||||
|
-- - MedioId NULL = global fallback; aplica a todos los medios a menos que exista
|
||||||
|
-- una fila per-medio más específica (resolución en usp_ChargeableCharConfig_GetActiveForMedio).
|
||||||
|
-- - ValidFrom = 2026-01-01: retroactivo al inicio del año fiscal 2026.
|
||||||
|
-- - ValidTo NULL = vigente (sin fecha de cierre).
|
||||||
|
-- - PricePerUnit 1.0000 son placeholders — CONFIRMAR con el área de tasación.
|
||||||
|
--
|
||||||
|
-- SDD Design: engram sdd/prc-001-word-counter-spike/design (§3.3)
|
||||||
|
|
||||||
|
SET QUOTED_IDENTIFIER ON;
|
||||||
|
SET ANSI_NULLS ON;
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
GO
|
||||||
|
|
||||||
|
MERGE dbo.ChargeableCharConfig AS t
|
||||||
|
USING (VALUES
|
||||||
|
(NULL, N'$', N'Currency', CAST(1.0000 AS DECIMAL(18,4)), CAST('2026-01-01' AS DATE)),
|
||||||
|
(NULL, N'%', N'Percentage', CAST(1.0000 AS DECIMAL(18,4)), CAST('2026-01-01' AS DATE)),
|
||||||
|
(NULL, N'!', N'Exclamation', CAST(1.0000 AS DECIMAL(18,4)), CAST('2026-01-01' AS DATE)),
|
||||||
|
(NULL, N'¡', N'Exclamation', CAST(1.0000 AS DECIMAL(18,4)), CAST('2026-01-01' AS DATE))
|
||||||
|
) AS s (MedioId, Symbol, Category, PricePerUnit, ValidFrom)
|
||||||
|
ON (t.MedioId IS NULL AND s.MedioId IS NULL AND t.Symbol = s.Symbol AND t.ValidTo IS NULL)
|
||||||
|
WHEN NOT MATCHED THEN
|
||||||
|
INSERT (MedioId, Symbol, Category, PricePerUnit, ValidFrom, ValidTo, IsActive)
|
||||||
|
VALUES (s.MedioId, s.Symbol, s.Category, s.PricePerUnit, s.ValidFrom, NULL, 1);
|
||||||
|
GO
|
||||||
|
|
||||||
|
PRINT 'V022 applied — 4 global ChargeableCharConfig defaults seeded ($, %, !, ¡).';
|
||||||
|
PRINT 'NOTE: PricePerUnit values are placeholders (1.0000). Update via CMS before going live.';
|
||||||
|
GO
|
||||||
Reference in New Issue
Block a user