在客户 loopback.io 项目中,我需要跟踪/审核并提供撤消/重做功能,我发现最好的方法是 SCD 方法。
我在这里找到了一些东西:https ://en.wikipedia.org/wiki/Slowly_changeing_dimension然后我创建了这个模型:
-------------------------------------------------
CREATE VIEW vw_trackedinvoice AS
SELECT
ivp.id AS id,
ivp.code AS code,
ivp.idCustomer AS idCustomer,
trk.id AS trkid,
trk.idSession AS idSession,
trk.isCurrent AS isCurrent,
trk.tableName AS tableName,
trk.tableCode AS tableCode,
trk.tableId AS tableId,
trk.dtIni AS dtIni,
trk.dtEnd AS dtEnd,
trk.dtDel AS dtDel
FROM
(invoiceversionprovider ivp
JOIN scdtrack trk ON ((ivp.idscd = trk.id)))
WHERE
(trk.tableName = 'invoiceversionprovider');
-------------------------------------------------
CREATE VIEW vw_trackedinvoicedetail AS
SELECT
idp.id AS id,
idp.code AS code,
idp.codeInvoice AS codeInvoice,
idp.idProduct AS idProduct,
idp.qtd AS qtd,
trk.id AS trkid,
trk.idSession AS idSession,
trk.isCurrent AS isCurrent,
trk.tableName AS tableName,
trk.tableCode AS tableCode,
trk.tableId AS tableId,
trk.dtIni AS dtIni,
trk.dtEnd AS dtEnd,
trk.dtDel AS dtDel
FROM
(invoicedetailversionprovider idp
JOIN scdtrack trk ON ((idp.idscd = trk.id)))
WHERE
(trk.tableName = 'invoicedetailversionprovider');
-------------------------------------------------
CREATE VIEW vw_currentinvoice AS
SELECT
trki.id AS id,
trki.code AS code,
trki.idCustomer AS idCustomer,
trki.trkid AS trkid
FROM
vw_trackedinvoice trki
WHERE
((trki.isCurrent = 1)
AND ISNULL(trki.dtDel));
-------------------------------------------------
CREATE VIEW vw_currentinvoicedetail AS
SELECT
trkid.id AS id,
trkid.code AS code,
trkid.codeInvoice AS codeInvoice,
trkid.idProduct AS idProduct,
trkid.qtd AS qtd,
trkid.trkid AS trkid
FROM
vw_trackedinvoicedetail trkid
WHERE
((trkid.isCurrent = 1)
AND ISNULL(trkid.dtDel));
-------------------------------------------------
有一些更好的正式模式来做吗?
我对SCD真的很陌生,希望有更多经验的人能看到它。