mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixes #195 unique index is not being created
This commit is contained in:
parent
8884789d31
commit
1f7065fa67
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "typeorm",
|
||||
"private": true,
|
||||
"version": "0.0.7-alpha.13",
|
||||
"version": "0.0.7-alpha.14",
|
||||
"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",
|
||||
|
||||
@ -4,49 +4,19 @@ import {Post} from "./entity/Post";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: {
|
||||
// type: "postgres",
|
||||
// host: "localhost",
|
||||
// port: 5432,
|
||||
// username: "root",
|
||||
// password: "admin",
|
||||
// database: "test"
|
||||
type: "oracle",
|
||||
host: "localhost",
|
||||
username: "system",
|
||||
password: "oracle",
|
||||
port: 1521,
|
||||
sid: "xe.oracle.docker",
|
||||
// type: "mssql",
|
||||
// host: "192.168.1.10",
|
||||
// username: "sa",
|
||||
// password: "admin12345",
|
||||
// database: "test",
|
||||
// port: 1521
|
||||
// type: "sqlite",
|
||||
// storage: "temp/sqlitedb.db"
|
||||
type: "sqlite",
|
||||
storage: "temp/sqlitedb.db"
|
||||
},
|
||||
logging: {
|
||||
logQueries: true,
|
||||
logSchemaCreation: true
|
||||
},
|
||||
autoSchemaSync: true,
|
||||
entities: [Post]
|
||||
dropSchemaOnConnection: true,
|
||||
entities: [
|
||||
Post
|
||||
]
|
||||
};
|
||||
/*const options: CreateConnectionOptions = {
|
||||
driver: "postgres",
|
||||
driverOptions: {
|
||||
host: "localhost",
|
||||
port: 5432,
|
||||
username: "test",
|
||||
password: "admin",
|
||||
database: "test",
|
||||
autoSchemaSync: true,
|
||||
logging: {
|
||||
logQueries: true
|
||||
}
|
||||
},
|
||||
entities: [Post]
|
||||
};*/
|
||||
|
||||
createConnection(options).then(connection => {
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import {Column, Entity} from "../../../src/index";
|
||||
import {PrimaryColumn} from "../../../src/decorator/columns/PrimaryColumn";
|
||||
import {Index} from "../../../src/decorator/Index";
|
||||
|
||||
@Entity("sample01_post")
|
||||
export class Post {
|
||||
@ -8,6 +9,7 @@ export class Post {
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
@Index({ unique: true })
|
||||
title: string;
|
||||
|
||||
@Column()
|
||||
|
||||
@ -35,12 +35,14 @@ export function Index(name: string, fields: (object: any) => any[], options?: In
|
||||
/**
|
||||
* Composite index must be set on entity classes and must specify entity's fields to be indexed.
|
||||
*/
|
||||
export function Index(nameOrFields: string|string[]|((object: any) => any[]),
|
||||
export function Index(nameOrFieldsOrOptions: string|string[]|((object: any) => any[])|IndexOptions,
|
||||
maybeFieldsOrOptions?: ((object: any) => any[])|IndexOptions|string[],
|
||||
maybeOptions?: IndexOptions): Function {
|
||||
const name = typeof nameOrFields === "string" ? nameOrFields : undefined;
|
||||
const fields = typeof nameOrFields === "string" ? <((object: any) => any[])|string[]> maybeFieldsOrOptions : nameOrFields;
|
||||
const options = (typeof maybeFieldsOrOptions === "object" && !Array.isArray(maybeFieldsOrOptions)) ? <IndexOptions> maybeFieldsOrOptions : maybeOptions;
|
||||
const name = typeof nameOrFieldsOrOptions === "string" ? nameOrFieldsOrOptions : undefined;
|
||||
const fields = typeof nameOrFieldsOrOptions === "string" ? <((object: any) => any[])|string[]> maybeFieldsOrOptions : nameOrFieldsOrOptions as string[];
|
||||
let options = (typeof nameOrFieldsOrOptions === "object" && !Array.isArray(nameOrFieldsOrOptions)) ? nameOrFieldsOrOptions as IndexOptions : maybeOptions;
|
||||
if (!options)
|
||||
options = (typeof maybeFieldsOrOptions === "object" && !Array.isArray(maybeFieldsOrOptions)) ? nameOrFieldsOrOptions as IndexOptions : maybeOptions;
|
||||
|
||||
return function (clsOrObject: Function|Object, propertyName?: string) {
|
||||
const args: IndexMetadataArgs = {
|
||||
|
||||
@ -5,7 +5,6 @@ import {ForeignKeySchema} from "./schema/ForeignKeySchema";
|
||||
import {IndexSchema} from "./schema/IndexSchema";
|
||||
import {Driver} from "../driver/Driver";
|
||||
import {QueryRunner} from "../query-runner/QueryRunner";
|
||||
import {NamingStrategyInterface} from "../naming-strategy/NamingStrategyInterface";
|
||||
import {Logger} from "../logger/Logger";
|
||||
import {PrimaryKeySchema} from "./schema/PrimaryKeySchema";
|
||||
import {ColumnMetadata} from "../metadata/ColumnMetadata";
|
||||
@ -343,6 +342,7 @@ export class SchemaBuilder {
|
||||
const indexSchema = IndexSchema.create(indexMetadata);
|
||||
tableSchema.indices.push(indexSchema);
|
||||
this.logger.logSchemaBuild(`adding new index: ${indexSchema.name}`);
|
||||
console.log(indexMetadata);
|
||||
await this.queryRunner.createIndex(indexSchema.tableName, indexSchema);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user