Skip to main content
Version: 5.9

SchemaGenerator

Should be renamed to SqlSchemaGenerator in v6

Hierarchy

  • AbstractSchemaGenerator<AbstractSqlDriver>
    • SchemaGenerator

Index

Constructors

constructor

  • new SchemaGenerator(em: EntityManager<IDatabaseDriver<Connection>> | AbstractSqlDriver<AbstractSqlConnection, AbstractSqlPlatform>): SchemaGenerator
  • Parameters

    • em: EntityManager<IDatabaseDriver<Connection>> | AbstractSqlDriver<AbstractSqlConnection, AbstractSqlPlatform>

    Returns SchemaGenerator

Methods

clearDatabase

  • clearDatabase(options?: { schema?: string; truncate?: boolean }): Promise<void>
  • Parameters

    • optionaloptions: { schema?: string; truncate?: boolean }
      • optionalschema: string
      • optionaltruncate: boolean

    Returns Promise<void>

createDatabase

  • createDatabase(name: string): Promise<void>
  • creates new database and connects to it


    Parameters

    • name: string

    Returns Promise<void>

createSchema

  • createSchema(options?: { schema?: string; wrap?: boolean }): Promise<void>
  • Parameters

    • optionaloptions: { schema?: string; wrap?: boolean }
      • optionalschema: string
      • optionalwrap: boolean

    Returns Promise<void>

diffToSQL

  • diffToSQL(schemaDiff: SchemaDifference, options: { dropTables?: boolean; safe?: boolean; schema?: string; wrap?: boolean }): Promise<string>
  • Parameters

    • schemaDiff: SchemaDifference
    • options: { dropTables?: boolean; safe?: boolean; schema?: string; wrap?: boolean }
      • optionaldropTables: boolean
      • optionalsafe: boolean
      • optionalschema: string
      • optionalwrap: boolean

    Returns Promise<string>

dropDatabase

  • dropDatabase(name?: string): Promise<void>
  • Parameters

    • optionalname: string

    Returns Promise<void>

dropSchema

  • dropSchema(options?: { dropDb?: boolean; dropMigrationsTable?: boolean; schema?: string; wrap?: boolean }): Promise<void>
  • Parameters

    • options: { dropDb?: boolean; dropMigrationsTable?: boolean; schema?: string; wrap?: boolean } = {}
      • optionaldropDb: boolean
      • optionaldropMigrationsTable: boolean
      • optionalschema: string
      • optionalwrap: boolean

    Returns Promise<void>

ensureDatabase

  • ensureDatabase(): Promise<boolean>
  • Returns true if the database was created.


    Returns Promise<boolean>

ensureIndexes

  • ensureIndexes(): Promise<void>
  • Returns Promise<void>

execute

  • execute(sql: string, options?: { wrap?: boolean }): Promise<undefined>
  • Parameters

    • sql: string
    • options: { wrap?: boolean } = {}
      • optionalwrap: boolean

    Returns Promise<undefined>

generate

  • generate(): Promise<string>
  • @deprecated

    use dropSchema and createSchema commands respectively


    Returns Promise<string>

getCreateSchemaSQL

  • getCreateSchemaSQL(options?: { schema?: string; wrap?: boolean }): Promise<string>
  • Parameters

    • options: { schema?: string; wrap?: boolean } = {}
      • optionalschema: string
      • optionalwrap: boolean

    Returns Promise<string>

getDropSchemaSQL

  • getDropSchemaSQL(options?: { dropMigrationsTable?: boolean; schema?: string; wrap?: boolean }): Promise<string>
  • Parameters

    • options: { dropMigrationsTable?: boolean; schema?: string; wrap?: boolean } = {}
      • optionaldropMigrationsTable: boolean
      • optionalschema: string
      • optionalwrap: boolean

    Returns Promise<string>

getTargetSchema

  • getTargetSchema(schema?: string): DatabaseSchema
  • Parameters

    • optionalschema: string

    Returns DatabaseSchema

getUpdateSchemaMigrationSQL

  • getUpdateSchemaMigrationSQL(options?: { dropTables?: boolean; fromSchema?: DatabaseSchema; safe?: boolean; schema?: string; wrap?: boolean }): Promise<{ down: string; up: string }>
  • Parameters

    • options: { dropTables?: boolean; fromSchema?: DatabaseSchema; safe?: boolean; schema?: string; wrap?: boolean } = {}
      • optionaldropTables: boolean
      • optionalfromSchema: DatabaseSchema
      • optionalsafe: boolean
      • optionalschema: string
      • optionalwrap: boolean

    Returns Promise<{ down: string; up: string }>

getUpdateSchemaSQL

  • getUpdateSchemaSQL(options?: { dropTables?: boolean; fromSchema?: DatabaseSchema; safe?: boolean; schema?: string; wrap?: boolean }): Promise<string>
  • Parameters

    • options: { dropTables?: boolean; fromSchema?: DatabaseSchema; safe?: boolean; schema?: string; wrap?: boolean } = {}
      • optionaldropTables: boolean
      • optionalfromSchema: DatabaseSchema
      • optionalsafe: boolean
      • optionalschema: string
      • optionalwrap: boolean

    Returns Promise<string>

refreshDatabase

  • refreshDatabase(): Promise<void>
  • Returns Promise<void>

updateSchema

  • updateSchema(options?: { dropTables?: boolean; fromSchema?: DatabaseSchema; safe?: boolean; schema?: string; wrap?: boolean }): Promise<void>
  • Parameters

    • options: { dropTables?: boolean; fromSchema?: DatabaseSchema; safe?: boolean; schema?: string; wrap?: boolean } = {}
      • optionaldropTables: boolean
      • optionalfromSchema: DatabaseSchema
      • optionalsafe: boolean
      • optionalschema: string
      • optionalwrap: boolean

    Returns Promise<void>

staticregister

  • register(orm: MikroORM<IDatabaseDriver<Connection>>): void
  • Parameters

    • orm: MikroORM<IDatabaseDriver<Connection>>

    Returns void