MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / fromMetadata

Method fromMetadata

packages/sql/src/schema/DatabaseSchema.ts:203–379  ·  view source on GitHub ↗
(
    metadata: EntityMetadata[],
    platform: AbstractSqlPlatform,
    config: Configuration,
    schemaName?: string,
    em?: any,
  )

Source from the content-addressed store, hash-verified

201 }
202
203 static fromMetadata(
204 metadata: EntityMetadata[],
205 platform: AbstractSqlPlatform,
206 config: Configuration,
207 schemaName?: string,
208 em?: any,
209 ): DatabaseSchema {
210 const schema = new DatabaseSchema(platform, schemaName ?? config.get('schema'));
211 const nativeEnums: Dictionary<{ name: string; schema?: string; items: string[] }> = {};
212 const skipColumns = config.get('schemaGenerator').skipColumns || {};
213
214 for (const meta of metadata) {
215 // Skip view entities when collecting native enums
216 if (meta.view) {
217 continue;
218 }
219
220 for (const prop of meta.props) {
221 if (prop.nativeEnumName) {
222 let key = prop.nativeEnumName;
223 let enumName = prop.nativeEnumName;
224 let enumSchema = meta.schema ?? schema.name;
225
226 if (key.includes('.')) {
227 const [explicitSchema, ...parts] = prop.nativeEnumName.split('.');
228 enumName = parts.join('.');
229 key = enumName;
230 enumSchema = explicitSchema;
231 }
232
233 if (enumSchema && enumSchema !== '*' && enumSchema !== platform.getDefaultSchemaName()) {
234 key = enumSchema + '.' + key;
235 }
236
237 nativeEnums[key] = {
238 name: enumName,
239 schema: enumSchema,
240 items: prop.items?.map(val => '' + val) ?? [],
241 };
242 }
243 }
244 }
245
246 schema.setNativeEnums(nativeEnums);
247
248 for (const meta of metadata) {
249 // Handle view entities separately
250 if (meta.view) {
251 const viewDefinition = this.getViewDefinition(meta, em, platform);
252 if (viewDefinition) {
253 const view = schema.addView(
254 meta.collection,
255 this.getSchemaName(meta, config, schemaName),
256 viewDefinition,
257 meta.materialized,
258 meta.withData,
259 );
260

Callers 1

getTargetSchemaMethod · 0.45

Calls 15

setNativeEnumsMethod · 0.95
getViewDefinitionMethod · 0.95
addViewMethod · 0.95
getSchemaNameMethod · 0.95
addIndexMethod · 0.95
getIndexesMethod · 0.95
addTableMethod · 0.95
shouldHaveColumnMethod · 0.95
addTPTForeignKeyMethod · 0.95
isRawFunction · 0.90
getTablePartitioningFunction · 0.85
filterMethod · 0.80

Tested by

no test coverage detected