+
+
+
- Untracked Relations
+ Untracked foreign-key relations
- {untrackedRelations.length === 0 ? (
-
- There are no untracked relations
-
- ) : null}
-
+
@@ -223,6 +250,7 @@ Schema.propTypes = {
const mapStateToProps = state => ({
schema: state.tables.allSchemas,
+ schemaList: state.tables.schemaList,
untracked: state.tables.untrackedSchemas,
migrationMode: state.main.migrationMode,
untrackedRelations: state.tables.untrackedRelations,
diff --git a/console/src/components/Services/Data/Schema/Tooltips.js b/console/src/components/Services/Data/Schema/Tooltips.js
index 514b0d30f031a..e3eac2e439d93 100644
--- a/console/src/components/Services/Data/Schema/Tooltips.js
+++ b/console/src/components/Services/Data/Schema/Tooltips.js
@@ -10,15 +10,13 @@ export const dataAPI = (
export const untrackedTip = (
- These are the tables/views in the schema which are not tracked by Data
- Microservice
+ Tables or views that are not exposed over GraphQL
);
export const untrackedRelTip = (
- These are the relations in the schema which are not tracked by Data
- Microservice
+ Foreign keys between tracked tables that are not relationships
);
diff --git a/console/src/components/Services/Data/TableCommon/TableReducer.js b/console/src/components/Services/Data/TableCommon/TableReducer.js
index 9b0c6564bdad1..d060a14c6306c 100644
--- a/console/src/components/Services/Data/TableCommon/TableReducer.js
+++ b/console/src/components/Services/Data/TableCommon/TableReducer.js
@@ -144,6 +144,7 @@ const modifyReducer = (tableName, schemas, modifyStateOrig, action) => {
lcol: '',
rTable: null,
rcol: '',
+ manualColumns: [],
},
};
case REL_SET_TYPE:
diff --git a/console/src/components/Services/Data/TableRelationships/Actions.js b/console/src/components/Services/Data/TableRelationships/Actions.js
index 7d90b82336616..67575cc6d07c7 100644
--- a/console/src/components/Services/Data/TableRelationships/Actions.js
+++ b/console/src/components/Services/Data/TableRelationships/Actions.js
@@ -1,4 +1,8 @@
-import { makeMigrationCall, loadUntrackedRelations } from '../DataActions';
+import {
+ makeMigrationCall,
+ loadUntrackedRelations,
+ loadSchema,
+} from '../DataActions';
import gqlPattern, { gqlRelErrorNotif } from '../Common/GraphQLValidation';
import { showErrorNotification } from '../Notification';
import suggestedRelationshipsRaw from './autoRelations';
@@ -410,6 +414,78 @@ const autoTrackRelations = () => (dispatch, getState) => {
);
};
+const autoAddRelName = obj => (dispatch, getState) => {
+ const currentSchema = getState().tables.currentSchema;
+ const isObjRel = obj.isObjRel;
+ const relName = formRelName(obj);
+
+ const relChangesUp = [
+ {
+ type: isObjRel
+ ? 'create_object_relationship'
+ : 'create_array_relationship',
+ args: {
+ name: relName,
+ table: { name: obj.tableName, schema: currentSchema },
+ using: isObjRel
+ ? { foreign_key_constraint_on: obj.lcol }
+ : {
+ foreign_key_constraint_on: {
+ table: { name: obj.rTable, schema: currentSchema },
+ column: obj.rcol,
+ },
+ },
+ },
+ },
+ ];
+ const relChangesDown = [
+ {
+ type: isObjRel
+ ? 'create_object_relationship'
+ : 'create_array_relationship',
+ args: {
+ name: relName,
+ table: { name: obj.tableName, schema: currentSchema },
+ using: isObjRel
+ ? { foreign_key_constraint_on: obj.lcol }
+ : {
+ foreign_key_constraint_on: {
+ table: { name: obj.rTable, schema: currentSchema },
+ column: obj.rcol,
+ },
+ },
+ },
+ },
+ ];
+
+ // Apply migrations
+ const migrationName = `add_relationship_${relName}_table_${currentSchema}_${
+ obj.tableName
+ }`;
+
+ const requestMsg = 'Adding Relationship...';
+ const successMsg = 'Relationship created';
+ const errorMsg = 'Creating relationship failed';
+
+ const customOnSuccess = () => {
+ Promise.all([dispatch(loadSchema()), dispatch(loadUntrackedRelations())]);
+ };
+ const customOnError = () => {};
+
+ makeMigrationCall(
+ dispatch,
+ getState,
+ relChangesUp,
+ relChangesDown,
+ migrationName,
+ customOnSuccess,
+ customOnError,
+ requestMsg,
+ successMsg,
+ errorMsg
+ );
+};
+
export {
deleteRelMigrate,
addNewRelClicked,
@@ -424,6 +500,7 @@ export {
resetRelationshipForm,
relManualAddClicked,
autoTrackRelations,
+ autoAddRelName,
formRelName,
getAllUnTrackedRelations,
};
diff --git a/console/src/components/Services/Data/TableRelationships/Relationships.js b/console/src/components/Services/Data/TableRelationships/Relationships.js
index a915a85de4fb8..134b70c7edbab 100644
--- a/console/src/components/Services/Data/TableRelationships/Relationships.js
+++ b/console/src/components/Services/Data/TableRelationships/Relationships.js
@@ -46,16 +46,13 @@ const getObjArrayRelationshipList = relationships => {
/* This function sets the styling to the way the relationship looks, for eg: id -> user::user_id */
const getRelationshipLine = (isObjRel, lcol, rcol, rTable) => {
const finalRTable = rTable.name ? rTable.name : rTable;
- const getGrayText = value =>
{value};
return isObjRel ? (
- {getGrayText(lcol)} → {rTable} :: {rcol}
+ {lcol} → {rTable} :: {rcol}
) : (
- {finalRTable} :: {rcol} → {getGrayText(
- lcol
- )}
+ {finalRTable} :: {rcol} → {lcol}
);
};
@@ -777,4 +774,4 @@ const relationshipsConnector = connect =>
export default relationshipsConnector;
-export { suggestedRelationships };
+export { suggestedRelationships, getRelationshipLine };