This commit is contained in:
Umed Khudoiberdiev 2016-12-29 23:46:50 +05:00
parent 20d690396e
commit 35e4f55b61
4 changed files with 19 additions and 9 deletions

View File

@ -1,5 +1,9 @@
# 0.0.6 (latest)
* fixed bug when new column was'nt added properly in sqlite #157
# 0.0.6 (latest)
* added `JSONB` support for Postgres in #126 (thanks @CreepGin)
* fixed in in sqlite query runner in #141 (thanks @marcinwadon)
* added shortcut exports for table schema classes in #135 (thanks @eduardoweiland)

View File

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

View File

@ -429,7 +429,7 @@ export class SqliteQueryRunner implements QueryRunner {
const tableSchema = await this.getTableSchema(tableSchemaOrName);
const newTableSchema = tableSchema.clone();
newTableSchema.addColumns([column]);
await this.recreateTable(tableSchema);
await this.recreateTable(newTableSchema, tableSchema);
}
/**
@ -452,7 +452,7 @@ export class SqliteQueryRunner implements QueryRunner {
const tableSchema = await this.getTableSchema(tableSchemaOrName);
const newTableSchema = tableSchema.clone();
newTableSchema.addColumns(columns);
await this.recreateTable(tableSchema);
await this.recreateTable(newTableSchema, tableSchema);
}
/**
@ -818,7 +818,7 @@ export class SqliteQueryRunner implements QueryRunner {
return c;
}
protected async recreateTable(tableSchema: TableSchema): Promise<void> {
protected async recreateTable(tableSchema: TableSchema, oldTableSchema?: TableSchema): Promise<void> {
// const withoutForeignKeyColumns = columns.filter(column => column.foreignKeys.length === 0);
// const createForeignKeys = options && options.createForeignKeys;
const columnDefinitions = tableSchema.columns.map(dbColumn => this.buildCreateColumnSql(dbColumn)).join(", ");
@ -844,8 +844,11 @@ export class SqliteQueryRunner implements QueryRunner {
// recreate a table with a temporary name
await this.query(sql1);
// we need only select data from old columns
const oldColumnNames = oldTableSchema ? oldTableSchema.columns.map(column => `"${column.name}"`).join(", ") : columnNames;
// migrate all data from the table into temporary table
const sql2 = `INSERT INTO "temporary_${tableSchema.name}" SELECT ${columnNames} FROM "${tableSchema.name}"`;
const sql2 = `INSERT INTO "temporary_${tableSchema.name}"(${oldColumnNames}) SELECT ${oldColumnNames} FROM "${tableSchema.name}"`;
await this.query(sql2);
// drop old table

View File

@ -438,7 +438,7 @@ export class WebsqlQueryRunner implements QueryRunner {
const tableSchema = await this.getTableSchema(tableSchemaOrName);
const newTableSchema = tableSchema.clone();
newTableSchema.addColumns([column]);
await this.recreateTable(tableSchema);
await this.recreateTable(newTableSchema, tableSchema);
}
/**
@ -461,7 +461,7 @@ export class WebsqlQueryRunner implements QueryRunner {
const tableSchema = await this.getTableSchema(tableSchemaOrName);
const newTableSchema = tableSchema.clone();
newTableSchema.addColumns(columns);
await this.recreateTable(tableSchema);
await this.recreateTable(newTableSchema, tableSchema);
}
/**
@ -827,7 +827,7 @@ export class WebsqlQueryRunner implements QueryRunner {
return c;
}
protected async recreateTable(tableSchema: TableSchema): Promise<void> {
protected async recreateTable(tableSchema: TableSchema, oldTableSchema?: TableSchema): Promise<void> {
// const withoutForeignKeyColumns = columns.filter(column => column.foreignKeys.length === 0);
// const createForeignKeys = options && options.createForeignKeys;
const columnDefinitions = tableSchema.columns.map(dbColumn => this.buildCreateColumnSql(dbColumn)).join(", ");
@ -853,8 +853,11 @@ export class WebsqlQueryRunner implements QueryRunner {
// recreate a table with a temporary name
await this.query(sql1);
// we need only select data from old columns
const oldColumnNames = oldTableSchema ? oldTableSchema.columns.map(column => `"${column.name}"`).join(", ") : columnNames;
// migrate all data from the table into temporary table
const sql2 = `INSERT INTO "temporary_${tableSchema.name}" SELECT ${columnNames} FROM "${tableSchema.name}"`;
const sql2 = `INSERT INTO "temporary_${tableSchema.name}"${oldColumnNames} SELECT ${oldColumnNames} FROM "${tableSchema.name}"`;
await this.query(sql2);
// drop old table