Skip to content

Commit

Permalink
Merge pull request #86 from oslabs-beta/master
Browse files Browse the repository at this point in the history
OS labs Beta to OSLabs main
  • Loading branch information
Aya Moosa authored Feb 23, 2023
2 parents 900e8a6 + ff78b42 commit 89e5434
Show file tree
Hide file tree
Showing 20 changed files with 542 additions and 1,133 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<img src="./assets/readmeImages/logo_readme.png" height=300/>

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/oslabs-beta/SeeQR)
![Release: 8.0.1](https://img.shields.io/badge/Release-8.0.1-red)
![Release: 9.0.1](https://img.shields.io/badge/Release-9.0.1-red)
![License: MIT](https://img.shields.io/badge/License-MIT-orange.svg)
![Contributions Welcome](https://img.shields.io/badge/Contributions-welcome-blue.svg)
[![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2Ftheseeqr)](https://twitter.com/theseeqr)
[![Github stars](https://img.shields.io/github/stars/open-source-labs/SeeQR?style=social)](https://github.com/open-source-labs/SeeQR)

[SeeQR.info](http://www.seeqr.info)
[SeeQRapp.com](http://www.seeqrapp.com)

<p>SeeQR is a <b>convenient one-stop shop</b> for efficient SQL database manipulation and performance testing. SeeQR can be used throughout the database life-cycle, from creation to testing.</p>

Expand All @@ -27,11 +27,13 @@

## Getting Started

To get started on contributing to this project:
To get started on contributing and editing databases to this project:


1. Download and install [Postgres](https://www.postgresql.org/download/) to access SeeQR's Postgres features and/or [MySQL](https://dev.mysql.com/downloads/mysql/) to access it's MySQL features.
2. Ensure that psql and/or mysql are available in the `$PATH`.
3. Download the latest version of [SeeQR](https://github.com/open-source-labs/seeqr/releases/latest).
3. Create users with passwords and permissions for both [PostgreSQL](https://phoenixnap.com/kb/postgres-create-user) and [MySQL](https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql). Linked are instructions for Mac (Homebrew) and Linux/WSL.
4. Download the latest version of [SeeQR](https://github.com/open-source-labs/seeqr/releases/latest).

## Built With

Expand Down Expand Up @@ -81,7 +83,7 @@ To get started on contributing to this project:
<div align="center">
<img src="./assets/readmeImages/gifs/dummy_data.gif" width=800/>
</div>
- Create/Edit Database <i>(currently in beta)</i>
- Create/Edit Database

- Users can create a new database from scratch by clicking the `Create New Database` button at the bottom of the sidebar.
- Users can modify the newly created database as well as any existing databases using the `ER Diagram` to create/change/delete tables and columns.
Expand All @@ -93,6 +95,7 @@ To get started on contributing to this project:
<img src="./assets/readmeImages/gifs/create_db3.gif" width=800/>
<img src="./assets/readmeImages/gifs/modify_db.gif" width=800/>
</div>

- Queries

- In the 'QUERIES' view, the main panel is where the query input text field is located, utilizing CodeMirror. The paint button in the top right corner of the panel auto-formats the inputted query.
Expand Down Expand Up @@ -162,7 +165,7 @@ We've released SeeQR because it's a useful tool to help optimize SQL databases.

## Core Team

[Fred Jeong](https://github.com/fred-jeong) | [Gabriel Kime](https://github.com/wizardbusiness) | [Chris Fryer](github.com/frynoceros) | [Ian Grepo](https://github.com/RadiantGH) | [Michelle Chang](https://github.com/mkchang168) | [Jake Bradbeer](https://github.com/JBradbeer) | [Bryan Santos](https://github.com/santosb93) | [William Trey Lewis](https://github.com/treyfrog128) | [Brandon Lee](https://github.com/BrandonW-Lee) | [Casey Escovedo](https://github.com/caseyescovedo) | [Casey Walker](https://github.com/cwalker3011) | [Catherine Chiu](https://github.com/catherinechiu) | [Chris Akinrinade](https://github.com/chrisakinrinade) | [Cindy Chau](https://github.com/cindychau) | [Claudio Santos](https://github.com/Claudiohbsantos) | [Eric Han](https://github.com/ericJH92) | [Faraz Akhtar](https://github.com/faraza22) | [Frank Norton](https://github.com/FrankNorton32) | [Harrison Nam](https://github.com/harrynam07) | [James Kolotouros](https://github.com/dkolotouros) | [Jennifer Courtner](https://github.com/jcourtner) | [John Wagner](https://github.com/jwagner988) | [Justin Dury-Agri](https://github.com/justinD-A) | [Justin Hicks](https://github.com/JuiceBawks) | [Katie Klochan](https://github.com/kklochan) | [May Wirapa Boonyasurat](https://github.com/mimiwrp) | [Mercer Stronck](https://github.com/mercerstronck) | [Muhammad Trad](https://github.com/muhammadtrad) | [Richard Guo](https://github.com/richardguoo) | [Richard Lam](https://github.com/rlam108) | [Sam Frakes](https://github.com/frakes413) | [Serena Kuo](https://github.com/serenackuo) | [Timothy Sin](https://github.com/timothysin) | [Vincent Trang](https://github.com/vincentt114)
[Aya Moosa](https://github.com/Hiya-its-Aya) | [Trevor Ferguson](https://github.com/TrevorJFerguson) | [Pauline Nguyen](https://github.com/paulinekpn) | [Utkarsh Uppal](https://github.com/utyvert) | [Fred Jeong](https://github.com/fred-jeong) | [Gabriel Kime](https://github.com/wizardbusiness) | [Chris Fryer](github.com/frynoceros) | [Ian Grepo](https://github.com/RadiantGH) | [Michelle Chang](https://github.com/mkchang168) | [Jake Bradbeer](https://github.com/JBradbeer) | [Bryan Santos](https://github.com/santosb93) | [William Trey Lewis](https://github.com/treyfrog128) | [Brandon Lee](https://github.com/BrandonW-Lee) | [Casey Escovedo](https://github.com/caseyescovedo) | [Casey Walker](https://github.com/cwalker3011) | [Catherine Chiu](https://github.com/catherinechiu) | [Chris Akinrinade](https://github.com/chrisakinrinade) | [Cindy Chau](https://github.com/cindychau) | [Claudio Santos](https://github.com/Claudiohbsantos) | [Eric Han](https://github.com/ericJH92) | [Faraz Akhtar](https://github.com/faraza22) | [Frank Norton](https://github.com/FrankNorton32) | [Harrison Nam](https://github.com/harrynam07) | [James Kolotouros](https://github.com/dkolotouros) | [Jennifer Courtner](https://github.com/jcourtner) | [John Wagner](https://github.com/jwagner988) | [Justin Dury-Agri](https://github.com/justinD-A) | [Justin Hicks](https://github.com/JuiceBawks) | [Katie Klochan](https://github.com/kklochan) | [May Wirapa Boonyasurat](https://github.com/mimiwrp) | [Mercer Stronck](https://github.com/mercerstronck) | [Muhammad Trad](https://github.com/muhammadtrad) | [Richard Guo](https://github.com/richardguoo) | [Richard Lam](https://github.com/rlam108) | [Sam Frakes](https://github.com/frakes413) | [Serena Kuo](https://github.com/serenackuo) | [Timothy Sin](https://github.com/timothysin) | [Vincent Trang](https://github.com/vincentt114)


## License
Expand Down
2 changes: 1 addition & 1 deletion __tests__/frontend/lib/queries.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.require = ((str: string) => str) as any
import * as queries from '../../../frontend/lib/queries';
import type { QueryData, ExplainJson } from '../../../frontend/types';
import type { QueryData } from '../../../frontend/types';

const first: Partial<QueryData> = {
label: 'firstQuery',
Expand Down
2 changes: 2 additions & 0 deletions backend/DummyD/dummyDataMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const getRandomInt = (min: number, max: number) => {
const generateDataByType = (columnObj: ColumnObj): string | number => {
let length;
// faker.js method to generate data by type
console.log('columnObj_datatype: ', columnObj.data_type)

switch (columnObj.data_type) {
case 'smallint':
return faker.random.number({ min: -32768, max: 32767 });
Expand Down
39 changes: 23 additions & 16 deletions backend/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ipcMain.on('return-db-list', (event, dbType: DBType = DBType.Postgres) => {

db.setBaseConnections()
.then(() => {
db.getLists()
db.getLists('', dbType)
.then((data: DBList) => {
event.sender.send('db-lists', data);
logger("Sent 'db-lists' from 'return-db-list'", LogType.SEND);
Expand Down Expand Up @@ -156,7 +156,7 @@ ipcMain.handle(
await db.query(dropDBScript, null, dbType);

// send updated db info
const dbsAndTables: DBList = await db.getLists();
const dbsAndTables: DBList = await db.getLists(dbName, dbType);
event.sender.send('db-lists', dbsAndTables);
logger("Sent 'db-lists' from 'drop-db'", LogType.SEND);
} finally {
Expand Down Expand Up @@ -228,7 +228,7 @@ ipcMain.handle(
}

// update frontend with new db list
const dbsAndTableInfo: DBList = await db.getLists();
const dbsAndTableInfo: DBList = await db.getLists('', dbType);
event.sender.send('db-lists', dbsAndTableInfo);
logger("Sent 'db-lists' from 'duplicate-db'", LogType.SEND);
} finally {
Expand Down Expand Up @@ -288,7 +288,7 @@ ipcMain.handle(
}

// update frontend with new db list
const dbsAndTableInfo: DBList = await db.getLists();
const dbsAndTableInfo: DBList = await db.getLists('', dbType);
event.sender.send('db-lists', dbsAndTableInfo);
logger("Sent 'db-lists' from 'import-db'", LogType.SEND);
} finally {
Expand Down Expand Up @@ -343,7 +343,7 @@ ipcMain.handle(
dbType
);
explainResults = results[0][0];
console.log('mysql explain results', explainResults);
// console.log('mysql explain results', explainResults);

console.log(LogType.WARNING, results);
}
Expand All @@ -361,9 +361,9 @@ ipcMain.handle(
console.log('returnedRows in channels for MySQL', returnedRows);
}
if (dbType === DBType.Postgres) {
console.log('results in channels for Postgres', results);
// console.log('results in channels for Postgres', results);
returnedRows = results.rows;
console.log('returnedRows in channels for Postgres', returnedRows);
// console.log('returnedRows in channels for Postgres', returnedRows);
}
} catch (e: any) {
error = e.toString();
Expand All @@ -383,7 +383,7 @@ ipcMain.handle(

// send updated db info in case query affected table or database information
// must be run after we connect back to the originally selected so tables information is accurate
const dbsAndTables: DBList = await db.getLists();
const dbsAndTables: DBList = await db.getLists('', dbType);
event.sender.send('db-lists', dbsAndTables);
logger(
"Sent 'db-lists' from 'run-query'",
Expand Down Expand Up @@ -440,26 +440,30 @@ interface dummyDataRequestPayload {
rows: number;
}

ipcMain.handle(
ipcMain.handle( // generate dummy data
'generate-dummy-data',
async (event, data: dummyDataRequestPayload, dbType: DBType) => {
logger("Received 'generate-dummy-data'", LogType.RECEIVE);
// send notice to front end that DD generation has been started
event.sender.send('async-started');

console.log('genereatedata ipcMain dbType: ', dbType)
let feedback: Feedback = {
type: '',
message: '',
};
try {
console.log('data in generate-dummy-data', data); // gets here fine

// Retrieves the Primary Keys and Foreign Keys for all the tables
const tableInfo: ColumnObj[] = await db.getTableInfo(data.tableName);

const tableInfo: ColumnObj[] = await db.getTableInfo(data.tableName, dbType); // passed in dbType to second argument
console.log('tableInfo in generate-dummy-data', tableInfo); // working

// generate dummy data
const dummyArray: DummyRecords = await generateDummyData(
tableInfo,
data.rows
);
console.log('dummyArray output: ', dummyArray)
// generate insert query string to insert dummy records
const columnsStringified = '('
.concat(dummyArray[0].join(', '))
Expand Down Expand Up @@ -491,9 +495,11 @@ ipcMain.handle(
message: err,
};
} finally {
console.log('dbType inside generate-dummy-data', dbType)
// send updated db info in case query affected table or database information
const dbsAndTables: DBList = await db.getLists();
event.sender.send('db-lists', dbsAndTables);
const dbsAndTables: DBList = await db.getLists('', dbType); // dummy data clear error is from here
console.log('dbsAndTables in generate-dummy-data', dbsAndTables)
event.sender.send('db-lists', dbsAndTables); // dummy data clear error is from here

// send feedback back to FE
event.sender.send('feedback', feedback);
Expand Down Expand Up @@ -534,7 +540,7 @@ ipcMain.handle(
await db.connectToDB(newDbName, dbType);

// update DBList in the sidebar to show this new db
const dbsAndTableInfo: DBList = await db.getLists();
const dbsAndTableInfo: DBList = await db.getLists(newDbName, dbType);
event.sender.send('db-lists', dbsAndTableInfo);
logger("Sent 'db-lists' from 'initialize-db'", LogType.SEND);
} catch (e) {
Expand Down Expand Up @@ -578,7 +584,7 @@ ipcMain.handle(
} finally {
// send updated db info in case query affected table or database information
// must be run after we connect back to the originally selected so tables information is accurate
const dbsAndTables: DBList = await db.getLists();
const dbsAndTables: DBList = await db.getLists('', dbType);
event.sender.send('db-lists', dbsAndTables);
logger("Sent 'db-lists' from 'update-db'", LogType.SEND);

Expand Down Expand Up @@ -625,6 +631,7 @@ ipcMain.handle(
};
} finally {
// send updated db info

const updatedDb: DBList = await db.getLists(dbName, dbType);
event.sender.send('db-lists', updatedDb);

Expand Down
31 changes: 19 additions & 12 deletions backend/helperFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable object-shorthand */
import { DBType } from './BE_types';
const { exec } = require('child_process'); // Child_Process: Importing Node.js' child_process API
const { dialog } = require('electron'); // Dialog: display native system dialogs for opening and saving files, alerting, etc
const { dialog } = require('electron'); // Dialog: display native system dialogs for opening and saving files, alerting, etcim
const docConfig = require('./_documentsConfig')
// ************************************** CLI COMMANDS & SQL Queries TO CREATE, DELETE, COPY DB SCHEMA, etc. ************************************** //

// Generate SQL queries & CLI commands to be executed in pg and child process respectively
Expand Down Expand Up @@ -63,9 +64,11 @@ const helperFunctions: HelperFunctions = {

// import SQL file into new DB created
runSQLFunc: function (dbName, file, dbType: DBType) {
const PG = `psql -U postgres -d "${dbName}" -f "${file}"`;
const SQL_data = docConfig.getFullConfig();
console.log(SQL_data)
const PG = `PGPASSWORD=${SQL_data.pg_pass} psql -U ${SQL_data.pg_user} -d "${dbName}" -f "${file}" -p ${SQL_data.pg_port}`;
// const MYSQL = `mysql -u root -p ${dbName} < ${file}`;
const MYSQL = `mysql -uroot -p; use ${dbName}; source ${file}`;
const MYSQL = `export MYSQL_PWD='${SQL_data.mysql_pass}'; mysql -u${SQL_data.mysql_user} --port=${SQL_data.mysql_port} ${dbName} < ${file}`;

console.log(`runSQLFunc MySQL: ${MYSQL}, ${dbType}`);
console.log(`runSQLFunc PG: ${PG}, ${dbType}`);
Expand All @@ -75,8 +78,9 @@ const helperFunctions: HelperFunctions = {

// import TAR file into new DB created
runTARFunc: function (dbName, file, dbType: DBType) {
const PG = `pg_restore -U postgres -d "${dbName}" "${file}"`;
const MYSQL = `mysqldump -u root -p ${dbName} > ${file}`;
const SQL_data = docConfig.getFullConfig();
const PG = `PGPASSWORD=${SQL_data.pg_pass} pg_restore -U ${SQL_data.pg_user} -p ${SQL_data.pg_port} -d "${dbName}" "${file}" `;
const MYSQL = `export MYSQL_PWD='${SQL_data.mysql_pass}'; mysqldump -u ${SQL_data.mysql_user} --port=${SQL_data.mysql_port} ${dbName} > ${file}`;

console.log(`runTARFunc MySQL: ${MYSQL}, ${dbType}`);
console.log(`runTARFunc PG: ${PG}, ${dbType}`);
Expand All @@ -86,8 +90,9 @@ const helperFunctions: HelperFunctions = {

// make a full copy of the schema
runFullCopyFunc: function (dbCopyName, newFile, dbType: DBType) {
const PG = `pg_dump -U postgres -F p -d "${dbCopyName}" > "${newFile}"`;
const MYSQL = `mysqldump -h localhost -u root -p --no-data ${dbCopyName} > ${newFile}`;
const SQL_data = docConfig.getFullConfig();
const PG = `PGPASSWORD=${SQL_data.pg_pass} pg_dump -s -U ${SQL_data.pg_user} -p ${SQL_data.pg_port} -Fp -d ${dbCopyName} > "${newFile}"`;
const MYSQL = `export MYSQL_PWD='${SQL_data.mysql_pass}'; mysqldump -h localhost -u ${SQL_data.mysql_user} ${dbCopyName} > ${newFile}`;

console.log(`runFullCopyFunc MySQL: ${MYSQL}, ${dbType}`);
console.log(`runFullCopyFunc PG: ${PG}, ${dbType}`);
Expand All @@ -97,20 +102,22 @@ const helperFunctions: HelperFunctions = {

// make a hollow copy of the schema
runHollowCopyFunc: function (dbCopyName, file, dbType: DBType) {
const PG = `pg_dump -s -U postgres -F p -d "${dbCopyName}" > "${file}"`;
const MYSQL = `mysqldump -h localhost -u root -p --no-data ${dbCopyName} > ${file}`;
const SQL_data = docConfig.getFullConfig();
const PG = ` PGPASSWORD=${SQL_data.pg_pass} pg_dump -s -U ${SQL_data.pg_user} -p ${SQL_data.pg_port} -F p -d "${dbCopyName}" > "${file}"`;
const MYSQL = `export MYSQL_PWD='${SQL_data.mysql_pass}'; mysqldump -h localhost -u ${SQL_data.mysql_user} --port=${SQL_data.mysql_port} ${dbCopyName} > ${file}`;

console.log(`runHollowCopyFunc MySQL: ${MYSQL}, ${dbType}`);
console.log(`runHollowCopyFunc PG: ${PG}, ${dbType}`);

return dbType === DBType.Postgres ? PG : MYSQL;
},

// promisified execute to execute commands in the child process
promExecute: (cmd: string) =>
new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) return reject(error);
exec(cmd, {timeout: 5000}, (error, stdout, stderr) => {
if (error){
console.log(error)
return reject(error)};
if (stderr) return reject(new Error(stderr));
return resolve({ stdout, stderr });
});
Expand Down
1 change: 0 additions & 1 deletion backend/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { FamilyRestroomRounded } from '@mui/icons-material';
import { BrowserWindow, Menu } from 'electron';

const { app } = require('electron');
Expand Down
Loading

0 comments on commit 89e5434

Please sign in to comment.