IF Commons GitHub

sql/lifecycle/change

Written to: 3 requirements: 3 proved, 0 partly, 0 failing, 0 with no test recorded. 0011-sql-lifecycle FR-004, 0011-sql-lifecycle FR-005, 0011-sql-lifecycle FR-013

Changes (commons data 0011-sql-lifecycle FR-004, FR-005, FR-013): what differs between two states, found by the identity of each element (its words, and for a constraint what it is) and not by its written name, so that a change of case style is a rename and a change of what an element is called in governance is a rename where governance says so. applyChange is the state a change leads to; applying the changes of diff(a, b) to a reaches b, which is checked by the plan and by property tests.

Source: commons/data/sql/lifecycle/change.ts

3 of 6 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

applyChangefunction
function applyChange(state: State, change: Change): State

The state a change leads to.

ParameterWhat it is
statethe state before
changethe change

Returns: the state after

Imported by 9 tests of the run (9 passed, 0 failed): the library's results

applyChangesconst
const applyChanges: (state: State, changes: readonly Change[]) => State

The state that applying changes in order leads to.

ParameterWhat it is
statethe state before; none for an empty database of the given dialect and naming
changesthe changes

Returns: the state after

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

Changetypeno test imports it
type Change = | { readonly kind: "renameTable"; readonly key: string; readonly fromWords: readonly s… (2328 characters)
type Change =
  | {
      readonly kind: "renameTable";
      readonly key: string;
      readonly fromWords: readonly string[];
      readonly toWords: readonly string[];
      readonly fromName: string;
      readonly toName: string;
    }
  | { readonly kind: "renameColumn"; readonly key: string; readonly table: TableRef; readonly from: StateColumn; readonly to: StateColumn }
  | { readonly kind: "dropConstraint"; readonly key: string; readonly table: TableRef; readonly constraint: StateConstraint }
  | {
      readonly kind: "renameConstraint";
      readonly key: string;
      readonly table: TableRef;
      readonly from: StateConstraint;
      readonly to: StateConstraint;
    }
  | { readonly kind: "addColumn"; readonly key: string; readonly table: TableRef; readonly column: StateColumn }
  | { readonly kind: "dropColumn"; readonly key: string; readonly table: TableRef; readonly column: StateColumn }
  | { readonly kind: "alterType"; readonly key: string; readonly table: TableRef; readonly from: StateColumn; readonly to: StateColumn }
  | { readonly kind: "alterNullable"; readonly key: string; readonly table: TableRef; readonly from: StateColumn; readonly to: StateColumn }
  | { readonly kind: "alterDefault"; readonly key: string; readonly table: TableRef; readonly from: StateColumn; readonly to: StateColumn }
  | {
      readonly kind: "alterPrimaryKey";
      readonly key: string;
      readonly table: TableRef;
      readonly from: readonly string[];
      readonly to: readonly string[];
    }
  | {
      readonly kind: "alterClause";
      readonly key: string;
      readonly table: TableRef;
      readonly from: string | undefined;
      readonly to: string | undefined;
    }
  | { readonly kind: "createTable"; readonly key: string; readonly table: StateTable }
  | { readonly kind: "addConstraint"; readonly key: string; readonly table: TableRef; readonly constraint: StateConstraint }
  | {
      readonly kind: "upsertRows";
      readonly key: string;
      readonly table: TableRef;
      readonly rows: readonly StateRow[];
      readonly before: readonly StateRow[];
    }
  | { readonly kind: "removeRows"; readonly key: string; readonly table: TableRef; readonly rows: readonly StateRow[] }
  | { readonly kind: "dropTable"; readonly key: string; readonly table: StateTable };

What a change is.

ChangeKindtypeno test imports it
type ChangeKind = Change["kind"];

The kinds of change.

difffunction
function diff(from: State | undefined, to: State): readonly Change[]

What differs between two states.

ParameterWhat it is
fromthe state a database is in; none for an empty database
tothe state wanted

Returns: the changes, in the order they are to be made: renames, drops of constraints, changes of columns, new tables, new constraints, rows, drops of tables

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

TableRefinterfaceno test imports it
interface TableRef

A table as a change names it: its words and its written name at the moment the change is made.

MemberTypeWhat it is
wordsreadonly string[]
namestring

Titles, headings, exports, tables, columns and requirements. Esc closes.