mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
controller / subscriber / migrations from options tsconfig now appended with a project root directory
This commit is contained in:
parent
c5d0dee8fa
commit
de7237315f
@ -25,6 +25,7 @@ each for its own `findOne*` or `find*` methods
|
||||
* `transaction` method has been removed from `Repository`. Use `EntityManager#transaction` method instead
|
||||
* custom repositories do not support container anymore
|
||||
* added ActiveRecord support (by extending EntityModel) class
|
||||
* controller / subscriber / migrations from options tsconfig now appended with a project root directory
|
||||
|
||||
|
||||
### NEW FEATURES
|
||||
|
||||
@ -384,13 +384,47 @@ export class ConnectionManager {
|
||||
throw new Error(`Configuration ${path || "ormconfig.json"} was not found. Add connection configuration inside ormconfig.json file.`);
|
||||
|
||||
const environmentLessOptions = optionsArray.filter(options => (options.name || "default") === connectionName);
|
||||
const options = environmentLessOptions.filter(options => !options.environment || options.environment === PlatformTools.getEnvVariable("NODE_ENV")); // skip connection creation if environment is set in the options, and its not equal to the value in the NODE_ENV variable
|
||||
const options = environmentLessOptions.find(options => !options.environment || options.environment === PlatformTools.getEnvVariable("NODE_ENV")); // skip connection creation if environment is set in the options, and its not equal to the value in the NODE_ENV variable
|
||||
|
||||
if (!options.length)
|
||||
if (!options)
|
||||
throw new Error(`Connection "${connectionName}" ${PlatformTools.getEnvVariable("NODE_ENV") ? "for the environment " + PlatformTools.getEnvVariable("NODE_ENV") + " " : ""}was not found in the json configuration file.` +
|
||||
(environmentLessOptions.length ? ` However there are such configurations for other environments: ${environmentLessOptions.map(options => options.environment).join(", ")}.` : ""));
|
||||
|
||||
return this.createAndConnectByConnectionOptions(options[0]);
|
||||
// normalize directory paths
|
||||
if (options.entities) {
|
||||
options.entities = (options.entities as any[]).map(entity => {
|
||||
if (typeof entity === "string" || entity.substr(0, 1) !== "/")
|
||||
return PlatformTools.load("app-root-path").path + "/" + entity;
|
||||
|
||||
return entity;
|
||||
});
|
||||
}
|
||||
if (options.subscribers) {
|
||||
options.subscribers = (options.subscribers as any[]).map(subscriber => {
|
||||
if (typeof subscriber === "string" || subscriber.substr(0, 1) !== "/")
|
||||
return PlatformTools.load("app-root-path").path + "/" + subscriber;
|
||||
|
||||
return subscriber;
|
||||
});
|
||||
}
|
||||
if (options.migrations) {
|
||||
options.migrations = (options.migrations as any[]).map(migration => {
|
||||
if (typeof migration === "string" || migration.substr(0, 1) !== "/")
|
||||
return PlatformTools.load("app-root-path").path + "/" + migration;
|
||||
|
||||
return migration;
|
||||
});
|
||||
}
|
||||
if (options.namingStrategies) {
|
||||
options.namingStrategies = (options.namingStrategies as any[]).map(namingStrategy => {
|
||||
if (typeof namingStrategy === "string" || namingStrategy.substr(0, 1) !== "/")
|
||||
return PlatformTools.load("app-root-path").path + "/" + namingStrategy;
|
||||
|
||||
return namingStrategy;
|
||||
});
|
||||
}
|
||||
|
||||
return this.createAndConnectByConnectionOptions(options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -12,65 +12,65 @@ export interface ConnectionOptions {
|
||||
/**
|
||||
* Database options of this connection.
|
||||
*/
|
||||
readonly driver: DriverOptions;
|
||||
driver: DriverOptions;
|
||||
|
||||
/**
|
||||
* Connection name. If connection name is not given then it will be called "default".
|
||||
* Different connections must have different names.
|
||||
*/
|
||||
readonly name?: string;
|
||||
name?: string;
|
||||
|
||||
/**
|
||||
* Name of the naming strategy or target class of the naming strategy to be used for this connection.
|
||||
*/
|
||||
readonly usedNamingStrategy?: string|Function;
|
||||
usedNamingStrategy?: string|Function;
|
||||
|
||||
/**
|
||||
* Entities to be loaded for this connection.
|
||||
* Accepts both entity classes and directories where from entities need to be loaded.
|
||||
* Directories support glob patterns.
|
||||
*/
|
||||
readonly entities?: Function[]|string[];
|
||||
entities?: Function[]|string[];
|
||||
|
||||
/**
|
||||
* Subscribers to be loaded for this connection.
|
||||
* Accepts both subscriber classes and directories where from subscribers need to be loaded.
|
||||
* Directories support glob patterns.
|
||||
*/
|
||||
readonly subscribers?: Function[]|string[];
|
||||
subscribers?: Function[]|string[];
|
||||
|
||||
/**
|
||||
* Naming strategies to be loaded for this connection.
|
||||
* Accepts both naming strategy classes and directories where from naming strategies need to be loaded.
|
||||
* Directories support glob patterns.
|
||||
*/
|
||||
readonly namingStrategies?: Function[]|string[];
|
||||
namingStrategies?: Function[]|string[];
|
||||
|
||||
/**
|
||||
* Entity schemas to be loaded for this connection.
|
||||
* Accepts both entity schema classes and directories where from entity schemas need to be loaded.
|
||||
* Directories support glob patterns.
|
||||
*/
|
||||
readonly entitySchemas?: EntitySchema[]|string[];
|
||||
entitySchemas?: EntitySchema[]|string[];
|
||||
|
||||
/**
|
||||
* Migrations to be loaded for this connection.
|
||||
* Accepts both migration classes and directories where from migrations need to be loaded.
|
||||
* Directories support glob patterns.
|
||||
*/
|
||||
readonly migrations?: Function[]|string[];
|
||||
migrations?: Function[]|string[];
|
||||
|
||||
/**
|
||||
* Logging options.
|
||||
*/
|
||||
readonly logging?: LoggerOptions;
|
||||
logging?: LoggerOptions;
|
||||
|
||||
/**
|
||||
* Drops the schema each time connection is being established.
|
||||
* Be careful with this option and don't use this in production - otherwise you'll loose all production data.
|
||||
* This option is useful during debug and development.
|
||||
*/
|
||||
readonly dropSchemaOnConnection?: boolean;
|
||||
dropSchemaOnConnection?: boolean;
|
||||
|
||||
/**
|
||||
* Indicates if database schema should be auto created on every application launch.
|
||||
@ -83,7 +83,7 @@ export interface ConnectionOptions {
|
||||
*
|
||||
* todo: rename it simply to synchronize: boolean ?
|
||||
*/
|
||||
readonly autoSchemaSync?: boolean;
|
||||
autoSchemaSync?: boolean;
|
||||
|
||||
/**
|
||||
* Indicates if migrations should be auto run on every application launch.
|
||||
@ -91,7 +91,7 @@ export interface ConnectionOptions {
|
||||
*
|
||||
* todo: rename it simply to runMigrations: boolean ?
|
||||
*/
|
||||
readonly autoMigrationsRun?: boolean;
|
||||
autoMigrationsRun?: boolean;
|
||||
|
||||
/**
|
||||
* Environment in which connection will run.
|
||||
@ -100,27 +100,27 @@ export interface ConnectionOptions {
|
||||
* then this connection will be created. On any other NODE_ENV value it will be skipped.
|
||||
* This option is specific to the configuration in the ormconfig.json file.
|
||||
*/
|
||||
readonly environment?: string;
|
||||
environment?: string;
|
||||
|
||||
/**
|
||||
* CLI settings.
|
||||
*/
|
||||
readonly cli?: {
|
||||
cli?: {
|
||||
|
||||
/**
|
||||
* Directory where entities should be created by default.
|
||||
*/
|
||||
readonly entitiesDir?: string;
|
||||
entitiesDir?: string;
|
||||
|
||||
/**
|
||||
* Directory where migrations should be created by default.
|
||||
*/
|
||||
readonly migrationsDir?: string;
|
||||
migrationsDir?: string;
|
||||
|
||||
/**
|
||||
* Directory where subscribers should be created by default.
|
||||
*/
|
||||
readonly subscribersDir?: string;
|
||||
subscribersDir?: string;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user