bugfixes in CLI commands; removed deprecated connection options

This commit is contained in:
Umed Khudoiberdiev 2017-09-27 11:59:32 +05:00
parent da0fe5e846
commit 00887d2a2a
19 changed files with 44 additions and 67 deletions

View File

@ -66,11 +66,7 @@ Also now all
* Now `logging` options in connection options is simple "true", or "all", or list of logging modes can be supplied
* removed `driver` section in connection options. Define options right in the connection options section.
* `Embedded` decorator is deprecated now. use `@Column(type => SomeEmbedded)` instead
* `tablesPrefix` in connection options is deprecated. Use `entityPrefix` instead
* `autoMigrationsRun` in connection options is deprecated. Use `migrationsRun` instead
* `autoSchemaSync` in connection options is deprecated. Use `synchronize` instead
* `dropSchemaOnConnection` in connection options is deprecated. Use `dropSchema` instead
* `schemaName` in connection options is deprecated. Use `schema` instead
* `schemaName` in connection options is removed. Use `schema` instead
* `TYPEORM_AUTO_SCHEMA_SYNC` env variable is now called `TYPEORM_SYNCHRONIZE`
* `schemaSync` method in `Connection` has been renamed to `synchronize`
* `getEntityManager` has been deprecated. Use `getManager` instead.
@ -78,6 +74,7 @@ Also now all
* `EmbeddableEntity`, `Embedded`, `AbstractEntity` decorators has been removed.
There is no need to use `EmbeddableEntity` and `AbstractEntity` decorators at all - entity will work as expected without them.
Instead of `@Embedded(type => X)` decorator now `@Column(type => X)` must be used instead
* `tablesPrefix`, `autoSchemaSync`, `autoMigrationsRun`, `dropSchemaOnConnection` options were removed. Use `entityPrefix`, `synchronize`, `migrationsRun`, `dropSchema` options instead
### NEW FEATURES

View File

@ -259,7 +259,7 @@ createConnection({
entities: [
Photo
],
autoSchemaSync: true,
synchronize: true,
}).then(connection => {
// 这里可以写实体操作相关的代码
}).catch(error => console.log(error));
@ -271,7 +271,7 @@ mysql, mariadb, postgres, sqlite, mssql or oracle.
把Photo实体加到数据连接的实体列表中所有需要在这个连接下使用的实体都必须加到这个列表中。
`autoSchemaSync`选项可以在应用启动时确保你的实体和数据库保持同步。
`synchronize`选项可以在应用启动时确保你的实体和数据库保持同步。
### 引用目录下的所有实体
@ -293,7 +293,7 @@ createConnection({
entities: [
__dirname + "/entity/*.js"
],
autoSchemaSync: true,
synchronize: true,
}).then(connection => {
// here you can start to work with your entities
}).catch(error => console.log(error));

View File

@ -336,11 +336,11 @@ createConnection({
port: 3306,
username: "root",
password: "admin",
database: "test"
database: "test",
entities: [
Photo
],
autoSchemaSync: true,
synchronize: true,
}).then(connection => {
// Here you can start to work with your entities
}).catch(error => console.log(error));
@ -354,7 +354,7 @@ Also make sure to use your own host, port, username, password and database setti
We added our Photo entity to the list of entities for this connection.
Each entity you are using in your connection must be listed here.
Setting `autoSchemaSync` makes sure your entities will be synced with the database, every time you run the application.
Setting `synchronize` makes sure your entities will be synced with the database, every time you run the application.
### Loading all entities from the directory
@ -374,7 +374,7 @@ createConnection({
entities: [
__dirname + "/entity/*.js"
],
autoSchemaSync: true,
synchronize: true,
}).then(connection => {
// Here you can start to work with your entities
}).catch(error => console.log(error));

View File

@ -44,7 +44,7 @@ createConnection({
entities: [
Photo
],
autoSchemaSync: true
synchronize: true
});
```

View File

@ -21,7 +21,7 @@ typeorm.createConnection({
require("./entity/Post"),
require("./entity/Category")
],
autoSchemaSync: true
synchronize: true
}).then(function (connection) {
var category1 = {

View File

@ -1,7 +1,7 @@
{
"name": "typeorm",
"private": true,
"version": "0.1.0-alpha.47",
"version": "0.1.0-alpha.48",
"description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, WebSQL, MongoDB databases.",
"license": "MIT",
"readmeFilename": "README.md",

View File

@ -33,9 +33,9 @@ export class CacheClearCommand {
const connectionOptions = await connectionOptionsReader.get(argv.connection);
Object.assign(connectionOptions, {
subscribers: [],
dropSchemaOnConnection: false,
autoSchemaSync: false,
autoMigrationsRun: false,
synchronize: false,
migrationsRun: false,
dropSchema: false,
logging: ["schema"]
});
connection = await createConnection(connectionOptions);

View File

@ -55,9 +55,9 @@ export class MigrationGenerateCommand {
const connectionOptionsReader = new ConnectionOptionsReader({ root: process.cwd(), configName: argv.config });
const connectionOptions = await connectionOptionsReader.get(argv.connection);
Object.assign(connectionOptions, {
dropSchemaOnConnection: false,
autoSchemaSync: false,
autoMigrationsRun: false,
synchronize: false,
migrationsRun: false,
dropSchema: false,
logging: false
});
connection = await createConnection(connectionOptions);
@ -81,11 +81,12 @@ export class MigrationGenerateCommand {
downSqls.push(" await queryRunner.query(`" + query.down.replace(new RegExp("`", "g"), "\\`") + "`);");
});
}
const fileContent = MigrationGenerateCommand.getTemplate(argv.name, timestamp, upSqls, downSqls.reverse());
const path = process.cwd() + "/" + (directory ? (directory + "/") : "") + filename;
await CommandUtils.createFile(path, fileContent);
if (upSqls.length) {
const fileContent = MigrationGenerateCommand.getTemplate(argv.name, timestamp, upSqls, downSqls.reverse());
const path = process.cwd() + "/" + (directory ? (directory + "/") : "") + filename;
await CommandUtils.createFile(path, fileContent);
console.log(chalk.green(`Migration ${chalk.blue(path)} has been generated successfully.`));
} else {

View File

@ -33,9 +33,9 @@ export class MigrationRevertCommand {
const connectionOptions = await connectionOptionsReader.get(argv.connection);
Object.assign(connectionOptions, {
subscribers: [],
dropSchemaOnConnection: false,
autoSchemaSync: false,
autoMigrationsRun: false,
synchronize: false,
migrationsRun: false,
dropSchema: false,
logging: ["schema"]
});
connection = await createConnection(connectionOptions);

View File

@ -35,7 +35,6 @@ export class MigrationRunCommand {
const connectionOptions = await connectionOptionsReader.get(argv.connection);
Object.assign(connectionOptions, {
subscribers: [],
dropSchemaOnConnection: false,
synchronize: false,
migrationsRun: false,
dropSchema: false,

View File

@ -36,9 +36,9 @@ export class QueryCommand {
const connectionOptionsReader = new ConnectionOptionsReader({ root: process.cwd(), configName: argv.config });
const connectionOptions = await connectionOptionsReader.get(argv.connection);
Object.assign(connectionOptions, {
dropSchemaOnConnection: false,
autoSchemaSync: false,
autoMigrationsRun: false,
synchronize: false,
migrationsRun: false,
dropSchema: false,
logging: false
});
connection = await createConnection(connectionOptions);

View File

@ -33,9 +33,9 @@ export class SchemaDropCommand {
const connectionOptionsReader = new ConnectionOptionsReader({ root: process.cwd(), configName: argv.config });
const connectionOptions = await connectionOptionsReader.get(argv.connection);
Object.assign(connectionOptions, {
dropSchemaOnConnection: false,
autoSchemaSync: false,
autoMigrationsRun: false,
synchronize: false,
migrationsRun: false,
dropSchema: false,
logging: ["query", "schema"]
});
connection = await createConnection(connectionOptions);

View File

@ -35,9 +35,9 @@ export class SchemaLogCommand {
const connectionOptionsReader = new ConnectionOptionsReader({ root: process.cwd(), configName: argv.config });
const connectionOptions = await connectionOptionsReader.get(argv.connection);
Object.assign(connectionOptions, {
dropSchemaOnConnection: false,
autoSchemaSync: false,
autoMigrationsRun: false,
synchronize: false,
migrationsRun: false,
dropSchema: false,
logging: false
});
connection = await createConnection(connectionOptions);

View File

@ -32,9 +32,9 @@ export class SchemaSyncCommand {
const connectionOptionsReader = new ConnectionOptionsReader({ root: process.cwd(), configName: argv.config });
const connectionOptions = await connectionOptionsReader.get(argv.connection);
Object.assign(connectionOptions, {
dropSchemaOnConnection: false,
autoSchemaSync: false,
autoMigrationsRun: false,
synchronize: false,
migrationsRun: false,
dropSchema: false,
logging: ["query", "schema"]
});
connection = await createConnection(connectionOptions);

View File

@ -158,24 +158,4 @@ export interface BaseConnectionOptions {
};
/**
* @deprecated - Use entityPrefix instead
*/
readonly tablesPrefix?: string;
/**
* @deprecated - Use synchronize instead
*/
readonly autoSchemaSync?: boolean;
/**
* @deprecated - Use migrationsRun instead
*/
readonly autoMigrationsRun?: boolean;
/**
* @deprecated - Use dropSchema instead
*/
readonly dropSchemaOnConnection?: boolean;
}

View File

@ -160,15 +160,15 @@ export class Connection {
await this.driver.afterConnect();
// if option is set - drop schema once connection is done
if (this.options.dropSchema || this.options.dropSchemaOnConnection)
if (this.options.dropSchema)
await this.dropDatabase();
// if option is set - automatically synchronize a schema
if (this.options.synchronize || this.options.autoSchemaSync)
if (this.options.synchronize)
await this.synchronize();
// if option is set - automatically synchronize a schema
if (this.options.migrationsRun || this.options.autoMigrationsRun)
if (this.options.migrationsRun)
await this.runMigrations();
} catch (error) {

View File

@ -27,7 +27,7 @@ export class ConnectionOptionsXmlReader {
database: connection.database ? connection.database[0] : undefined,
sid: connection.sid ? connection.sid[0] : undefined,
extra: connection.extra ? connection.extra[0] : undefined,
autoSchemaSync: connection.autoSchemaSync ? connection.autoSchemaSync[0] : undefined,
synchronize: connection.synchronize ? connection.synchronize[0] : undefined,
entities: connection.entities ? connection.entities[0].entity : [],
subscribers: connection.subscribers ? connection.subscribers[0].entity : [],
entitySchemas: connection.entitySchemas ? connection.entitySchemas[0].entity : [],

View File

@ -390,7 +390,7 @@ export class EntityMetadata {
args: TableMetadataArgs
}) {
const namingStrategy = options.connection.namingStrategy;
const entityPrefix = options.connection.options.entityPrefix || options.connection.options.tablesPrefix;
const entityPrefix = options.connection.options.entityPrefix;
this.lazyRelationsWrapper = new LazyRelationsWrapper(options.connection);
this.parentClosureEntityMetadata = options.parentClosureEntityMetadata!;
this.target = options.args.target;

View File

@ -159,7 +159,7 @@ describe("ConnectionManager", () => {
/* it("should drop the database if dropSchema was set to true (postgres)", async () => {
const options: ConnectionOptions = {
dropSchema: true,
autoSchemaSync: true,
synchronize: true,
driver: createTestingConnectionOptions("postgres"),
entities: [Post]
};
@ -182,7 +182,7 @@ describe("ConnectionManager", () => {
/* it("should drop the database if dropSchema was set to true (postgres)", async () => {
const options: ConnectionOptions = {
dropSchema: true,
autoSchemaSync: true,
synchronize: true,
driver: createTestingConnectionOptions("postgres"),
entities: [Post]
};