@prisma/orm-family-sql 8.0.0-rc.19-dev.3 → 8.0.0-rc.19-dev.5
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-B_FwQQXi.mjs → control-Cih61sJa.mjs} +198 -56
- package/dist/control-Cih61sJa.mjs.map +1 -0
- package/dist/{control-Xwm5kFlC.d.mts → control-Dv1ea79q.d.mts} +68 -11
- package/dist/{control-Xwm5kFlC.d.mts.map → control-Dv1ea79q.d.mts.map} +1 -1
- package/dist/family.d.mts +2 -2
- package/dist/family.mjs +2 -2
- package/dist/family__control.d.mts +2 -2
- package/dist/family__control.mjs +2 -2
- package/package.json +18 -18
- package/dist/control-B_FwQQXi.mjs.map +0 -1
|
@@ -1614,6 +1614,11 @@ function fieldRenameStorageEffect(statement, fromContract, contract) {
|
|
|
1614
1614
|
function operationsOf(call) {
|
|
1615
1615
|
return [call, ...call.companions];
|
|
1616
1616
|
}
|
|
1617
|
+
/** The origins of a plan whose statements renamed and moved nothing. */
|
|
1618
|
+
const NO_RENAMED_ORIGINS = {
|
|
1619
|
+
originTable: (current) => current,
|
|
1620
|
+
originColumn: (_origin, column) => column
|
|
1621
|
+
};
|
|
1617
1622
|
const DRIFTED = "so the database has drifted from that contract. Inspect it with prisma db schema, or leave out this statement.";
|
|
1618
1623
|
const UNMATCHED = "A statement plans the rename a hand-written rename call makes, and that call does not match the contracts. Leave out this statement.";
|
|
1619
1624
|
function statementRefused(statement, summary, why, location, refusedOperationClass) {
|
|
@@ -1638,6 +1643,19 @@ function tableControlPolicy(contract, table) {
|
|
|
1638
1643
|
function tableKey(table) {
|
|
1639
1644
|
return JSON.stringify([table.namespaceId, table.table]);
|
|
1640
1645
|
}
|
|
1646
|
+
/** A contract space other than the one planned that declares the namespace, if any. */
|
|
1647
|
+
function otherSpaceDeclaring(ownership, namespaceId) {
|
|
1648
|
+
return (ownership.oracle?.namespaceDeclaringSpaces(namespaceId) ?? []).find((spaceId) => spaceId !== ownership.spaceId);
|
|
1649
|
+
}
|
|
1650
|
+
function withoutNamespacesRefused(statement, label) {
|
|
1651
|
+
return statementRefused(statement, `${label}: the database target keeps every table in one namespace`, "This database target has no namespaces, so a statement cannot rename a namespace or move a model to another one. Leave out this statement.", void 0);
|
|
1652
|
+
}
|
|
1653
|
+
function namespaceText(namespaceId) {
|
|
1654
|
+
return namespaceId === UNBOUND_NAMESPACE_ID ? "the unbound namespace" : `namespace "${namespaceId}"`;
|
|
1655
|
+
}
|
|
1656
|
+
function qualifiedTable(table) {
|
|
1657
|
+
return table.namespaceId === UNBOUND_NAMESPACE_ID ? table.table : `${table.namespaceId}.${table.table}`;
|
|
1658
|
+
}
|
|
1641
1659
|
function tableRenameRefused(statement, label, rename, mismatch) {
|
|
1642
1660
|
switch (mismatch.kind) {
|
|
1643
1661
|
case "tableMissing": return statementRefused(statement, `${label}: the schema being planned from has no table "${rename.from}"`, `The database has no table "${rename.from}", although the contract it was last updated to names it, ${DRIFTED}`, {
|
|
@@ -1682,8 +1700,15 @@ var StatementPlanner = class {
|
|
|
1682
1700
|
#contract;
|
|
1683
1701
|
#policy;
|
|
1684
1702
|
#target;
|
|
1685
|
-
/**
|
|
1703
|
+
/** Where each table renamed or moved so far is in the working schema, keyed by its origin place. */
|
|
1686
1704
|
#renamedTables = /* @__PURE__ */ new Map();
|
|
1705
|
+
/** The origin place of each table renamed or moved so far, keyed as `#renamedTables`. */
|
|
1706
|
+
#originTables = /* @__PURE__ */ new Map();
|
|
1707
|
+
/** Each column renamed so far: its origin table, and its name before and after. */
|
|
1708
|
+
#renamedColumns = [];
|
|
1709
|
+
/** The name each namespace renamed so far has in the working schema, keyed by its origin name. */
|
|
1710
|
+
#renamedNamespaces = /* @__PURE__ */ new Map();
|
|
1711
|
+
#ownership;
|
|
1687
1712
|
calls = [];
|
|
1688
1713
|
/** How many operations the calls planned so far lower to. */
|
|
1689
1714
|
#operationCount = 0;
|
|
@@ -1694,10 +1719,55 @@ var StatementPlanner = class {
|
|
|
1694
1719
|
this.#contract = input.contract;
|
|
1695
1720
|
this.#policy = input.policy;
|
|
1696
1721
|
this.#target = input.target;
|
|
1722
|
+
this.#ownership = input.ownership;
|
|
1697
1723
|
}
|
|
1698
1724
|
/** Plans one statement; the result is the positions of the operations it accounts for. */
|
|
1699
1725
|
plan(statement) {
|
|
1700
|
-
|
|
1726
|
+
switch (statement.entity) {
|
|
1727
|
+
case "namespace": return this.#planNamespace(statement);
|
|
1728
|
+
case "model": return this.#planModel(statement);
|
|
1729
|
+
case "field": return this.#planField(statement);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
/** Where a table of the origin is in the working schema, after the renames planned so far. */
|
|
1733
|
+
#current(origin) {
|
|
1734
|
+
const table = this.#renamedTables.get(tableKey(origin)) ?? origin;
|
|
1735
|
+
return {
|
|
1736
|
+
namespaceId: this.#renamedNamespaces.get(table.namespaceId) ?? table.namespaceId,
|
|
1737
|
+
table: table.table
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
#planNamespace(statement) {
|
|
1741
|
+
const rename = {
|
|
1742
|
+
from: statement.from,
|
|
1743
|
+
to: statement.to
|
|
1744
|
+
};
|
|
1745
|
+
const label = `Cannot rename namespace "${rename.from}" to "${rename.to}"`;
|
|
1746
|
+
const namespaces = this.#target.namespaces;
|
|
1747
|
+
if (namespaces === void 0) return notOk(withoutNamespacesRefused(statement, label));
|
|
1748
|
+
const movePerModel = `--rename ${rename.from}.<Model>:${rename.to}.<Model>`;
|
|
1749
|
+
const refusal = namespaces.namespaceRenameRefusal(rename);
|
|
1750
|
+
if (refusal !== void 0) return notOk(statementRefused(statement, `${label}: ${refusal.reason}`, refusal.fix, void 0));
|
|
1751
|
+
const otherSpace = this.#ownership === void 0 ? void 0 : otherSpaceDeclaring(this.#ownership, rename.from);
|
|
1752
|
+
if (otherSpace !== void 0) return notOk(statementRefused(statement, `${label}: contract space "${otherSpace}" also declares it`, `Renaming the namespace would rename it under contract space "${otherSpace}" too, whose contract still names it "${rename.from}". Leave out this statement, or move each model with ${movePerModel} instead.`, void 0));
|
|
1753
|
+
const tables = Object.keys(this.#contract.storage.namespaces[rename.to]?.entries.table ?? {});
|
|
1754
|
+
for (const table of tables) {
|
|
1755
|
+
const controlPolicy = tableControlPolicy(this.#contract, {
|
|
1756
|
+
namespaceId: rename.to,
|
|
1757
|
+
table
|
|
1758
|
+
});
|
|
1759
|
+
if (controlPolicy === "managed") continue;
|
|
1760
|
+
return notOk(statementRefused(statement, `${label}: table "${table}" has control policy "${controlPolicy}"`, `Statements rename only namespaces whose tables all have control policy "managed"; table "${table}" is "${controlPolicy}". Make the change in the database yourself and leave out this statement.`, {
|
|
1761
|
+
namespaceId: rename.to,
|
|
1762
|
+
table
|
|
1763
|
+
}));
|
|
1764
|
+
}
|
|
1765
|
+
const schemaTables = this.#target.tables();
|
|
1766
|
+
if (!schemaTables.hasNamespace(rename.from)) return notOk(statementRefused(statement, `${label}: the schema being planned from has no namespace "${rename.from}"`, `The database has no namespace "${rename.from}", although the contract it was last updated to names it, ${DRIFTED}`, void 0));
|
|
1767
|
+
if (schemaTables.hasNamespace(rename.to)) return notOk(statementRefused(statement, `${label}: the database already has a namespace "${rename.to}"`, `The database already has a namespace "${rename.to}", which the contract it was last updated to does not declare. If it holds nothing, drop or rename it in the database yourself; otherwise move each model with ${movePerModel} instead of this statement.`, void 0));
|
|
1768
|
+
const planned = this.#emit(statement, label, void 0, namespaces.renameNamespaceCall(rename));
|
|
1769
|
+
if (planned.ok) this.#renamedNamespaces.set(rename.from, rename.to);
|
|
1770
|
+
return planned;
|
|
1701
1771
|
}
|
|
1702
1772
|
#controlPolicyRefusal(statement, label, destinationTable) {
|
|
1703
1773
|
const controlPolicy = tableControlPolicy(this.#contract, destinationTable);
|
|
@@ -1718,8 +1788,25 @@ var StatementPlanner = class {
|
|
|
1718
1788
|
if (!worked.ok) return notOk(statementRefused(statement, `Model "${modelDisplayName(worked.failure.model)}" has no table in its contract`, `A model rename renames the model's table, and model "${modelDisplayName(worked.failure.model)}" has none in its contract. Leave out this statement.`, void 0));
|
|
1719
1789
|
const effect = worked.value;
|
|
1720
1790
|
if (effect.kind === "unchanged") return ok([]);
|
|
1721
|
-
|
|
1722
|
-
|
|
1791
|
+
const [origin, destination] = effect.kind === "moveNamespace" ? [effect.from, effect.to] : [{
|
|
1792
|
+
namespaceId: effect.rename.namespaceId,
|
|
1793
|
+
table: effect.rename.from
|
|
1794
|
+
}, {
|
|
1795
|
+
namespaceId: effect.rename.namespaceId,
|
|
1796
|
+
table: effect.rename.to
|
|
1797
|
+
}];
|
|
1798
|
+
const current = this.#current(origin);
|
|
1799
|
+
if (current.namespaceId === destination.namespaceId) {
|
|
1800
|
+
if (current.table === destination.table) return ok([]);
|
|
1801
|
+
return this.#planTableRename(statement, origin, {
|
|
1802
|
+
namespaceId: destination.namespaceId,
|
|
1803
|
+
from: current.table,
|
|
1804
|
+
to: destination.table
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
return this.#planMove(statement, origin, current, destination);
|
|
1808
|
+
}
|
|
1809
|
+
#planTableRename(statement, origin, rename) {
|
|
1723
1810
|
const destinationTable = {
|
|
1724
1811
|
namespaceId: rename.namespaceId,
|
|
1725
1812
|
table: rename.to
|
|
@@ -1732,37 +1819,86 @@ var StatementPlanner = class {
|
|
|
1732
1819
|
const planned = this.#emit(statement, label, destinationTable, this.#target.renameTableCall(rename));
|
|
1733
1820
|
if (planned.ok) {
|
|
1734
1821
|
this.tableRenames.push(rename);
|
|
1735
|
-
this.#renamedTables.set(tableKey(
|
|
1736
|
-
|
|
1737
|
-
table: rename.from
|
|
1738
|
-
}), rename.to);
|
|
1822
|
+
this.#renamedTables.set(tableKey(origin), destinationTable);
|
|
1823
|
+
this.#originTables.set(tableKey(origin), origin);
|
|
1739
1824
|
}
|
|
1740
1825
|
return planned;
|
|
1741
1826
|
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Moves the table to the destination namespace under its own name, creating the namespace first
|
|
1829
|
+
* when the working schema lacks it, then renames it there when the destination names it
|
|
1830
|
+
* differently. The statement accounts for the move and the rename, not the namespace's creation.
|
|
1831
|
+
*/
|
|
1832
|
+
#planMove(statement, origin, from, to) {
|
|
1833
|
+
const label = `Cannot move table "${from.table}" from ${namespaceText(from.namespaceId)} to ${namespaceText(to.namespaceId)}`;
|
|
1834
|
+
const namespaces = this.#target.namespaces;
|
|
1835
|
+
if (namespaces === void 0) return notOk(withoutNamespacesRefused(statement, label));
|
|
1836
|
+
if (to.namespaceId === UNBOUND_NAMESPACE_ID) return notOk(statementRefused(statement, `Cannot move table "${from.table}" from ${namespaceText(from.namespaceId)} to the unbound namespace: the unbound namespace has no fixed place in the database`, `A table of the unbound namespace lives wherever the connection that uses it looks, so a migration cannot move a table there. Move the table yourself and leave out this statement, or keep the model in ${namespaceText(from.namespaceId)}.`, from));
|
|
1837
|
+
const moved = {
|
|
1838
|
+
namespaceId: to.namespaceId,
|
|
1839
|
+
table: from.table
|
|
1840
|
+
};
|
|
1841
|
+
const policyRefusal = this.#controlPolicyRefusal(statement, label, to);
|
|
1842
|
+
if (policyRefusal !== void 0) return notOk(policyRefusal);
|
|
1843
|
+
const tables = this.#target.tables();
|
|
1844
|
+
if (!tables.hasTable(from.namespaceId, from.table)) return notOk(statementRefused(statement, `${label}: the schema being planned from has no table "${qualifiedTable(from)}"`, `The database has no table "${qualifiedTable(from)}", although the contract it was last updated to names it, ${DRIFTED}`, from));
|
|
1845
|
+
const [taken] = [...tables.tablesNamed(to.namespaceId, from.table), ...tables.tablesNamed(to.namespaceId, to.table)];
|
|
1846
|
+
if (taken !== void 0) {
|
|
1847
|
+
const takenTable = qualifiedTable({
|
|
1848
|
+
namespaceId: to.namespaceId,
|
|
1849
|
+
table: taken
|
|
1850
|
+
});
|
|
1851
|
+
return notOk(statementRefused(statement, `${label}: the schema being planned from already has a table "${takenTable}"`, `A move cannot replace a table that already exists. Rename, move or drop table "${takenTable}" first, or leave out this statement.`, {
|
|
1852
|
+
namespaceId: to.namespaceId,
|
|
1853
|
+
table: taken
|
|
1854
|
+
}));
|
|
1855
|
+
}
|
|
1856
|
+
for (const call of namespaces.createNamespaceCalls(to.namespaceId)) {
|
|
1857
|
+
const created = this.#emit(statement, label, moved, call);
|
|
1858
|
+
if (!created.ok) return created;
|
|
1859
|
+
}
|
|
1860
|
+
const planned = this.#emit(statement, label, moved, namespaces.moveTableCall({
|
|
1861
|
+
table: from.table,
|
|
1862
|
+
from: from.namespaceId,
|
|
1863
|
+
to: to.namespaceId
|
|
1864
|
+
}));
|
|
1865
|
+
if (!planned.ok) return planned;
|
|
1866
|
+
this.#renamedTables.set(tableKey(origin), moved);
|
|
1867
|
+
this.#originTables.set(tableKey(origin), origin);
|
|
1868
|
+
if (to.table === from.table) return planned;
|
|
1869
|
+
const renamed = this.#planTableRename(statement, origin, {
|
|
1870
|
+
namespaceId: to.namespaceId,
|
|
1871
|
+
from: from.table,
|
|
1872
|
+
to: to.table
|
|
1873
|
+
});
|
|
1874
|
+
if (!renamed.ok) return renamed;
|
|
1875
|
+
return ok([...planned.value, ...renamed.value]);
|
|
1876
|
+
}
|
|
1742
1877
|
#planField(statement) {
|
|
1743
1878
|
const worked = fieldRenameStorageEffect(statement, this.#fromContract, this.#contract);
|
|
1744
1879
|
if (!worked.ok && worked.failure.kind === "noTable") return notOk(statementRefused(statement, `Model "${modelDisplayName(worked.failure.model)}" has no table in its contract`, `A field rename renames the field's column, and model "${modelDisplayName(worked.failure.model)}" has no table in its contract. Leave out this statement.`, void 0));
|
|
1745
1880
|
if (!worked.ok) return notOk(statementRefused(statement, `Field "${modelDisplayName(statement.from)}.${statement.from.field}" has a column on one side only of ${describeMigrationStatement(statement, this.#fromContract, this.#contract)}`, "A field rename renames a column or changes nothing in storage, and this field gains or loses its column. Leave out this statement and plan the change without it.", void 0));
|
|
1746
1881
|
const effect = worked.value;
|
|
1747
1882
|
if (effect.kind === "unchanged") return ok([]);
|
|
1748
|
-
const
|
|
1883
|
+
const current = this.#current(effect.table);
|
|
1884
|
+
const table = current.table;
|
|
1749
1885
|
const destinationTable = modelTable(this.#contract, statement.to);
|
|
1750
|
-
if (destinationTable !== void 0 && (destinationTable.namespaceId !==
|
|
1886
|
+
if (destinationTable !== void 0 && (destinationTable.namespaceId !== current.namespaceId || destinationTable.table !== table)) {
|
|
1751
1887
|
const tableRename = {
|
|
1752
|
-
namespaceId:
|
|
1888
|
+
namespaceId: current.namespaceId,
|
|
1753
1889
|
from: table,
|
|
1754
1890
|
to: destinationTable.table
|
|
1755
1891
|
};
|
|
1756
1892
|
const model = modelDisplayName(statement.to);
|
|
1757
1893
|
const fieldText = `${model}.${statement.from.field}:${model}.${statement.to.field}`;
|
|
1758
1894
|
return notOk(statementRefused(statement, `Cannot rename column "${table}"."${effect.from}": the model's table changes from "${table}" to "${destinationTable.table}", and no statement renames the table`, `The column would be renamed on a table the plan then drops and creates under the new name, and a migration that only changes the table name is planned the same way. With migration plan, rename the table by hand in its own migration first. Change the contract so that only the table name changes, and run prisma contract emit. Run prisma migration new --name <name> --from <hash of the migration the database is at>, add ${this.#target.renderTableRename(tableRename)} to the operations of its migration.ts, and run node on that migration.ts to write its ops.json. Then change the contract to its final form, emit it, and plan the field rename with --from that migration. With db update, change the contract so that only the table name changes, and run prisma contract emit. Rename the table in the database yourself with ${this.#target.tableRenameByHand(tableRename).join("; ")}, check that prisma db update --dry-run plans no drop of a table or column, and run prisma db update to store that contract. Then emit the final contract and run prisma db update --rename ${fieldText}.`, {
|
|
1759
|
-
namespaceId:
|
|
1895
|
+
namespaceId: current.namespaceId,
|
|
1760
1896
|
table,
|
|
1761
1897
|
column: effect.from
|
|
1762
1898
|
}));
|
|
1763
1899
|
}
|
|
1764
1900
|
const rename = {
|
|
1765
|
-
namespaceId:
|
|
1901
|
+
namespaceId: current.namespaceId,
|
|
1766
1902
|
table,
|
|
1767
1903
|
from: effect.from,
|
|
1768
1904
|
to: effect.to
|
|
@@ -1780,14 +1916,38 @@ var StatementPlanner = class {
|
|
|
1780
1916
|
...tableLocation,
|
|
1781
1917
|
column: rename.from
|
|
1782
1918
|
}, this.#target.renameColumnCall(rename));
|
|
1783
|
-
if (planned.ok)
|
|
1919
|
+
if (planned.ok) {
|
|
1920
|
+
this.columnRenames.push(rename);
|
|
1921
|
+
this.#renamedColumns.push({
|
|
1922
|
+
origin: effect.table,
|
|
1923
|
+
from: effect.from,
|
|
1924
|
+
to: effect.to
|
|
1925
|
+
});
|
|
1926
|
+
}
|
|
1784
1927
|
return planned;
|
|
1785
1928
|
}
|
|
1929
|
+
/** The origins of the working schema's tables and columns, as the statements left them. */
|
|
1930
|
+
origins() {
|
|
1931
|
+
const sameTable = (left, right) => left.namespaceId === right.namespaceId && left.table === right.table;
|
|
1932
|
+
return {
|
|
1933
|
+
originTable: (current) => {
|
|
1934
|
+
for (const origin of this.#originTables.values()) if (sameTable(this.#current(origin), current)) return origin;
|
|
1935
|
+
for (const [origin, renamed] of this.#renamedNamespaces) if (renamed === current.namespaceId) return {
|
|
1936
|
+
namespaceId: origin,
|
|
1937
|
+
table: current.table
|
|
1938
|
+
};
|
|
1939
|
+
return current;
|
|
1940
|
+
},
|
|
1941
|
+
originColumn: (origin, column) => this.#renamedColumns.find((renamed) => sameTable(renamed.origin, origin) && renamed.to === column)?.from ?? column
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1786
1944
|
};
|
|
1787
1945
|
/**
|
|
1788
|
-
* Plans the statements
|
|
1789
|
-
*
|
|
1790
|
-
*
|
|
1946
|
+
* Plans the statements against a target's working schema, namespace renames first and the rest in
|
|
1947
|
+
* the order given: model and field statements name the origin and destination contracts, so the
|
|
1948
|
+
* namespace renames' place among them does not matter. Each model rename becomes a table rename
|
|
1949
|
+
* and each field rename a column rename, computed against the schema earlier statements left, then
|
|
1950
|
+
* applied to it. The first statement that cannot be planned fails the whole
|
|
1791
1951
|
* plan with a `statementRefused` conflict that carries the statement.
|
|
1792
1952
|
*/
|
|
1793
1953
|
function planStatements(input) {
|
|
@@ -1797,15 +1957,18 @@ function planStatements(input) {
|
|
|
1797
1957
|
calls: [],
|
|
1798
1958
|
tableRenames: [],
|
|
1799
1959
|
columnRenames: [],
|
|
1800
|
-
appliedStatements: []
|
|
1960
|
+
appliedStatements: [],
|
|
1961
|
+
origins: NO_RENAMED_ORIGINS
|
|
1801
1962
|
});
|
|
1802
1963
|
if (fromContract === null) return notOk(statementRefused(first, "Statements need an origin contract, and this plan has none", "A statement names models and fields of the origin contract, and this plan has none. Plan from a contract that has the old names, or leave out the statement.", void 0));
|
|
1803
1964
|
const planner = new StatementPlanner({
|
|
1804
1965
|
...input,
|
|
1805
|
-
fromContract
|
|
1966
|
+
fromContract,
|
|
1967
|
+
ownership: input.ownership
|
|
1806
1968
|
});
|
|
1807
1969
|
const appliedStatements = [];
|
|
1808
|
-
|
|
1970
|
+
const namespacesFirst = [...input.statements.filter((statement) => statement.entity === "namespace"), ...input.statements.filter((statement) => statement.entity !== "namespace")];
|
|
1971
|
+
for (const statement of namespacesFirst) {
|
|
1809
1972
|
const operationIndexes = planner.plan(statement);
|
|
1810
1973
|
if (!operationIndexes.ok) return operationIndexes;
|
|
1811
1974
|
appliedStatements.push({
|
|
@@ -1817,7 +1980,8 @@ function planStatements(input) {
|
|
|
1817
1980
|
calls: planner.calls,
|
|
1818
1981
|
tableRenames: planner.tableRenames,
|
|
1819
1982
|
columnRenames: planner.columnRenames,
|
|
1820
|
-
appliedStatements
|
|
1983
|
+
appliedStatements,
|
|
1984
|
+
origins: planner.origins()
|
|
1821
1985
|
});
|
|
1822
1986
|
}
|
|
1823
1987
|
/**
|
|
@@ -1927,26 +2091,6 @@ function unknownCallNames(calls) {
|
|
|
1927
2091
|
return [call, (counts.get(call.factoryName) ?? 0) > 1 ? `${call.factoryName}#${ordinal}` : call.factoryName];
|
|
1928
2092
|
}));
|
|
1929
2093
|
}
|
|
1930
|
-
function originTable(context, namespaceId, table) {
|
|
1931
|
-
for (const statement of context.statements) {
|
|
1932
|
-
if (statement.kind !== "rename" || statement.entity !== "model") continue;
|
|
1933
|
-
const effect = modelRenameStorageEffect(statement, context.fromContract, context.contract);
|
|
1934
|
-
if (!effect.ok || effect.value.kind !== "renameTable") continue;
|
|
1935
|
-
const { rename } = effect.value;
|
|
1936
|
-
if (rename.namespaceId === namespaceId && rename.to === table) return rename.from;
|
|
1937
|
-
}
|
|
1938
|
-
return table;
|
|
1939
|
-
}
|
|
1940
|
-
function originColumn(context, namespaceId, table, column) {
|
|
1941
|
-
for (const statement of context.statements) {
|
|
1942
|
-
if (statement.kind !== "rename" || statement.entity !== "field") continue;
|
|
1943
|
-
const effect = fieldRenameStorageEffect(statement, context.fromContract, context.contract);
|
|
1944
|
-
if (!effect.ok || effect.value.kind !== "renameColumn") continue;
|
|
1945
|
-
const rename = effect.value;
|
|
1946
|
-
if (rename.table.namespaceId === namespaceId && rename.table.table === table && rename.to === column) return rename.from;
|
|
1947
|
-
}
|
|
1948
|
-
return column;
|
|
1949
|
-
}
|
|
1950
2094
|
/** The models of `contract` that store `table`: a model and its variants share one. */
|
|
1951
2095
|
function modelsStoring(contract, namespaceId, table) {
|
|
1952
2096
|
return Object.entries(contract.domain.namespaces).flatMap(([modelNamespace, namespace]) => Object.entries(namespace.models).flatMap(([model, definition]) => {
|
|
@@ -1970,13 +2114,11 @@ function subjectOf(target, context) {
|
|
|
1970
2114
|
};
|
|
1971
2115
|
const { fromContract } = context;
|
|
1972
2116
|
if (target.table === void 0 || fromContract === null) return storage;
|
|
1973
|
-
const
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
};
|
|
1977
|
-
const
|
|
1978
|
-
const table = originTable(withOrigin, namespaceId, target.table.table);
|
|
1979
|
-
const models = modelsStoring(fromContract, namespaceId, table);
|
|
2117
|
+
const origin = context.origins.originTable({
|
|
2118
|
+
namespaceId: target.table.namespaceId,
|
|
2119
|
+
table: target.table.table
|
|
2120
|
+
});
|
|
2121
|
+
const models = modelsStoring(fromContract, origin.namespaceId, origin.table);
|
|
1980
2122
|
if (target.table.column === void 0) {
|
|
1981
2123
|
const model = models.find(({ isRoot }) => isRoot) ?? models[0];
|
|
1982
2124
|
return model === void 0 ? storage : {
|
|
@@ -1984,7 +2126,7 @@ function subjectOf(target, context) {
|
|
|
1984
2126
|
...model.coordinate
|
|
1985
2127
|
};
|
|
1986
2128
|
}
|
|
1987
|
-
const column = originColumn(
|
|
2129
|
+
const column = context.origins.originColumn(origin, target.table.column);
|
|
1988
2130
|
for (const model of [...models].sort((a, b) => Number(b.isRoot) - Number(a.isRoot))) {
|
|
1989
2131
|
const field = Object.entries(model.fields).find(([, stored]) => stored.column === column)?.[0];
|
|
1990
2132
|
if (field !== void 0) return {
|
|
@@ -2015,13 +2157,13 @@ function keepTableAdvice(target, subject, context) {
|
|
|
2015
2157
|
return `To keep its rows, rename table "${from}" to "${storage.table}" instead; a statement cannot rename the table of a model that keeps its name. With db update, rename the table in the database yourself with ${context.byHand.tableRenameByHand(rename).join("; ")}, then run prisma db update. With migration plan, write the rename as a migration of its own instead: run prisma migration new --name <name> --from <hash of the migration the database is at>, add ${context.byHand.renderTableRename(rename)} to the operations of its migration.ts, run node on that migration.ts so it writes ops.json, then run prisma db migrate.`;
|
|
2016
2158
|
}
|
|
2017
2159
|
/**
|
|
2018
|
-
* The subject of each operation that loses data and each that
|
|
2160
|
+
* The subject of each operation that loses data and each that changes access, at its position in
|
|
2019
2161
|
* the plan. A subject is a model or a field of the origin contract when one stores it, found under
|
|
2020
2162
|
* its origin name when a rename statement renamed its table or column earlier in the plan.
|
|
2021
2163
|
*/
|
|
2022
2164
|
function subjectsOfCalls(calls, context) {
|
|
2023
2165
|
const dataLoss = [];
|
|
2024
|
-
const
|
|
2166
|
+
const accessChanges = [];
|
|
2025
2167
|
const temporaryValues = [];
|
|
2026
2168
|
let operationIndex = 0;
|
|
2027
2169
|
for (const call of calls) {
|
|
@@ -2043,7 +2185,7 @@ function subjectsOfCalls(calls, context) {
|
|
|
2043
2185
|
...ifDefined("keepDataAdvice", keepTableAdvice(target, subject, context))
|
|
2044
2186
|
});
|
|
2045
2187
|
}
|
|
2046
|
-
for (const target of call.
|
|
2188
|
+
for (const target of call.accessChanges) accessChanges.push({
|
|
2047
2189
|
operationIndex,
|
|
2048
2190
|
subject: subjectOf(target, context),
|
|
2049
2191
|
widens: target.widens
|
|
@@ -2052,7 +2194,7 @@ function subjectsOfCalls(calls, context) {
|
|
|
2052
2194
|
}
|
|
2053
2195
|
return {
|
|
2054
2196
|
dataLoss,
|
|
2055
|
-
|
|
2197
|
+
accessChanges,
|
|
2056
2198
|
temporaryValues
|
|
2057
2199
|
};
|
|
2058
2200
|
}
|
|
@@ -2118,7 +2260,7 @@ function plannerSuccess(plan, appliedStatements, subjects, warnings) {
|
|
|
2118
2260
|
plan,
|
|
2119
2261
|
appliedStatements: Object.freeze([...appliedStatements]),
|
|
2120
2262
|
dataLoss: Object.freeze([...subjects.dataLoss]),
|
|
2121
|
-
|
|
2263
|
+
accessChanges: Object.freeze([...subjects.accessChanges]),
|
|
2122
2264
|
temporaryValues: Object.freeze([...subjects.temporaryValues]),
|
|
2123
2265
|
...warnings && warnings.length > 0 ? { warnings: Object.freeze(warnings.map((conflict) => Object.freeze({
|
|
2124
2266
|
kind: conflict.kind,
|
|
@@ -2574,6 +2716,6 @@ function columnCodecRef(codecId, column) {
|
|
|
2574
2716
|
}
|
|
2575
2717
|
var control_default = new SqlFamilyDescriptor();
|
|
2576
2718
|
//#endregion
|
|
2577
|
-
export {
|
|
2719
|
+
export { unmatchedColumnRename as $, planFieldEventOperations as A, resolveTableRenameAgainst as B, fieldStatementColumns as C, partitionCallsByControlPolicy as D, otherSpaceDeclaring as E, readReportedDefault as F, slotSource as G, rowsWithoutValueSummary as H, requiredColumnMeta as I, sqlTypeLookupsOf as J, sqlDefaultFunctions as K, requiredColumnOf as L, plannerFailure as M, plannerSuccess as N, partitionIssuesByControlPolicy as O, readColumnDefault as P, unknownCallNames as Q, requiredColumnsOfMigration as R, fieldRenameStorageEffect as S, modelRenameStorageEffect as T, runnerFailure as U, rowsWithoutValueFailure as V, runnerSuccess as W, subjectsOfCalls as X, storageNameOfOperation as Y, unconvertedFieldOf as Z, createSqlTextSources as _, appliedStatementsInOrder as a, fieldEventStorage as b, checkSqlExpressionText as c, contractNamespaceToSchemaIR as d, unmatchedTableRename as et, contractToSchemaIR as f, createMigrationPlan as g, convertedColumnOf as h, TABLE_NAME_CASE_CHANGED_CODE as i, planStatements as j, planFieldEventCalls as k, columnTakesTemporaryValue as l, convertedColumnMeta as m, INIT_ADDITIVE_POLICY as n, assembleAuthoringContributions$1 as o, control_default as p, sqlOfSlot as q, NO_RENAMED_ORIGINS as r, backfillOfDefaultedField as s, COLUMN_RENAME_UNMATCHED_CODE as t, contractColumns as u, detectDestructiveChanges as v, isUnfilledSlot as w, fieldOfColumn as x, detectTableNameCaseChanges as y, resolveColumnRenameAgainst as z };
|
|
2578
2720
|
|
|
2579
|
-
//# sourceMappingURL=control-
|
|
2721
|
+
//# sourceMappingURL=control-Cih61sJa.mjs.map
|