recognition of unique column #57
This commit is contained in:
parent
d0fe49b9b8
commit
a1b5e68ea8
@ -44,9 +44,20 @@ export class MssqlDriver extends AbstractDriver {
|
||||
NUMERIC_PRECISION: number;
|
||||
NUMERIC_SCALE: number;
|
||||
IsIdentity: number;
|
||||
IsUnique: number;
|
||||
}[] = (await request.query(`SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,
|
||||
DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,
|
||||
COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') IsIdentity FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA in (${schema})`))
|
||||
COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') IsIdentity,
|
||||
(SELECT count(*)
|
||||
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
|
||||
inner join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu
|
||||
on cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
|
||||
where
|
||||
tc.CONSTRAINT_TYPE = 'UNIQUE'
|
||||
and tc.TABLE_NAME = c.TABLE_NAME
|
||||
and cu.COLUMN_NAME = c.COLUMN_NAME
|
||||
and tc.TABLE_SCHEMA=c.TABLE_SCHEMA) IsUnique
|
||||
FROM INFORMATION_SCHEMA.COLUMNS c where TABLE_SCHEMA in (${schema})`))
|
||||
.recordset;
|
||||
entities.forEach(ent => {
|
||||
response
|
||||
@ -56,9 +67,9 @@ export class MssqlDriver extends AbstractDriver {
|
||||
.forEach(resp => {
|
||||
let colInfo: ColumnInfo = new ColumnInfo();
|
||||
colInfo.name = resp.COLUMN_NAME;
|
||||
colInfo.is_nullable =
|
||||
resp.IS_NULLABLE == "YES" ? true : false;
|
||||
colInfo.is_generated = resp.IsIdentity == 1 ? true : false;
|
||||
colInfo.is_nullable = resp.IS_NULLABLE == "YES";
|
||||
colInfo.is_generated = resp.IsIdentity == 1;
|
||||
colInfo.is_unique = resp.IsUnique == 1;
|
||||
colInfo.default = resp.COLUMN_DEFAULT;
|
||||
colInfo.sql_type = resp.DATA_TYPE;
|
||||
switch (resp.DATA_TYPE) {
|
||||
|
@ -44,10 +44,11 @@ export class MysqlDriver extends AbstractDriver {
|
||||
NUMERIC_SCALE: number;
|
||||
IsIdentity: number;
|
||||
column_type: string;
|
||||
column_key: string;
|
||||
}>(`SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,
|
||||
DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,
|
||||
CASE WHEN EXTRA like '%auto_increment%' THEN 1 ELSE 0 END IsIdentity, column_type FROM INFORMATION_SCHEMA.COLUMNS
|
||||
where TABLE_SCHEMA like DATABASE()`);
|
||||
CASE WHEN EXTRA like '%auto_increment%' THEN 1 ELSE 0 END IsIdentity, column_type, column_key
|
||||
FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA like DATABASE()`);
|
||||
entities.forEach(ent => {
|
||||
response
|
||||
.filter(filterVal => {
|
||||
@ -56,9 +57,9 @@ export class MysqlDriver extends AbstractDriver {
|
||||
.forEach(resp => {
|
||||
let colInfo: ColumnInfo = new ColumnInfo();
|
||||
colInfo.name = resp.COLUMN_NAME;
|
||||
colInfo.is_nullable =
|
||||
resp.IS_NULLABLE == "YES" ? true : false;
|
||||
colInfo.is_generated = resp.IsIdentity == 1 ? true : false;
|
||||
colInfo.is_nullable = resp.IS_NULLABLE == "YES";
|
||||
colInfo.is_generated = resp.IsIdentity == 1;
|
||||
colInfo.is_unique = resp.column_key == "UNI";
|
||||
colInfo.default = resp.COLUMN_DEFAULT;
|
||||
colInfo.sql_type = resp.DATA_TYPE;
|
||||
switch (resp.DATA_TYPE) {
|
||||
|
@ -44,12 +44,21 @@ export class PostgresDriver extends AbstractDriver {
|
||||
numeric_precision: number;
|
||||
numeric_scale: number;
|
||||
isidentity: string;
|
||||
isunique: number;
|
||||
}[] = (await this.Connection
|
||||
.query(`SELECT table_name,column_name,column_default,is_nullable,
|
||||
data_type,character_maximum_length,numeric_precision,numeric_scale
|
||||
--,COLUMNPROPERTY(object_id(table_name), column_name, 'isidentity') isidentity
|
||||
, case when column_default LIKE 'nextval%' then 'YES' else 'NO' end isidentity
|
||||
FROM INFORMATION_SCHEMA.COLUMNS where table_schema in (${schema})`))
|
||||
data_type,character_maximum_length,numeric_precision,numeric_scale,
|
||||
case when column_default LIKE 'nextval%' then 'YES' else 'NO' end isidentity,
|
||||
(SELECT count(*)
|
||||
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
|
||||
inner join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu
|
||||
on cu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
|
||||
where
|
||||
tc.CONSTRAINT_TYPE = 'UNIQUE'
|
||||
and tc.TABLE_NAME = c.TABLE_NAME
|
||||
and cu.COLUMN_NAME = c.COLUMN_NAME
|
||||
and tc.TABLE_SCHEMA=c.TABLE_SCHEMA) IsUnique
|
||||
FROM INFORMATION_SCHEMA.COLUMNS c where table_schema in (${schema})`))
|
||||
.rows;
|
||||
entities.forEach(ent => {
|
||||
response
|
||||
@ -59,10 +68,9 @@ export class PostgresDriver extends AbstractDriver {
|
||||
.forEach(resp => {
|
||||
let colInfo: ColumnInfo = new ColumnInfo();
|
||||
colInfo.name = resp.column_name;
|
||||
colInfo.is_nullable =
|
||||
resp.is_nullable == "YES" ? true : false;
|
||||
colInfo.is_generated =
|
||||
resp.isidentity == "YES" ? true : false;
|
||||
colInfo.is_nullable = resp.is_nullable == "YES";
|
||||
colInfo.is_generated = resp.isidentity == "YES";
|
||||
colInfo.is_unique = resp.isunique == 1;
|
||||
colInfo.default = colInfo.is_generated
|
||||
? null
|
||||
: resp.column_default;
|
||||
|
20
test/integration/github-issues/57/entity/Post.ts
Normal file
20
test/integration/github-issues/57/entity/Post.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, JoinColumn} from "typeorm";
|
||||
|
||||
|
||||
@Entity("Post")
|
||||
export class Post {
|
||||
|
||||
@Column("integer",{
|
||||
nullable:false,
|
||||
primary:true,
|
||||
name:"id"
|
||||
})
|
||||
id:number;
|
||||
|
||||
@Column({unique:true})
|
||||
body:string;
|
||||
|
||||
@Column()
|
||||
body2:string;
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ describe("GitHub issues", async function () {
|
||||
if (process.env.MYSQL_Skip == '0') dbDrivers.push('mysql')
|
||||
if (process.env.MARIADB_Skip == '0') dbDrivers.push('mariadb')
|
||||
if (process.env.MSSQL_Skip == '0') dbDrivers.push('mssql')
|
||||
if (process.env.ORACLE_Skip == '0') dbDrivers.push('oracle')
|
||||
|
||||
let examplesPathJS = path.resolve(process.cwd(), 'dist/test/integration/github-issues')
|
||||
let examplesPathTS = path.resolve(process.cwd(), 'test/integration/github-issues')
|
||||
@ -37,9 +38,9 @@ describe("GitHub issues", async function () {
|
||||
|
||||
switch (folder) {
|
||||
case '39':
|
||||
if (dbDriver == 'mysql' || dbDriver == 'mariadb')
|
||||
if (dbDriver == 'mysql' || dbDriver == 'mariadb' || dbDriver == 'oracle')
|
||||
continue;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -65,7 +66,9 @@ describe("GitHub issues", async function () {
|
||||
case 'mariadb':
|
||||
engine = await GTU.createMariaDBModels(filesOrgPathJS, resultsPath)
|
||||
break;
|
||||
|
||||
case 'oracle':
|
||||
engine = await GTU.createOracleDBModels(filesOrgPathJS, resultsPath)
|
||||
break;
|
||||
default:
|
||||
console.log(`Unknown engine type`);
|
||||
engine = <Engine>{}
|
||||
|
@ -301,11 +301,6 @@ export class EntityFileToJson {
|
||||
if (retVal.indicies.length > 0 && retVal.indicies[retVal.indicies.length - 1].columnNames.length == 0) {
|
||||
retVal.indicies[retVal.indicies.length - 1].columnNames.push(retVal.columns[retVal.columns.length - 1].columnName)
|
||||
}
|
||||
retVal.indicies.forEach(ind => {
|
||||
if (ind.isUnique && ind.columnNames.length == 1 && ind.columnNames[0] == retVal.columns[retVal.columns.length - 1].columnName) {
|
||||
retVal.columns[retVal.columns.length - 1].columnOptions['unique'] = true
|
||||
}
|
||||
})
|
||||
continue
|
||||
} else if (trimmedLine == '}') {
|
||||
isInClassBody = false;
|
||||
|
Loading…
Reference in New Issue
Block a user