2021-08-29 11:58:11 -07:00
|
|
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
|
|
/* eslint-disable import/no-cycle */
|
|
|
|
import { ICredentialNodeAccess } from 'n8n-workflow';
|
2019-07-22 11:29:06 -07:00
|
|
|
|
|
|
|
import {
|
2021-05-29 11:31:21 -07:00
|
|
|
BeforeUpdate,
|
2019-07-22 11:29:06 -07:00
|
|
|
Column,
|
2021-05-29 11:31:21 -07:00
|
|
|
CreateDateColumn,
|
2019-07-22 11:29:06 -07:00
|
|
|
Entity,
|
|
|
|
Index,
|
|
|
|
PrimaryGeneratedColumn,
|
2021-05-29 11:31:21 -07:00
|
|
|
UpdateDateColumn,
|
2019-09-19 05:14:37 -07:00
|
|
|
} from 'typeorm';
|
2021-08-29 11:58:11 -07:00
|
|
|
|
2021-10-13 15:21:00 -07:00
|
|
|
import config = require('../../../config');
|
|
|
|
import { DatabaseType, ICredentialsDb } from '../..';
|
|
|
|
|
|
|
|
function resolveDataType(dataType: string) {
|
|
|
|
const dbType = config.get('database.type') as DatabaseType;
|
|
|
|
|
|
|
|
const typeMap: { [key in DatabaseType]: { [key: string]: string } } = {
|
|
|
|
sqlite: {
|
|
|
|
json: 'simple-json',
|
|
|
|
},
|
|
|
|
postgresdb: {
|
|
|
|
datetime: 'timestamptz',
|
|
|
|
},
|
|
|
|
mysqldb: {},
|
|
|
|
mariadb: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
return typeMap[dbType][dataType] ?? dataType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
|
|
function getTimestampSyntax() {
|
|
|
|
const dbType = config.get('database.type') as DatabaseType;
|
|
|
|
|
|
|
|
const map: { [key in DatabaseType]: string } = {
|
|
|
|
sqlite: "STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')",
|
|
|
|
postgresdb: 'CURRENT_TIMESTAMP(3)',
|
|
|
|
mysqldb: 'CURRENT_TIMESTAMP(3)',
|
|
|
|
mariadb: 'CURRENT_TIMESTAMP(3)',
|
|
|
|
};
|
|
|
|
|
|
|
|
return map[dbType];
|
|
|
|
}
|
2019-07-22 11:29:06 -07:00
|
|
|
|
|
|
|
@Entity()
|
|
|
|
export class CredentialsEntity implements ICredentialsDb {
|
|
|
|
@PrimaryGeneratedColumn()
|
|
|
|
id: number;
|
|
|
|
|
|
|
|
@Column({
|
2020-10-22 06:46:03 -07:00
|
|
|
length: 128,
|
2019-07-22 11:29:06 -07:00
|
|
|
})
|
|
|
|
name: string;
|
|
|
|
|
|
|
|
@Column('text')
|
|
|
|
data: string;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
@Column({
|
2020-10-22 06:46:03 -07:00
|
|
|
length: 32,
|
2019-07-22 11:29:06 -07:00
|
|
|
})
|
|
|
|
type: string;
|
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
@Column(resolveDataType('json'))
|
2019-07-22 11:29:06 -07:00
|
|
|
nodesAccess: ICredentialNodeAccess[];
|
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
@CreateDateColumn({ precision: 3, default: () => getTimestampSyntax() })
|
2019-07-22 11:29:06 -07:00
|
|
|
createdAt: Date;
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
@UpdateDateColumn({
|
|
|
|
precision: 3,
|
|
|
|
default: () => getTimestampSyntax(),
|
|
|
|
onUpdate: getTimestampSyntax(),
|
|
|
|
})
|
2019-07-22 11:29:06 -07:00
|
|
|
updatedAt: Date;
|
2020-04-29 02:34:12 -07:00
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
@BeforeUpdate()
|
|
|
|
setUpdateDate() {
|
|
|
|
this.updatedAt = new Date();
|
|
|
|
}
|
2019-07-22 11:29:06 -07:00
|
|
|
}
|