RelationalSchemaManager
Class: RelationalSchemaManager
Defined in: packages/sql/src/relational/manager.ts:67
Holds the plan of a relational store and brings the database to it: builds the plan from the model metadata, creates or extends the tables (never destructively) and reports what differs
Constructors
Constructor
new RelationalSchemaManager(
options):RelationalSchemaManager
Defined in: packages/sql/src/relational/manager.ts:77
Create a new RelationalSchemaManager instance
Parameters
options
RelationalSchemaManagerOptions
the store's dialect, layout and logger
Returns
RelationalSchemaManager
Properties
options
protectedreadonlyoptions:RelationalSchemaManagerOptions
Defined in: packages/sql/src/relational/manager.ts:77
the store's dialect, layout and logger
plan
plan:
RelationalSchemaPlan|undefined
Defined in: packages/sql/src/relational/manager.ts:71
The plan, once build ran
Methods
applyContract()
applyContract(
client,steps):Promise<ContractStep[]>
Defined in: packages/sql/src/relational/manager.ts:310
Apply contract steps: the drops and NOT NULL in one transaction under the schema lock (a NOT NULL is skipped
when a row is null), the validations after it
Parameters
client
a client whose statements run on one connection
steps
object[]
the steps with their statements
Returns
Promise<ContractStep[]>
the applied steps
backfill()
backfill(
client,table,from,to,batch?):Promise<number>
Defined in: packages/sql/src/relational/manager.ts:363
Copy a column into another one, by batches of rows where the target is null and the source is not: the expand/contract step between the addition of a column and the switch of the reads
Parameters
client
the client
table
string
the table
from
string
the source column
to
string
the target column
batch?
number = 1000
rows per statement
Returns
Promise<number>
the number of rows updated
Throws
when the table or a column is not in the plan
build()
build(
models,knownModels,referencedTables?):RelationalSchemaPlan
Defined in: packages/sql/src/relational/manager.ts:87
Build the plan of the models of the store
Parameters
models
Iterable<SchemaModelMetadata>
the models of the store, subclasses included
knownModels
Iterable<SchemaModelMetadata>
every application model, to type the references to other stores
referencedTables?
{[identifier: string]: ReferencedTable; }
the tables of other stores a foreign key may reference, by model identifier
Returns
RelationalSchemaPlan
the plan
Throws
SchemaBuildError when the models cannot share their tables
changes()
protectedchanges(live,mode,livePlans):object
Defined in: packages/sql/src/relational/manager.ts:156
The additive changes and the drift of a database, the columns of the live versions left out of the drift
Parameters
live
the database
mode
"create" | "alter"
create or alter
livePlans
LiveSchemaPlan[]
the plans of the live versions
Returns
object
the steps and the drift
drift
drift:
SchemaDrift[]
steps
steps:
SchemaStep[]
contract()
contract(
client,live,retired):Promise<object[]>
Defined in: packages/sql/src/relational/manager.ts:287
What the contract phase can apply: the database of every table any version planned, compared with the union of the live plans
Parameters
client
the client
live
LiveSchemaPlan[]
the plans of the live versions, this one included
retired
RelationalSchemaPlan[]
the plans of the retired and expired versions
Returns
Promise<object[]>
the steps and their statements (empty for a step the engine cannot run)
createStatements()
createStatements():
string[]
Defined in: packages/sql/src/relational/manager.ts:128
Create statements
Returns
string[]
the DDL creating the whole plan on an empty database
diff()
diff(
client,livePlans?):Promise<{drift:SchemaDrift[];statements:string[];steps:SchemaStep[]; }>
Defined in: packages/sql/src/relational/manager.ts:179
Compare the database with the plan
Parameters
client
the client
livePlans?
LiveSchemaPlan[] = []
the plans of the live versions: their columns are not drift
Returns
Promise<{ drift: SchemaDrift[]; statements: string[]; steps: SchemaStep[]; }>
what alter would apply, what it never resolves, and the statements
planOptions()
protectedplanOptions():object
Defined in: packages/sql/src/relational/manager.ts:136
Return the planner options of the dialect
Returns
object
the planner options of the dialect
inlineForeignKeys?
optionalinlineForeignKeys?:boolean
render()
protectedrender(steps):string[]
Defined in: packages/sql/src/relational/manager.ts:145
Render operation
Parameters
steps
schema changes
Returns
string[]
their statements
requirePlan()
protectedrequirePlan():RelationalSchemaPlan
Defined in: packages/sql/src/relational/manager.ts:107
Return the plan
Returns
RelationalSchemaPlan
the plan
Throws
when build did not run
sync()
sync(
client,mode,hooks?):Promise<SchemaStep[]>
Defined in: packages/sql/src/relational/manager.ts:204
Bring the database to the plan
create and alter take the schema lock in a transaction, describe the database under it, apply the additive
steps and commit; the online steps the dialect keeps out of the transaction (CREATE INDEX CONCURRENTLY,
VALIDATE CONSTRAINT) run afterwards, one by one, and a failing one is logged and left out.
Parameters
client
a client whose statements run on one connection (the DDL runs in a transaction under the schema lock)
mode
what to do: nothing, create the missing tables, also extend the existing ones, or only check
hooks?
SchemaSyncHooks = {}
the registry hooks
Returns
Promise<SchemaStep[]>
the applied steps
Throws
SchemaDriftError in validate mode when anything is missing or differs
tableOf()
tableOf(
model):TablePlan|undefined
Defined in: packages/sql/src/relational/manager.ts:119
Return its table, undefined when the model is not in the plan
Parameters
model
string
a model identifier
Returns
TablePlan | undefined
its table, undefined when the model is not in the plan