Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/@n8n/db/src/entities/deployment-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Column, Entity } from '@n8n/typeorm';

import { datetimeColumnType, WithTimestampsAndStringId } from './abstract-entity';

@Entity()
export class DeploymentKey extends WithTimestampsAndStringId {
@Column({ type: 'varchar', length: 64 })
type: string;

@Column('text')
value: string;

@Column({ type: 'varchar', length: 20, nullable: true })
algorithm: string | null;

@Column({ type: 'varchar', length: 20 })
status: string;

@Column({ type: datetimeColumnType, nullable: true })
deprecatedAt: Date | null;
}
3 changes: 3 additions & 0 deletions packages/@n8n/db/src/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type CredentialDependencyType,
} from './credential-dependency-entity';
import { CredentialsEntity } from './credentials-entity';
import { DeploymentKey } from './deployment-key';
import { ExecutionAnnotation } from './execution-annotation.ee';
import { ExecutionData } from './execution-data';
import { ExecutionEntity } from './execution-entity';
Expand Down Expand Up @@ -58,6 +59,7 @@ export {
CredentialsEntity,
CredentialDependency,
type CredentialDependencyType,
DeploymentKey,
Folder,
Project,
ProjectRelation,
Expand Down Expand Up @@ -101,6 +103,7 @@ export const entities = {
AuthIdentity,
CredentialsEntity,
CredentialDependency,
DeploymentKey,
Folder,
Project,
ProjectRelation,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { MigrationContext, ReversibleMigration } from '../migration-types';

export class CreateDeploymentKeyTable1777000000000 implements ReversibleMigration {
async up({ schemaBuilder: { createTable, column, createIndex } }: MigrationContext) {
await createTable('deployment_key').withColumns(
column('type').varchar(64).notNull,
column('value').text.notNull,
column('algorithm').varchar(20),
column('status').varchar(20).notNull,
column('deprecatedAt').timestamp(),
).withTimestamps;

await createIndex(
'deployment_key',
['type'],
true,
'IDX_deployment_key_data_encryption_active',
"status = 'active' AND type = 'data_encryption'",
);
}

async down({ schemaBuilder: { dropTable } }: MigrationContext) {
await dropTable('deployment_key');
}
}
2 changes: 2 additions & 0 deletions packages/@n8n/db/src/migrations/postgresdb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import { CreateInstanceVersionHistoryTable1774854660000 } from '../common/177485
import { CreateInstanceAiTables1775000000000 } from '../common/1775000000000-CreateInstanceAiTables';
import { CreateTokenExchangeJtiTable1775116241000 } from '../common/1775116241000-CreateTokenExchangeJtiTable';
import { CreateTrustedKeyTables1776000000000 } from '../common/1776000000000-CreateTrustedKeyTables';
import { CreateDeploymentKeyTable1777000000000 } from '../common/1777000000000-CreateDeploymentKeyTable';
import type { Migration } from '../migration-types';

export const postgresMigrations: Migration[] = [
Expand Down Expand Up @@ -323,4 +324,5 @@ export const postgresMigrations: Migration[] = [
CreateInstanceAiTables1775000000000,
CreateTokenExchangeJtiTable1775116241000,
CreateTrustedKeyTables1776000000000,
CreateDeploymentKeyTable1777000000000,
];
2 changes: 2 additions & 0 deletions packages/@n8n/db/src/migrations/sqlite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ import { CreateInstanceVersionHistoryTable1774854660000 } from '../common/177485
import { CreateInstanceAiTables1775000000000 } from '../common/1775000000000-CreateInstanceAiTables';
import { CreateTokenExchangeJtiTable1775116241000 } from '../common/1775116241000-CreateTokenExchangeJtiTable';
import { CreateTrustedKeyTables1776000000000 } from '../common/1776000000000-CreateTrustedKeyTables';
import { CreateDeploymentKeyTable1777000000000 } from '../common/1777000000000-CreateDeploymentKeyTable';
import type { Migration } from '../migration-types';

const sqliteMigrations: Migration[] = [
Expand Down Expand Up @@ -311,6 +312,7 @@ const sqliteMigrations: Migration[] = [
CreateInstanceAiTables1775000000000,
CreateTokenExchangeJtiTable1775116241000,
CreateTrustedKeyTables1776000000000,
CreateDeploymentKeyTable1777000000000,
];

export { sqliteMigrations };
23 changes: 23 additions & 0 deletions packages/@n8n/db/src/repositories/deployment-key.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Service } from '@n8n/di';
import { DataSource, Repository } from '@n8n/typeorm';

import { DeploymentKey } from '../entities/deployment-key';

@Service()
export class DeploymentKeyRepository extends Repository<DeploymentKey> {
constructor(dataSource: DataSource) {
super(DeploymentKey, dataSource.manager);
}

async findActiveByType(type: string): Promise<DeploymentKey | null> {
return await this.findOne({ where: { type, status: 'active' } });
}

async findById(id: string): Promise<DeploymentKey | null> {
return await this.findOne({ where: { id } });
}

async findAllByType(type: string): Promise<DeploymentKey[]> {
return await this.find({ where: { type } });
}
}
1 change: 1 addition & 0 deletions packages/@n8n/db/src/repositories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { BinaryDataRepository } from './binary-data.repository';
export { ClockRepository } from './clock.repository';
export { CredentialsRepository } from './credentials.repository';
export { CredentialDependencyRepository } from './credential-dependency.repository';
export { DeploymentKeyRepository } from './deployment-key.repository';
export { ExecutionAnnotationRepository } from './execution-annotation.repository';
export { ExecutionDataRepository } from './execution-data.repository';
export { ExecutionMetadataRepository } from './execution-metadata.repository';
Expand Down
Loading