Add index stopped at (#766)

* 🚧 add index on sqlite

* 🚧 add migration for postgres

* 🚧 add mysql migration

* 🚧 add mongodb migration

*  revert change of default postgresdb user
This commit is contained in:
Ben Hesseldieck 2020-07-17 17:08:40 +02:00 committed by GitHub
parent 479606753b
commit ebe2775701
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 128 additions and 9 deletions

View file

@ -185,6 +185,7 @@ const config = convict({
// in the editor.
saveDataManualExecutions: {
doc: 'Save data of executions when started manually via editor',
format: 'Boolean',
default: false,
env: 'EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONS'
},
@ -196,16 +197,19 @@ const config = convict({
// a future version.
pruneData: {
doc: 'Delete data of past executions on a rolling basis',
format: 'Boolean',
default: false,
env: 'EXECUTIONS_DATA_PRUNE'
},
pruneDataMaxAge: {
doc: 'How old (hours) the execution data has to be to get deleted',
format: Number,
default: 336,
env: 'EXECUTIONS_DATA_MAX_AGE'
},
pruneDataTimeout: {
doc: 'Timeout (seconds) after execution data has been pruned',
format: Number,
default: 3600,
env: 'EXECUTIONS_DATA_PRUNE_TIMEOUT'
},

View file

@ -44,9 +44,9 @@ module.exports = [
"logging": false,
"host": "localhost",
"username": "postgres",
"password": "docker",
"password": "",
"port": 5432,
"database": "postgres",
"database": "n8n",
"schema": "public",
"entities": Object.values(PostgresDb),
"migrations": [
@ -68,7 +68,7 @@ module.exports = [
"username": "root",
"password": "password",
"host": "localhost",
"port": "3308",
"port": "3306",
"logging": false,
"entities": Object.values(MySQLDb),
"migrations": [
@ -90,7 +90,7 @@ module.exports = [
"username": "root",
"password": "password",
"host": "localhost",
"port": "3308",
"port": "3306",
"logging": false,
"entities": Object.values(MySQLDb),
"migrations": [
@ -105,4 +105,4 @@ module.exports = [
"subscribersDir": "./src/databases/mysqldb/Subscribers"
}
},
];
];

View file

@ -35,21 +35,25 @@ export let collections: IDatabaseCollections = {
import {
InitialMigration1587669153312,
WebhookModel1589476000887,
CreateIndexStoppedAt1594828256133,
} from './databases/postgresdb/migrations';
import {
InitialMigration1587563438936,
WebhookModel1592679094242,
CreateIndexStoppedAt1594910478695,
} from './databases/mongodb/migrations';
import {
InitialMigration1588157391238,
WebhookModel1592447867632,
CreateIndexStoppedAt1594902918301,
} from './databases/mysqldb/migrations';
import {
InitialMigration1588102412422,
WebhookModel1592445003908,
CreateIndexStoppedAt1594825041918,
} from './databases/sqlite/migrations';
import * as path from 'path';
@ -71,7 +75,11 @@ export async function init(): Promise<IDatabaseCollections> {
entityPrefix,
url: await GenericHelpers.getConfigValue('database.mongodb.connectionUrl') as string,
useNewUrlParser: true,
migrations: [InitialMigration1587563438936, WebhookModel1592679094242],
migrations: [
InitialMigration1587563438936,
WebhookModel1592679094242,
CreateIndexStoppedAt1594910478695,
],
migrationsRun: true,
migrationsTableName: `${entityPrefix}migrations`,
};
@ -104,7 +112,11 @@ export async function init(): Promise<IDatabaseCollections> {
port: await GenericHelpers.getConfigValue('database.postgresdb.port') as number,
username: await GenericHelpers.getConfigValue('database.postgresdb.user') as string,
schema: config.get('database.postgresdb.schema'),
migrations: [InitialMigration1587669153312, WebhookModel1589476000887],
migrations: [
InitialMigration1587669153312,
WebhookModel1589476000887,
CreateIndexStoppedAt1594828256133,
],
migrationsRun: true,
migrationsTableName: `${entityPrefix}migrations`,
ssl,
@ -123,7 +135,11 @@ export async function init(): Promise<IDatabaseCollections> {
password: await GenericHelpers.getConfigValue('database.mysqldb.password') as string,
port: await GenericHelpers.getConfigValue('database.mysqldb.port') as number,
username: await GenericHelpers.getConfigValue('database.mysqldb.user') as string,
migrations: [InitialMigration1588157391238, WebhookModel1592447867632],
migrations: [
InitialMigration1588157391238,
WebhookModel1592447867632,
CreateIndexStoppedAt1594902918301,
],
migrationsRun: true,
migrationsTableName: `${entityPrefix}migrations`,
};
@ -135,7 +151,11 @@ export async function init(): Promise<IDatabaseCollections> {
type: 'sqlite',
database: path.join(n8nFolder, 'database.sqlite'),
entityPrefix,
migrations: [InitialMigration1588102412422, WebhookModel1592445003908],
migrations: [
InitialMigration1588102412422,
WebhookModel1592445003908,
CreateIndexStoppedAt1594825041918
],
migrationsRun: true,
migrationsTableName: `${entityPrefix}migrations`,
};

View file

@ -39,6 +39,7 @@ export class ExecutionEntity implements IExecutionFlattedDb {
@Column('Date')
startedAt: Date;
@Index()
@Column('Date')
stoppedAt: Date;

View file

@ -0,0 +1,22 @@
import { MigrationInterface } from "typeorm";
import {
MongoQueryRunner,
} from 'typeorm/driver/mongodb/MongoQueryRunner';
import * as config from '../../../../config';
export class CreateIndexStoppedAt1594910478695 implements MigrationInterface {
name = 'CreateIndexStoppedAt1594910478695'
public async up(queryRunner: MongoQueryRunner): Promise<void> {
const tablePrefix = config.get('database.tablePrefix');
await queryRunner.manager.createCollectionIndex(`${tablePrefix}execution_entity`, 'stoppedAt', { name: `IDX_${tablePrefix}execution_entity_stoppedAt`});
}
public async down(queryRunner: MongoQueryRunner): Promise<void> {
const tablePrefix = config.get('database.tablePrefix');
await queryRunner.manager.dropCollectionIndex
(`${tablePrefix}execution_entity`, `IDX_${tablePrefix}execution_entity_stoppedAt`);
}
}

View file

@ -1,2 +1,3 @@
export * from './1587563438936-InitialMigration';
export * from './1592679094242-WebhookModel';
export * from './151594910478695-CreateIndexStoppedAt';

View file

@ -39,6 +39,7 @@ export class ExecutionEntity implements IExecutionFlattedDb {
@Column('datetime')
startedAt: Date;
@Index()
@Column('datetime')
stoppedAt: Date;

View file

@ -0,0 +1,20 @@
import {MigrationInterface, QueryRunner} from "typeorm";
import * as config from '../../../../config';
export class CreateIndexStoppedAt1594902918301 implements MigrationInterface {
name = 'CreateIndexStoppedAt1594902918301'
public async up(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.get('database.tablePrefix');
await queryRunner.query('CREATE INDEX `IDX_' + tablePrefix + 'cefb067df2402f6aed0638a6c1` ON `' + tablePrefix + 'execution_entity` (`stoppedAt`)');
}
public async down(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.get('database.tablePrefix');
await queryRunner.query('DROP INDEX `IDX_' + tablePrefix + 'cefb067df2402f6aed0638a6c1` ON `' + tablePrefix + 'execution_entity`');
}
}

View file

@ -1,2 +1,3 @@
export * from './1588157391238-InitialMigration';
export * from './1592447867632-WebhookModel';
export * from './1594902918301-CreateIndexStoppedAt';

View file

@ -39,6 +39,7 @@ export class ExecutionEntity implements IExecutionFlattedDb {
@Column('timestamp')
startedAt: Date;
@Index()
@Column('timestamp')
stoppedAt: Date;

View file

@ -0,0 +1,25 @@
import {MigrationInterface, QueryRunner} from "typeorm";
import * as config from '../../../../config';
export class CreateIndexStoppedAt1594828256133 implements MigrationInterface {
name = 'CreateIndexStoppedAt1594828256133'
public async up(queryRunner: QueryRunner): Promise<void> {
let tablePrefix = config.get('database.tablePrefix');
const tablePrefixPure = tablePrefix;
const schema = config.get('database.postgresdb.schema');
if (schema) {
tablePrefix = schema + '.' + tablePrefix;
}
await queryRunner.query(`CREATE INDEX IF NOT EXISTS IDX_${tablePrefixPure}33228da131bb1112247cf52a42 ON ${tablePrefix}execution_entity ("stoppedAt") `);
}
public async down(queryRunner: QueryRunner): Promise<void> {
let tablePrefix = config.get('database.tablePrefix');
await queryRunner.query(`DROP INDEX IDX_${tablePrefix}33228da131bb1112247cf52a42`);
}
}

View file

@ -1,3 +1,4 @@
export * from './1587669153312-InitialMigration';
export * from './1589476000887-WebhookModel';
export * from './1594828256133-CreateIndexStoppedAt';

View file

@ -39,6 +39,7 @@ export class ExecutionEntity implements IExecutionFlattedDb {
@Column()
startedAt: Date;
@Index()
@Column()
stoppedAt: Date;

View file

@ -0,0 +1,20 @@
import {MigrationInterface, QueryRunner} from "typeorm";
import * as config from '../../../../config';
export class CreateIndexStoppedAt1594825041918 implements MigrationInterface {
name = 'CreateIndexStoppedAt1594825041918'
public async up(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.get('database.tablePrefix');
await queryRunner.query(`CREATE INDEX "IDX_${tablePrefix}cefb067df2402f6aed0638a6c1" ON "execution_entity" ("stoppedAt") `);
}
public async down(queryRunner: QueryRunner): Promise<void> {
const tablePrefix = config.get('database.tablePrefix');
await queryRunner.query(`DROP INDEX "IDX_${tablePrefix}cefb067df2402f6aed0638a6c1"`);
}
}

View file

@ -1,2 +1,3 @@
export * from './1588102412422-InitialMigration';
export * from './1592445003908-WebhookModel';
export * from './1594825041918-CreateIndexStoppedAt'