Skip to content

Commit

Permalink
Add option to run fresh db migration or just upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
erssebaggala committed Oct 11, 2019
1 parent 0fa8cf4 commit 0819fc0
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 81 deletions.
2 changes: 1 addition & 1 deletion background/background-process.html
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ <h1>Background process</h1>
}

//
//Add parameter to baseline reference
//delete parameter to baseline reference
try{
if(task === 'delete_baseline_parameter'){
const result = await utils.deleteBaselineParameter(options.vendor, options.technology, options.mo, options.parameter);
Expand Down
97 changes: 51 additions & 46 deletions background/background-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,60 +625,65 @@ function getPathToPsqlOnMacOSX(){
* @param string port
* @param string username
* @param string password
* @param boolean refreshSetup
*
* @since 0.3.0
*/
async function runMigrations(hostname, port, username, password){
async function runMigrations(hostname, port, username, password, refreshSetup){

const connectionString = `postgresql://${username}:${password}@${hostname}:${port}/postgres`;
const client = new Client({
connectionString: connectionString,
});
//Fresh installation
if(refreshSetup === true){

const connectionString = `postgresql://${username}:${password}@${hostname}:${port}/postgres`;
const client = new Client({
connectionString: connectionString,
});

client.connect((err) => {
if(err){
return err;
}
});

client.connect((err) => {
if(err){
return err;
//@TODO: Check if user wants to recreate database or just update
try{
let results = await
new Promise( async (resolve, reject) => {
let res = await client.query("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = 'boda'");
res = await client.query("DROP DATABASE IF EXISTS boda");
res = await client.query("DROP ROLE IF EXISTS bodastage");
res = await client.query("CREATE USER bodastage WITH PASSWORD 'password'");
res = await client.query("CREATE DATABASE boda owner bodastage");

client.end();
if(typeof res.err !== 'undefined') reject("Error occured"); else resolve("Database and role created successfully.");

});
}catch(e){
return {status: 'error', message: 'Error occurred while running migrations. See log for details'}
}
});

//@TODO: Check if user wants to recreate database or just update
try{
let results = await
new Promise( async (resolve, reject) => {
let res = await client.query("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = 'boda'");
res = await client.query("DROP DATABASE IF EXISTS boda");
res = await client.query("DROP ROLE IF EXISTS bodastage");
res = await client.query("CREATE USER bodastage WITH PASSWORD 'password'");
res = await client.query("CREATE DATABASE boda owner bodastage");

client.end();
if(typeof res.err !== 'undefined') reject("Error occured"); else resolve("Database and role created successfully.");

});
}catch(e){
return {status: 'error', message: 'Error occurred while running migrations. See log for details'}
}

//add tablefunc extension
const connStr2 = `postgresql://${username}:${password}@${hostname}:${port}/boda`;
const client2 = new Client({connectionString: connStr2});
client2.connect((err) => {
if(err){
log.error(err)

//add tablefunc extension
const connStr2 = `postgresql://${username}:${password}@${hostname}:${port}/boda`;
const client2 = new Client({connectionString: connStr2});
client2.connect((err) => {
if(err){
log.error(err)
return {status: 'error', message: 'Error occurred while creating tablefunc extension. See log for details'}
}
});

try{
let results = await
new Promise( async (resolve, reject) => {
const res = await client2.query("CREATE EXTENSION IF NOT EXISTS tablefunc");
client2.end();
if(typeof res.err !== 'undefined') reject("Error occured while creating tablefunc extension"); else resolve("tablefunc extension created successfully.");
});
}catch(e){
return {status: 'error', message: 'Error occurred while creating tablefunc extension. See log for details'}
}
});

try{
let results = await
new Promise( async (resolve, reject) => {
const res = await client2.query("CREATE EXTENSION IF NOT EXISTS tablefunc");
client2.end();
if(typeof res.err !== 'undefined') reject("Error occured while creating tablefunc extension"); else resolve("tablefunc extension created successfully.");
});
}catch(e){
return {status: 'error', message: 'Error occurred while creating tablefunc extension. See log for details'}
}
}//if refreshSetup === true


//Get app base path
Expand Down
30 changes: 26 additions & 4 deletions src/modules/cm/ParseAndImport.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from 'react'
import { connect } from 'react-redux';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Intent, Button, FileInput, HTMLSelect,
ProgressBar, Classes, Switch } from "@blueprintjs/core";
import {
Intent,
Button,
FileInput,
HTMLSelect,
ProgressBar,
Classes,
Switch
} from "@blueprintjs/core";
import { VENDOR_CM_FORMATS, VENDOR_PM_FORMATS, VENDOR_FM_FORMATS } from './VendorFormats.js'
import Timer from './Timer';
import { saveCMParsingFolders } from './cm-actions';
Expand Down Expand Up @@ -71,20 +78,28 @@ class ParseAndImport extends React.Component {
* Update the output folder state when the text field value changes
*/
onOutputFolderInputChange = (e) => {
if(typeof e.target.files !== 'object'){
this.setState({errorMessage: 'Error reading file', successMessage: null, infoMessage:null, processing: false})
}
this.setState({outputFolderText: e.target.files[0].path})
}

/**
* Update the input folder state when the text field value changes
*/
onInputFileChange = (e) => {
if(typeof e.target.files !== 'object'){
this.setState({errorMessage: 'Error reading file', successMessage: null, infoMessage:null, processing: false})
}

this.setState({inputFileText: e.target.files[0].path})
}

/**
* Update the vendor format in state when the vendor format is selected
*/
onVendorFormatSelectChange =(e) => {

this.setState({currentFormat: e.target.value })
}

Expand Down Expand Up @@ -307,6 +322,7 @@ class ParseAndImport extends React.Component {
}

render(){


let successNotice = null;
if(this.state.successMessage !== null ){
Expand Down Expand Up @@ -417,8 +433,14 @@ class ParseAndImport extends React.Component {

</div>


<Button icon="play" text="Process" className={Classes.INTENT_PRIMARY} onClick={this.processDumps} disabled={this.state.processing}/> &nbsp;
<Button
icon="play"
text="Process"
className={Classes.INTENT_PRIMARY}
onClick={this.processDumps}
disabled={this.state.processing}
/>
&nbsp;
<Button text="Clear" onClick={this.clearForm} disabled={this.state.processing}/>
</div>
</fieldset>
Expand Down
3 changes: 3 additions & 0 deletions src/modules/gis/GISMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ class GISMap extends React.Component{
});

ipcRenderer.removeListener("parse-cm-request", this.importFileBGJobListener);
//Reload the carrier colors
if(this.props.carrierColors.length === 0) this.props.dispatch(gisFetchPlanFrequencies());

this.refreshMap();
}

Expand Down
76 changes: 46 additions & 30 deletions src/modules/settings/Database.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ import React from 'react';
import { connect } from 'react-redux';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { setSidePanel } from '../layout/uilayout-actions';
import { Button, Intent, ProgressBar, Collapse, Callout } from "@blueprintjs/core";
import {
Button,
Intent,
ProgressBar,
Collapse,
Callout,
Popover,
Menu,
Position,
MenuItem,
Icon
} from "@blueprintjs/core";
import { updateDBSettings, getDBSettings, clearDBUpdateError, clearDBUpdateSuccess,
checkConnection, showDBUpdateError, showDBUpdateSuccess, stopDBSettingsUpdate,
startDBSettingsUpdate } from './settings-actions';
Expand Down Expand Up @@ -92,15 +103,21 @@ class Database extends React.Component{
this.setState({notice: null});
}

setupDB = () => {
/*
* Setup database
*
* @param Boolean refreshSetup true -- re-create database, false -- upgrade
*/
setupDB = (refreshSetup) => {

this.props.dispatch(startDBSettingsUpdate());

let payload={
hostname: this.state.hostname,
port: this.state.port,
username: this.state.username,
password: this.state.password
password: this.state.password,
refreshSetup: refreshSetup
}

//Send request for background job
Expand Down Expand Up @@ -134,9 +151,22 @@ class Database extends React.Component{
//Listen on channel
ipcRenderer.on('parse-cm-request', this.setupDBListener);
}

render(){

const setupMenu = (
<Menu>
<MenuItem
text="Fresh setup"
onClick={() => this.setupDB(true)}
/>
<MenuItem
text="Upgrade"
onClick={() => this.setupDB(false)}
/>
</Menu>
);

let errorNotice = null
if(this.props.db.error !== null){
errorNotice = (<div className="alert alert-danger mt-2 p-2" role="alert">
Expand Down Expand Up @@ -209,32 +239,18 @@ class Database extends React.Component{


<Button type="submit" text="Update" intent={Intent.PRIMARY} disabled={this.props.updating || this.props.db.updating} /> &nbsp;
<Button type="button" intent={Intent.SUCCESS} icon="play" text="Setup database" disabled={this.props.updating || this.props.db.updating} onClick={this.setupDB} /> &nbsp;
<Button type="button" text="Test connection" disabled={this.props.updating || this.props.db.updating} onClick={this.testDBConnection} /> &nbsp;
<Button type="button" text="How to install PostgreSQL" minimal={true} disabled={this.props.updating} icon="info-sign" onClick={(e) => { e.preventDefault(); this.handleOpenCollapse();}}/> &nbsp;

<Collapse isOpen={this.state.collapseOpen} className="mt-2">
<Callout>
<p>
<strong>
We require you to manually install PostgreSQL as it requires elevated privileges to be run as a service.
</strong>
</p>


<ol>
<li> Download version 10.9 installer from the <a href="https://www.enterprisedb.com/downloads/postgres-postgresql-downloads" onClick={this.handleOnHrefClick}>Enterprise DB Download page</a> </li>
<li> Run installation</li>
<li> Confirm <strong>psql</strong> command is available in the system PATH i.e. can be run from the terminal. Type <code>psql --help</code> in the terminal to confirm.</li>
<li> Restart Boda-Lite application</li>
</ol>

<p>
See documentation for more details.
</p>
</Callout>
</Collapse>

<Popover content={setupMenu} position={Position.RIGHT_TOP}>
<Button
type="button"
intent={Intent.SUCCESS}
icon="database"
text="Setup database"
disabled={this.props.updating || this.props.db.updating}
rightIcon={<Icon icon="chevron-right" />}
/>
</Popover>
&nbsp;
<Button type="button" text="Test connection" disabled={this.props.updating || this.props.db.updating} onClick={this.testDBConnection} /> &nbsp;
</form>

</fieldset>
Expand Down

0 comments on commit 0819fc0

Please sign in to comment.