Skip to main content
Module

x/typeorm/src/schema-builder/RdbmsSchemaBuilder.ts>RdbmsSchemaBuilder

Forked from https://github.com/typeorm/typeorm
Latest
class RdbmsSchemaBuilder
implements SchemaBuilder
import { RdbmsSchemaBuilder } from "https://deno.land/x/typeorm@v0.2.23-rc10/src/schema-builder/RdbmsSchemaBuilder.ts";

Creates complete tables schemas in the database based on the entity metadatas.

Steps how schema is being built:

  1. load list of all tables with complete column and keys information from the db
  2. drop all (old) foreign keys that exist in the table, but does not exist in the metadata
  3. create new tables that does not exist in the db, but exist in the metadata
  4. drop all columns exist (left old) in the db table, but does not exist in the metadata
  5. add columns from metadata which does not exist in the table
  6. update all exist columns which metadata has changed
  7. update primary keys - update old and create new primary key from changed columns
  8. create foreign keys which does not exist in the table yet
  9. create indices which are missing in db yet, and drops indices which exist in the db, but does not exist in the metadata anymore

Constructors

new
RdbmsSchemaBuilder(connection: Connection)

Properties

protected
readonly
entityToSyncMetadatas: EntityMetadata[]

Returns only entities that should be synced in the database.

protected
queryRunner: QueryRunner

Used to execute schema creation queries in a single connection.

protected
readonly
viewEntityToSyncMetadatas: EntityMetadata[]

Returns only entities that should be synced in the database.

Methods

protected
addNewColumns(): Promise<void>

Adds columns from metadata which does not exist in the table. Columns are created without keys.

protected
createCompositeUniqueConstraints(): Promise<void>

Creates composite uniques which are missing in db yet.

protected
createForeignKeys(): Promise<void>

Creates foreign keys which does not exist in the table yet.

protected
createNewChecks(): Promise<void>
protected
createNewExclusions(): Promise<void>

Creates exclusions which are missing in db yet.

protected
createNewIndices(): Promise<void>

Creates composite indices which are missing in db yet.

protected
createNewTables(): Promise<void>

Creates tables that do not exist in the database yet. New tables are created without foreign and primary keys. Primary key only can be created in conclusion with auto generated column.

Creates typeorm service table for storing user defined Views.

protected
createViews(): Promise<void>
protected
dropColumnCompositeIndices(tablePath: string, columnName: string): Promise<void>

Drops all composite indices, related to given column.

protected
dropColumnCompositeUniques(tablePath: string, columnName: string): Promise<void>

Drops all composite uniques, related to given column.

protected
dropColumnReferencedForeignKeys(tablePath: string, columnName: string): Promise<void>

Drops all foreign keys where given column of the given table is being used.

protected
dropCompositeUniqueConstraints(): Promise<void>
protected
dropOldChecks(): Promise<void>
protected
dropOldExclusions(): Promise<void>
protected
dropOldForeignKeys(): Promise<void>

Drops all (old) foreign keys that exist in the tables, but do not exist in the entity metadata.

protected
dropOldIndices(): Promise<void>
protected
dropOldViews(): Promise<void>
protected
dropRemovedColumns(): Promise<void>

Drops all columns that exist in the table, but does not exist in the metadata (left old). We drop their keys too, since it should be safe.

Executes schema sync operations in a proper order. Order of operations matter here.

protected
metadataColumnsToTableColumnOptions(columns: ColumnMetadata[]): TableColumnOptions[]

Creates new columns from the given column metadatas.

protected
renameColumns(): Promise<void>

Renames columns. Works if only one column per table was changed. Changes only column name. If something besides name was changed, these changes will be ignored.

protected
renameTables(): Promise<void>

Rename tables

protected
updateExistColumns(): Promise<void>

Update all exist columns which metadata has changed. Still don't create keys. Also we don't touch foreign keys of the changed columns.

protected
updatePrimaryKeys(): Promise<void>

Updates composite primary keys.

build(): Promise<void>

Creates complete schemas for the given entity metadatas.

log(): Promise<SqlInMemory>

Returns sql queries to be executed by schema builder.