mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 12:19:09 +00:00
init migration test files, ormconfig
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
ConnectionOptions,
|
||||
createConnection,
|
||||
getRepository,
|
||||
Connection,
|
||||
} from 'typeorm';
|
||||
|
||||
import {
|
||||
@@ -29,12 +30,13 @@ export let collections: IDatabaseCollections = {
|
||||
|
||||
import * as path from 'path';
|
||||
|
||||
export async function init(synchronize?: boolean): Promise<IDatabaseCollections> {
|
||||
export async function init(synchronize?: boolean): Promise<boolean> {
|
||||
const dbType = await GenericHelpers.getConfigValue('database.type') as DatabaseType;
|
||||
const n8nFolder = UserSettings.getUserN8nFolderPath();
|
||||
|
||||
let entities;
|
||||
let connectionOptions: ConnectionOptions;
|
||||
let connection;
|
||||
|
||||
let dbNotExistError: string | undefined;
|
||||
switch (dbType) {
|
||||
@@ -45,8 +47,7 @@ export async function init(synchronize?: boolean): Promise<IDatabaseCollections>
|
||||
entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string,
|
||||
url: await GenericHelpers.getConfigValue('database.mongodb.connectionUrl') as string,
|
||||
useNewUrlParser: true,
|
||||
migrations: ['./databases/mongodb/Migrations/*.ts'],
|
||||
migrationsRun: true
|
||||
migrations: ['./databases/mongodb/migrations/*.js'],
|
||||
};
|
||||
break;
|
||||
|
||||
@@ -62,8 +63,7 @@ export async function init(synchronize?: boolean): Promise<IDatabaseCollections>
|
||||
port: await GenericHelpers.getConfigValue('database.postgresdb.port') as number,
|
||||
username: await GenericHelpers.getConfigValue('database.postgresdb.user') as string,
|
||||
schema: await GenericHelpers.getConfigValue('database.postgresdb.schema') as string,
|
||||
migrations: ['./databases/postgresdb/Migrations/*.ts'],
|
||||
migrationsRun: true
|
||||
migrations: ['./databases/postgresdb/migrations/*.js']
|
||||
};
|
||||
break;
|
||||
|
||||
@@ -79,8 +79,7 @@ export async function init(synchronize?: boolean): 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: ['./databases/mysqldb/Migrations/*.ts'],
|
||||
migrationsRun: true
|
||||
migrations: ['./databases/mysqldb/migrations/*.js']
|
||||
};
|
||||
break;
|
||||
|
||||
@@ -91,8 +90,7 @@ export async function init(synchronize?: boolean): Promise<IDatabaseCollections>
|
||||
type: 'sqlite',
|
||||
database: path.join(n8nFolder, 'database.sqlite'),
|
||||
entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string,
|
||||
migrations: ['./databases/sqlite/Migrations/*.ts'],
|
||||
migrationsRun: true
|
||||
migrations: ['./databases/sqlite/migrations/*.js'],
|
||||
};
|
||||
break;
|
||||
|
||||
@@ -103,37 +101,25 @@ export async function init(synchronize?: boolean): Promise<IDatabaseCollections>
|
||||
Object.assign(connectionOptions, {
|
||||
entities: Object.values(entities),
|
||||
synchronize: false,//synchronize === true || process.env['NODE_ENV'] !== 'production',
|
||||
logging: false
|
||||
logging: true,
|
||||
migrationsRun: true
|
||||
});
|
||||
|
||||
const connection = await createConnection(connectionOptions);
|
||||
|
||||
// TODO: Fix that properly
|
||||
// @ts-ignore
|
||||
collections.Credentials = getRepository(entities.CredentialsEntity);
|
||||
// @ts-ignore
|
||||
collections.Execution = getRepository(entities.ExecutionEntity);
|
||||
// @ts-ignore
|
||||
collections.Workflow = getRepository(entities.WorkflowEntity);
|
||||
|
||||
// Make sure that database did already get initialized
|
||||
try {
|
||||
// Try a simple query, if it fails it is normally a sign that
|
||||
// database did not get initialized
|
||||
await collections.Workflow!.findOne({ id: 1 });
|
||||
} catch (error) {
|
||||
// If query errors and the problem is that the database does not exist
|
||||
// run the init again with "synchronize: true"
|
||||
if (dbNotExistError !== undefined && error.message.includes(dbNotExistError)) {
|
||||
// Disconnect before we try to connect again
|
||||
if (connection.isConnected) {
|
||||
await connection.close();
|
||||
}
|
||||
|
||||
return init(true);
|
||||
}
|
||||
throw error;
|
||||
for(let i = 0; i < 1000; i++){
|
||||
console.log(connectionOptions);
|
||||
}
|
||||
|
||||
return collections;
|
||||
}
|
||||
try{
|
||||
connection = await createConnection(connectionOptions);
|
||||
|
||||
await connection.runMigrations({
|
||||
transaction: "none"
|
||||
});
|
||||
}catch(e){
|
||||
throw new Error("Couldn't connect to db / migrate stuff.")
|
||||
}
|
||||
|
||||
|
||||
|
||||
return connection.isConnected;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user