Skip to content

Commit 2b9710b

Browse files
Yufaneighbor-peacegeistnine01001101CKatu816
authored andcommitted
replace all constrainName with constraintName
Co-authored-by: Michael Costello <[email protected]> Co-authored-by: Steven Geiger <[email protected]> Co-authored-by: Yufa Li <[email protected]> Co-authored-by: Alexander Tu <[email protected]>
1 parent 19b8914 commit 2b9710b

File tree

10 files changed

+24
-31
lines changed

10 files changed

+24
-31
lines changed

server/controllers/mysqlData.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export const objSchema = (req, res, next) => {
8383
this.ReferencesPropertyName = null; //key name at current table
8484
this.ReferencesTableName = null; //current table name
8585
this.IsDestination = false;
86-
this.constrainName = null; //constraint from SQL query
86+
this.constraintName = null; //constraint from SQL query
8787
}
8888

8989
//append tables and table properties to results
@@ -132,7 +132,7 @@ export const objSchema = (req, res, next) => {
132132
foreignKeyReferences[fKey].ReferencesTableName = table.name;
133133
foreignKeyReferences[fKey].PrimaryKeyName = primaryKey;
134134
foreignKeyReferences[fKey].PrimaryKeyTableName = primaryTable;
135-
foreignKeyReferences[fKey].constrainName = constraint;
135+
foreignKeyReferences[fKey].constraintName = constraint;
136136

137137
//find additional foreign keys and references
138138
return foreignKeys(string);

src/components/ReactFlow/Flow.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export default function Flow() {
2121
// re-render every time schemaStore updates
2222
// useSchemaStore.subscribe((state) => state.schemaStore, reRender);
2323

24+
useEffect(() => {
25+
reRender(schemaStore);
26+
}, [schemaStore]);
27+
2428
function reRender(schemaStore: SchemaStore) {
2529
console.log('rerendering reactflow-------------------------------------------------');
2630
if (!schemaStore || !Object.keys(schemaStore).length) return;
@@ -35,9 +39,9 @@ export default function Flow() {
3539
console.log('nodes set');
3640
}
3741

38-
useEffect(() => {
39-
reRender(schemaStore);
40-
}, [schemaStore]);
42+
// useEffect(() => {
43+
// reRender(schemaStore);
44+
// }, [schemaStore]);
4145

4246
// renders React Flow canvas
4347
return (

src/components/ReactFlow/TableNode.jsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import useSettingsStore from '../../store/settingsStore';
77

88
export default function TableNode({ data }) {
99
const tableName = data.table[0];
10-
console.log('tableName', tableName)
11-
1210
// columnData is an array of objects with each column in the table as an element
1311
const columnData = Object.values(data.table[1]);
1412
const [tableColumns, setTableColumns] = useState(columnData);
@@ -19,13 +17,10 @@ export default function TableNode({ data }) {
1917
const tableHandles = [];
2018
for (let i = 0; i < data.edges.length; i++) {
2119
if (data.edges[i].source === tableName) {
22-
console.log('Source.tableName', data.edges[i].source)
2320
//make handle placement dynamic, we need to know the column of our source
2421
let columnNumberSource =
2522
columnData.findIndex((obj) => obj.Name === data.edges[i].sourceHandle) + 1;
2623
if (columnNumberSource === 0) columnNumberSource = 1;
27-
// console.log('columnNumberSource', columnNumberSource);
28-
// console.log('data.edges[i].sourceHandle', data.edges[i].sourceHandle);
2924
tableHandles.push(
3025
<Handle
3126
key={`${data.edges[i]}-source-${[i]}`}
@@ -41,13 +36,10 @@ export default function TableNode({ data }) {
4136
);
4237
}
4338
if (data.edges[i].target === tableName) {
44-
console.log('target.tableName', data.edges[i].target)
4539
//make handle placement dynamic, we need to know the column of our target
4640
let columnNumberTarget =
4741
columnData.findIndex((obj) => obj.Name === data.edges[i].targetHandle) + 1;
4842
if (columnNumberTarget === 0) columnNumberTarget = 1;
49-
// console.log('columnNumberTarget', columnNumberTarget);
50-
// console.log('data.edges[i].targetHandle', data.edges[i].targetHandle);
5143
tableHandles.push(
5244
<Handle
5345
key={`${data.edges[i]}-target-${[i]}`}

src/components/ReactFlow/createEdges.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ export default function createEdges(schemaObject: SchemaStore) {
2525
const table = schemaObject[tableKey];
2626
for (const rowKey in table) {
2727
const row = table[rowKey];
28-
if (row.IsForeignKey) {
29-
console.log('row', row)
30-
};
3128
if (row.IsForeignKey) {
3229
edges.push({
3330
id: `${row.References[0].ReferencesTableName}-to-${row.References[0].PrimaryKeyTableName}`,

src/components/ReactFlow/reactFlowTypes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface StoreProps {
2323
PrimaryKeyTableName: string;
2424
ReferencesTableName: string;
2525
IsDestination: boolean;
26-
constrainName: string;
26+
constraintName: string;
2727
}
2828
,
2929
IsPrimaryKey: boolean;

src/parse.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function parseSQLServerForeignKey(name, currentTableModel, propertyType) {
194194
currentTableModel.Properties.push(propertyModel);
195195
}
196196

197-
function parseMySQLForeignKey(name, currentTableModel, constrainName = null) {
197+
function parseMySQLForeignKey(name, currentTableModel, constraintName = null) {
198198
name = name.replace(/\"/g, '');
199199

200200
let foreignKeyName = name
@@ -255,7 +255,7 @@ function parseMySQLForeignKey(name, currentTableModel, constrainName = null) {
255255
false
256256
);
257257

258-
foreignKeyDestinationModel.constrainName = constrainName;
258+
foreignKeyDestinationModel.constraintName = constraintName;
259259
// Add ForeignKey Destination
260260
foreignKeyList.push(foreignKeyDestinationModel);
261261
}
@@ -298,7 +298,7 @@ function processForeignKey() {
298298
PrimaryKeyTableName: foreignKeyModel.PrimaryKeyTableName,
299299
ReferencesTableName: foreignKeyModel.ReferencesTableName,
300300
IsDestination: true,
301-
constrainName: foreignKeyModel.constrainName,
301+
constraintName: foreignKeyModel.constraintName,
302302
});
303303
}
304304
});
@@ -344,7 +344,7 @@ function parseTableName(name) {
344344

345345
function parseAlterTable(tableName, constraint) {
346346
const regexConstraint = /(?<=CONSTRAINT\s)([a-zA-Z_]+)/;
347-
const constrainName = constraint.match(regexConstraint);
347+
const constraintName = constraint.match(regexConstraint);
348348

349349
tableName = tableName.trim();
350350
let currentTableModel;
@@ -362,7 +362,7 @@ function parseAlterTable(tableName, constraint) {
362362
parseMySQLForeignKey(
363363
name,
364364
currentTableModel,
365-
constrainName !== null ? constrainName[0] : null
365+
constraintName !== null ? constraintName[0] : null
366366
);
367367
} else if (constraint.indexOf('PRIMARY KEY') !== -1) {
368368
const name = constraint.substring(

src/queryGen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// PrimaryKeyTableName: string,
1313
// ReferencesTableName: string,
1414
// IsDestination: boolean,
15-
// constrainName: string
15+
// constraintName: string
1616
// }
1717
// ],
1818
// IsPrimaryKey: boolean,
@@ -56,7 +56,7 @@ export default function queryGen(schemaObj: SchemaObject) {
5656
// if constraint pertains to a foreign key reference, build alterTableQ
5757
// access stuff on Reference to tell us what's up
5858
const ref = References[0]
59-
// `ALTER TABLE ${TableName} ADD CONSTRAINT fk${References{constrainName}} FOREIGN KEY (${field_name}) REFERENCES ${References{ReferencesTableName}}(${References{ReferencesPropertyName}})`
59+
// `ALTER TABLE ${TableName} ADD CONSTRAINT fk${References{constraintName}} FOREIGN KEY (${field_name}) REFERENCES ${References{ReferencesTableName}}(${References{ReferencesPropertyName}})`
6060
if (IsForeignKey === true){
6161
const alterTableString: string = `ALTER TABLE ${TableName} ADD CONSTRAINT ${ref['constraintName']} FOREIGN KEY (${field_name}) REFERENCES ${ref['ReferencesTableName']}(${ref['ReferencesPropertyName']}) ON UPDATE SET NULL ON DELETE SET NULL `
6262
alterTableQs.push(alterTableString);

src/store/displayStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default useDisplayStore;
3737
// PrimaryKeyTableName: string,
3838
// ReferencesTableName: string,
3939
// IsDestination: boolean,
40-
// constrainName: string
40+
// constraintName: string
4141
// }
4242
// ],
4343
// IsPrimaryKey: boolean,

tests/components/queryExport.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface Reference {
1111
PrimaryKeyTableName: string;
1212
ReferencesTableName: string;
1313
IsDestination: boolean;
14-
constrainName: string;
14+
constraintName: string;
1515
}
1616

1717
interface Column {
@@ -47,7 +47,7 @@ const schema: SchemaObject = {
4747
PrimaryKeyTableName: '',
4848
ReferencesTableName: '',
4949
IsDestination: false,
50-
constrainName: '',
50+
constraintName: '',
5151
},
5252
],
5353
IsPrimaryKey: false,
@@ -127,7 +127,7 @@ describe('Query Exports', () => {
127127
PrimaryKeyTableName,
128128
ReferencesTableName,
129129
IsDestination,
130-
constrainName,
130+
constraintName,
131131
} = References;
132132
expect(columnQuery).toBeInTheDocument;
133133
}

tests/queryGen.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface Reference {
55
PrimaryKeyTableName: string,
66
ReferencesTableName: string,
77
IsDestination: boolean,
8-
constrainName: string
8+
constraintName: string
99
}
1010

1111
interface Column {
@@ -40,7 +40,7 @@ const schema: SchemaObject = {
4040
PrimaryKeyTableName: "",
4141
ReferencesTableName: "",
4242
IsDestination: false,
43-
constrainName: ""
43+
constraintName: ""
4444
}],
4545
IsPrimaryKey: 'true',
4646
IsForeignKey: 'false',
@@ -58,7 +58,7 @@ const schema: SchemaObject = {
5858
PrimaryKeyTableName: "",
5959
ReferencesTableName: "",
6060
IsDestination: false,
61-
constrainName: ""
61+
constraintName: ""
6262
}],
6363
IsPrimaryKey: 'false',
6464
IsForeignKey: 'true',

0 commit comments

Comments
 (0)