@prisma-next/family-sql 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/control.d.mts +1 -1
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +99 -55
- package/dist/control.mjs.map +1 -1
- package/dist/ir.d.mts +5 -41
- package/dist/ir.d.mts.map +1 -1
- package/dist/ir.mjs +1 -1
- package/dist/migration.d.mts +1 -1
- package/dist/schema-verify.d.mts.map +1 -1
- package/dist/schema-verify.mjs +1 -1
- package/dist/{sql-contract-serializer-qUQCnP-k.mjs → sql-contract-serializer-C6ypWJYR.mjs} +22 -43
- package/dist/sql-contract-serializer-C6ypWJYR.mjs.map +1 -0
- package/dist/{types-DMINfGUO.d.mts → types-hQoMXr54.d.mts} +4 -3
- package/dist/types-hQoMXr54.d.mts.map +1 -0
- package/dist/verify-sql-schema-Bfvz07Ik.d.mts.map +1 -1
- package/dist/{verify-sql-schema-BXw7yx6L.mjs → verify-sql-schema-Bj4Wqe2c.mjs} +99 -63
- package/dist/verify-sql-schema-Bj4Wqe2c.mjs.map +1 -0
- package/package.json +21 -21
- package/src/core/control-instance.ts +11 -4
- package/src/core/ir/sql-contract-serializer-base.ts +58 -47
- package/src/core/migrations/contract-to-schema-ir.ts +82 -33
- package/src/core/migrations/field-event-planner.ts +53 -29
- package/src/core/migrations/types.ts +2 -1
- package/src/core/psl-contract-infer/sql-schema-ir-to-psl-ast.ts +17 -3
- package/src/core/schema-verify/verify-helpers.ts +44 -14
- package/src/core/schema-verify/verify-sql-schema.ts +106 -47
- package/dist/sql-contract-serializer-qUQCnP-k.mjs.map +0 -1
- package/dist/types-DMINfGUO.d.mts.map +0 -1
- package/dist/verify-sql-schema-BXw7yx6L.mjs.map +0 -1
package/dist/control.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SqlPlannerConflictKind, C as SqlMigrationRunnerExecuteCallbacks, D as SqlMigrationRunnerSuccessValue, E as SqlMigrationRunnerResult, F as StorageTypePlanResult, I as SqlControlFamilyInstance, M as SqlPlannerFailureResult, N as SqlPlannerResult, O as SqlPlanTargetDetails, P as SqlPlannerSuccessResult, S as SqlMigrationRunnerErrorCode, T as SqlMigrationRunnerFailure, _ as SqlMigrationPlanOperationStep, a as FieldEvent, b as SqlMigrationPlannerPlanOptions, c as MultiSpaceRunnerResult, d as SqlControlAdapterDescriptor, f as SqlControlExtensionDescriptor, g as SqlMigrationPlanOperation, h as SqlMigrationPlanContractInfo, i as ExpandNativeTypeInput, j as SqlPlannerConflictLocation, k as SqlPlannerConflict, l as MultiSpaceRunnerSuccessValue, m as SqlMigrationPlan, n as CodecControlHooks, o as FieldEventContext, p as SqlControlTargetDescriptor, r as CreateSqlMigrationPlanOptions, s as MultiSpaceRunnerFailure, t as AnyRecord, u as ResolveIdentityValueInput, v as SqlMigrationPlanOperationTarget, w as SqlMigrationRunnerExecuteOptions, x as SqlMigrationRunner, y as SqlMigrationPlanner } from "./types-
|
|
1
|
+
import { A as SqlPlannerConflictKind, C as SqlMigrationRunnerExecuteCallbacks, D as SqlMigrationRunnerSuccessValue, E as SqlMigrationRunnerResult, F as StorageTypePlanResult, I as SqlControlFamilyInstance, M as SqlPlannerFailureResult, N as SqlPlannerResult, O as SqlPlanTargetDetails, P as SqlPlannerSuccessResult, S as SqlMigrationRunnerErrorCode, T as SqlMigrationRunnerFailure, _ as SqlMigrationPlanOperationStep, a as FieldEvent, b as SqlMigrationPlannerPlanOptions, c as MultiSpaceRunnerResult, d as SqlControlAdapterDescriptor, f as SqlControlExtensionDescriptor, g as SqlMigrationPlanOperation, h as SqlMigrationPlanContractInfo, i as ExpandNativeTypeInput, j as SqlPlannerConflictLocation, k as SqlPlannerConflict, l as MultiSpaceRunnerSuccessValue, m as SqlMigrationPlan, n as CodecControlHooks, o as FieldEventContext, p as SqlControlTargetDescriptor, r as CreateSqlMigrationPlanOptions, s as MultiSpaceRunnerFailure, t as AnyRecord, u as ResolveIdentityValueInput, v as SqlMigrationPlanOperationTarget, w as SqlMigrationRunnerExecuteOptions, x as SqlMigrationRunner, y as SqlMigrationPlanner } from "./types-hQoMXr54.mjs";
|
|
2
2
|
import { ControlFamilyDescriptor, ControlStack, MigrationOperationClass, MigrationOperationPolicy, MigrationOperationPolicy as MigrationOperationPolicy$1, MigrationPlan, MigrationPlanOperation, MigrationPlanner, MigrationPlannerConflict, MigrationPlannerConflict as MigrationPlannerConflict$1, MigrationPlannerResult, MutationDefaultGeneratorDescriptor, OpFactoryCall, TargetMigrationsCapability, assembleAuthoringContributions } from "@prisma-next/framework-components/control";
|
|
3
3
|
import { SqlStorage, StorageColumn } from "@prisma-next/sql-contract/types";
|
|
4
4
|
import { NotOk, Ok } from "@prisma-next/utils/result";
|
package/dist/control.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/field-event-planner.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;cAUa,mBAAA,YACA,uBAAA,QAA+B,wBAAA;EAAA,SAEjC,IAAA;EAAA,SACA,EAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA,EAAU,WAAA;EAAA,SACV,SAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKT,MAAA,0BAAA,CACE,KAAA,EAAO,YAAA,QAAoB,SAAA,IAC1B,wBAAA;AAAA;;;iBCHW,wBAAA,CACd,WAAA,EAAa,aAAA,CAAc,8BAAA,mBAC1B,GAAA,SAAY,iBAAA;;;;;;;;;ADdf;;;;KE2BY,kBAAA,IAAsB,KAAA;EAAA,SACvB,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAA;AAAA;;;;;;;;;;KAYZ,eAAA,IAAmB,GAAA,EAAK,aAAA,EAAe,MAAA,EAAQ,aAAA;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/field-event-planner.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;cAUa,mBAAA,YACA,uBAAA,QAA+B,wBAAA;EAAA,SAEjC,IAAA;EAAA,SACA,EAAA;EAAA,SACA,QAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA,EAAU,WAAA;EAAA,SACV,SAAA;IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAKT,MAAA,0BAAA,CACE,KAAA,EAAO,YAAA,QAAoB,SAAA,IAC1B,wBAAA;AAAA;;;iBCHW,wBAAA,CACd,WAAA,EAAa,aAAA,CAAc,8BAAA,mBAC1B,GAAA,SAAY,iBAAA;;;;;;;;;ADdf;;;;KE2BY,kBAAA,IAAsB,KAAA;EAAA,SACvB,UAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA,GAAa,MAAA;AAAA;;;;;;;;;;KAYZ,eAAA,IAAmB,GAAA,EAAK,aAAA,EAAe,MAAA,EAAQ,aAAA;;;;;;;;;;iBAgK3C,wBAAA,CACd,IAAA,EAAM,UAAA,SACN,EAAA,EAAI,UAAA,YACM,0BAAA;AAAA,UA8CK,yBAAA;EAAA,SACN,mBAAA;EAAA,SACA,gBAAA,GAAmB,kBAAA;EAAA,SACnB,aAAA,GAAgB,eAAA;AAAA;;;;;;;;;;;;;;;iBAiBX,kBAAA,CACd,QAAA,EAAU,QAAA,CAAS,UAAA,UACnB,OAAA,EAAS,yBAAA,GACR,WAAA;;;UC/Pc,+BAAA;EHZI;;;;EAAA,SGiBV,aAAA,EAAe,QAAA,CAAS,UAAA;;;;WAIxB,WAAA,EAAa,QAAA,CAAS,UAAA;;;;;;;;;;WAUtB,UAAA,EAAY,WAAA,SAAoB,iBAAA;AAAA;AAAA,iBAa3B,wBAAA,CACd,OAAA,EAAS,+BAAA,YACC,aAAA;;;iBCgCI,mBAAA,gBAAA,CACd,OAAA,EAAS,6BAAA,CAA8B,cAAA,IACtC,gBAAA,CAAiB,cAAA;AAAA,iBAcJ,cAAA,gBAAA,CACd,IAAA,EAAM,gBAAA,CAAiB,cAAA,IACtB,uBAAA,CAAwB,cAAA;AAAA,iBAOX,cAAA,CAAe,SAAA,WAAoB,kBAAA,KAAuB,uBAAA;;;;iBAoB1D,aAAA,CAAc,KAAA;EAC5B,iBAAA;EACA,kBAAA;AAAA,IACE,EAAA,CAAG,8BAAA;;;;iBAYS,aAAA,CACd,IAAA,EAAM,2BAAA,EACN,OAAA,UACA,OAAA;EAAY,GAAA;EAAc,IAAA,GAAO,SAAA;AAAA,IAChC,KAAA,CAAM,yBAAA;;;;;;cC1JI,oBAAA,EAAsB,0BAAA;;;;;;;;;;;;;;iBCsBnB,6BAAA,CAAA,GAAiC,kCAAA;;;;;;;;;;;iBAoBjC,wBAAA,+DAAA,CAGd,KAAA;EAAA,SAAkB,OAAA,EAAS,OAAA;EAAA,SAAkB,UAAA,EAAY,UAAA;AAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCyBlB,QAAA"}
|
package/dist/control.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as sqlFamilyAuthoringFieldPresets, t as sqlFamilyAuthoringTypes } from "./authoring-type-constructors-F4JpCJl7.mjs";
|
|
2
|
-
import { t as SqlContractSerializer } from "./sql-contract-serializer-
|
|
3
|
-
import { a as extractCodecControlHooks, t as verifySqlSchema } from "./verify-sql-schema-
|
|
2
|
+
import { t as SqlContractSerializer } from "./sql-contract-serializer-C6ypWJYR.mjs";
|
|
3
|
+
import { a as extractCodecControlHooks, t as verifySqlSchema } from "./verify-sql-schema-Bj4Wqe2c.mjs";
|
|
4
4
|
import { t as collectSupportedCodecTypeIds } from "./verify-Crewz6hG.mjs";
|
|
5
5
|
import { n as temporalAuthoringPresets, r as timestampNowControlDescriptor } from "./timestamp-now-generator-r7BP5n3l.mjs";
|
|
6
6
|
import { sqlEmission } from "@prisma-next/sql-contract-emitter";
|
|
@@ -9,7 +9,8 @@ import { assertDescriptorSelfConsistency } from "@prisma-next/migration-tools/sp
|
|
|
9
9
|
import { ensureSchemaStatement, ensureTableStatement, writeContractMarker } from "@prisma-next/sql-runtime";
|
|
10
10
|
import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
|
|
11
11
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
12
|
-
import { isPostgresEnumStorageEntry, isStorageTypeInstance, toStorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
12
|
+
import { StorageTable, isPostgresEnumStorageEntry, isStorageTypeInstance, toStorageTypeInstance } from "@prisma-next/sql-contract/types";
|
|
13
|
+
import { UNSPECIFIED_PSL_NAMESPACE_ID } from "@prisma-next/framework-components/psl-ast";
|
|
13
14
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
14
15
|
//#region src/core/operation-preview.ts
|
|
15
16
|
function isDdlStatement(sqlStatement) {
|
|
@@ -657,9 +658,14 @@ function buildPslDocumentAst(schemaIR, options) {
|
|
|
657
658
|
return {
|
|
658
659
|
kind: "document",
|
|
659
660
|
sourceId: "<sql-schema-ir>",
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
661
|
+
namespaces: [{
|
|
662
|
+
kind: "namespace",
|
|
663
|
+
name: UNSPECIFIED_PSL_NAMESPACE_ID,
|
|
664
|
+
models: sortedModels,
|
|
665
|
+
enums,
|
|
666
|
+
compositeTypes: [],
|
|
667
|
+
span: SYNTHETIC_SPAN
|
|
668
|
+
}],
|
|
663
669
|
...types ? { types } : {},
|
|
664
670
|
span: SYNTHETIC_SPAN
|
|
665
671
|
};
|
|
@@ -1012,10 +1018,12 @@ function topologicalSort(models, tables, modelNameMap) {
|
|
|
1012
1018
|
//#region src/core/control-instance.ts
|
|
1013
1019
|
function extractCodecTypeIdsFromContract(contract) {
|
|
1014
1020
|
const typeIds = /* @__PURE__ */ new Set();
|
|
1015
|
-
if (typeof contract === "object" && contract !== null && "storage" in contract && typeof contract.storage === "object" && contract.storage !== null && "
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
|
|
1021
|
+
if (typeof contract === "object" && contract !== null && "storage" in contract && typeof contract.storage === "object" && contract.storage !== null && "namespaces" in contract.storage && typeof contract.storage.namespaces === "object" && contract.storage.namespaces !== null) {
|
|
1022
|
+
const namespaces = contract.storage.namespaces;
|
|
1023
|
+
for (const ns of Object.values(namespaces)) {
|
|
1024
|
+
const tbls = ns.tables;
|
|
1025
|
+
if (typeof tbls !== "object" || tbls === null) continue;
|
|
1026
|
+
for (const table of Object.values(tbls)) if (typeof table === "object" && table !== null && "columns" in table && typeof table.columns === "object" && table.columns !== null) {
|
|
1019
1027
|
const columns = table.columns;
|
|
1020
1028
|
for (const column of Object.values(columns)) if (column && typeof column === "object" && "codecId" in column && typeof column.codecId === "string") typeIds.add(column.codecId);
|
|
1021
1029
|
}
|
|
@@ -1453,9 +1461,10 @@ function convertIndex(index) {
|
|
|
1453
1461
|
}
|
|
1454
1462
|
function convertForeignKey(fk) {
|
|
1455
1463
|
return {
|
|
1456
|
-
columns: fk.columns,
|
|
1457
|
-
referencedTable: fk.
|
|
1458
|
-
|
|
1464
|
+
columns: fk.source.columns,
|
|
1465
|
+
referencedTable: fk.target.tableName,
|
|
1466
|
+
referencedSchema: fk.target.namespaceId,
|
|
1467
|
+
referencedColumns: fk.target.columns,
|
|
1459
1468
|
...ifDefined("name", fk.name)
|
|
1460
1469
|
};
|
|
1461
1470
|
}
|
|
@@ -1470,12 +1479,12 @@ function convertTable(name, table, storageTypes, expandNativeType, renderDefault
|
|
|
1470
1479
|
const fkBackingIndexes = [];
|
|
1471
1480
|
for (const fk of table.foreignKeys) {
|
|
1472
1481
|
if (fk.index === false) continue;
|
|
1473
|
-
const key = fk.columns.join(",");
|
|
1482
|
+
const key = fk.source.columns.join(",");
|
|
1474
1483
|
if (satisfiedIndexColumns.has(key)) continue;
|
|
1475
1484
|
fkBackingIndexes.push({
|
|
1476
|
-
columns: fk.columns,
|
|
1485
|
+
columns: fk.source.columns,
|
|
1477
1486
|
unique: false,
|
|
1478
|
-
name: defaultIndexName(name, fk.columns)
|
|
1487
|
+
name: defaultIndexName(name, fk.source.columns)
|
|
1479
1488
|
});
|
|
1480
1489
|
satisfiedIndexColumns.add(key);
|
|
1481
1490
|
}
|
|
@@ -1501,21 +1510,30 @@ function detectDestructiveChanges(from, to) {
|
|
|
1501
1510
|
if (!from) return [];
|
|
1502
1511
|
const hasOwn = (value, key) => Object.hasOwn(value, key);
|
|
1503
1512
|
const conflicts = [];
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1513
|
+
const namespaceIds = [...new Set([...Object.keys(from.namespaces), ...Object.keys(to.namespaces)])].sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
1514
|
+
for (const namespaceId of namespaceIds) {
|
|
1515
|
+
const fromNs = from.namespaces[namespaceId];
|
|
1516
|
+
const toNs = to.namespaces[namespaceId];
|
|
1517
|
+
const fromTables = fromNs?.tables;
|
|
1518
|
+
if (!fromTables) continue;
|
|
1519
|
+
for (const tableName of Object.keys(fromTables)) {
|
|
1520
|
+
const toTableRaw = toNs?.tables[tableName];
|
|
1521
|
+
if (!(toTableRaw instanceof StorageTable)) {
|
|
1522
|
+
conflicts.push({
|
|
1523
|
+
kind: "tableRemoved",
|
|
1524
|
+
summary: `Table "${tableName}" was removed`
|
|
1525
|
+
});
|
|
1526
|
+
continue;
|
|
1527
|
+
}
|
|
1528
|
+
const toTable = toTableRaw;
|
|
1529
|
+
const fromTableRaw = fromTables[tableName];
|
|
1530
|
+
if (!(fromTableRaw instanceof StorageTable)) continue;
|
|
1531
|
+
const fromTable = fromTableRaw;
|
|
1532
|
+
for (const columnName of Object.keys(fromTable.columns)) if (!hasOwn(toTable.columns, columnName)) conflicts.push({
|
|
1533
|
+
kind: "columnRemoved",
|
|
1534
|
+
summary: `Column "${tableName}"."${columnName}" was removed`
|
|
1509
1535
|
});
|
|
1510
|
-
continue;
|
|
1511
1536
|
}
|
|
1512
|
-
const toTable = to.tables[tableName];
|
|
1513
|
-
const fromTable = from.tables[tableName];
|
|
1514
|
-
if (!fromTable) continue;
|
|
1515
|
-
for (const columnName of Object.keys(fromTable.columns)) if (!hasOwn(toTable.columns, columnName)) conflicts.push({
|
|
1516
|
-
kind: "columnRemoved",
|
|
1517
|
-
summary: `Column "${tableName}"."${columnName}" was removed`
|
|
1518
|
-
});
|
|
1519
1537
|
}
|
|
1520
1538
|
return conflicts;
|
|
1521
1539
|
}
|
|
@@ -1537,17 +1555,32 @@ function contractToSchemaIR(contract, options) {
|
|
|
1537
1555
|
if (options.annotationNamespace.length === 0) throw new Error("annotationNamespace must be a non-empty string");
|
|
1538
1556
|
if (!contract) return { tables: {} };
|
|
1539
1557
|
const storage = contract.storage;
|
|
1540
|
-
const
|
|
1558
|
+
const allTypes = { ...storage.types ?? {} };
|
|
1559
|
+
for (const ns of Object.values(storage.namespaces)) {
|
|
1560
|
+
const nsTypes = ns.types;
|
|
1561
|
+
if (nsTypes) for (const [k, v] of Object.entries(nsTypes)) allTypes[k] = v;
|
|
1562
|
+
}
|
|
1563
|
+
const storageTypes = allTypes;
|
|
1541
1564
|
const tables = {};
|
|
1542
|
-
for (const
|
|
1565
|
+
for (const ns of Object.values(storage.namespaces)) for (const [tableName, tableDefRaw] of Object.entries(ns.tables)) {
|
|
1566
|
+
if (!(tableDefRaw instanceof StorageTable)) throw new Error(`contractToSchemaIR: expected StorageTable at namespaces.${ns.id}.tables.${tableName}`);
|
|
1567
|
+
const tableDef = tableDefRaw;
|
|
1568
|
+
if (tables[tableName] !== void 0) throw new Error(`contractToSchemaIR: duplicate SQL table name "${tableName}" across namespaces (ambiguous for flat SqlSchemaIR.tables).`);
|
|
1569
|
+
tables[tableName] = convertTable(tableName, tableDef, storageTypes, options.expandNativeType, options.renderDefault);
|
|
1570
|
+
}
|
|
1543
1571
|
return {
|
|
1544
1572
|
tables,
|
|
1545
1573
|
...ifDefined("annotations", deriveAnnotations(storage, options.annotationNamespace))
|
|
1546
1574
|
};
|
|
1547
1575
|
}
|
|
1548
1576
|
function deriveAnnotations(storage, annotationNamespace) {
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1577
|
+
const allTypes = { ...storage.types ?? {} };
|
|
1578
|
+
for (const ns of Object.values(storage.namespaces)) {
|
|
1579
|
+
const nsTypes = ns.types;
|
|
1580
|
+
if (nsTypes) for (const [k, v] of Object.entries(nsTypes)) allTypes[k] = v;
|
|
1581
|
+
}
|
|
1582
|
+
const types = allTypes;
|
|
1583
|
+
if (Object.keys(types).length === 0) return void 0;
|
|
1551
1584
|
const byNativeType = {};
|
|
1552
1585
|
for (const typeInstance of Object.values(types)) {
|
|
1553
1586
|
if (isPostgresEnumStorageEntry(typeInstance)) {
|
|
@@ -1565,31 +1598,41 @@ function deriveAnnotations(storage, annotationNamespace) {
|
|
|
1565
1598
|
//#endregion
|
|
1566
1599
|
//#region src/core/migrations/field-event-planner.ts
|
|
1567
1600
|
function planFieldEventOperations(options) {
|
|
1568
|
-
const
|
|
1569
|
-
const
|
|
1601
|
+
const priorContract = options.priorContract;
|
|
1602
|
+
const newContract = options.newContract;
|
|
1570
1603
|
const added = [];
|
|
1571
1604
|
const dropped = [];
|
|
1572
1605
|
const altered = [];
|
|
1573
|
-
const
|
|
1574
|
-
for (const
|
|
1575
|
-
const
|
|
1576
|
-
const
|
|
1577
|
-
const
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
const
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1606
|
+
const namespaceIds = unionSorted(priorContract ? Object.keys(priorContract.storage.namespaces) : [], Object.keys(newContract.storage.namespaces));
|
|
1607
|
+
for (const namespaceId of namespaceIds) {
|
|
1608
|
+
const priorNs = priorContract?.storage.namespaces[namespaceId];
|
|
1609
|
+
const newNs = newContract.storage.namespaces[namespaceId];
|
|
1610
|
+
const priorTables = priorNs?.tables;
|
|
1611
|
+
const newTables = newNs?.tables;
|
|
1612
|
+
const tableNames = unionSorted(priorTables ? Object.keys(priorTables) : [], newTables ? Object.keys(newTables) : []);
|
|
1613
|
+
for (const tableName of tableNames) {
|
|
1614
|
+
const priorTableRaw = priorTables?.[tableName];
|
|
1615
|
+
const newTableRaw = newTables?.[tableName];
|
|
1616
|
+
const priorTable = priorTableRaw instanceof StorageTable ? priorTableRaw : void 0;
|
|
1617
|
+
const newTable = newTableRaw instanceof StorageTable ? newTableRaw : void 0;
|
|
1618
|
+
const fieldNames = unionSorted(priorTable ? Object.keys(priorTable.columns) : [], newTable ? Object.keys(newTable.columns) : []);
|
|
1619
|
+
for (const fieldName of fieldNames) {
|
|
1620
|
+
const priorField = priorTable?.columns[fieldName];
|
|
1621
|
+
const newField = newTable?.columns[fieldName];
|
|
1622
|
+
const entry = {
|
|
1623
|
+
namespaceId,
|
|
1624
|
+
tableName,
|
|
1625
|
+
fieldName,
|
|
1626
|
+
priorTable,
|
|
1627
|
+
newTable,
|
|
1628
|
+
priorField,
|
|
1629
|
+
newField
|
|
1630
|
+
};
|
|
1631
|
+
if (priorField === void 0 && newField !== void 0) added.push(entry);
|
|
1632
|
+
else if (priorField !== void 0 && newField === void 0) dropped.push(entry);
|
|
1633
|
+
else if (priorField !== void 0 && newField !== void 0) {
|
|
1634
|
+
if (isAlteration(priorField, newField)) altered.push(entry);
|
|
1635
|
+
}
|
|
1593
1636
|
}
|
|
1594
1637
|
}
|
|
1595
1638
|
}
|
|
@@ -1619,6 +1662,7 @@ function appendCalls(event, entries, codecHooks, calls, pickCodecId) {
|
|
|
1619
1662
|
*/
|
|
1620
1663
|
function buildContext(event, entry) {
|
|
1621
1664
|
const base = {
|
|
1665
|
+
namespaceId: entry.namespaceId,
|
|
1622
1666
|
tableName: entry.tableName,
|
|
1623
1667
|
fieldName: entry.fieldName
|
|
1624
1668
|
};
|