Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Create database route, endpoint and service #288

Merged
merged 14 commits into from
Apr 28, 2021

Conversation

rudream
Copy link
Contributor

@rudream rudream commented Apr 27, 2021

Purpose

This PR resolves #271

Create a route and endpoint to for fetching databases. Process the response so that all fields are properly set up and formatted for front-end displaying and searching.

Implementation

Define an api endpoint in config.ts to be used by our database service for fetching databases for a given :clusterId. Create makeDatabase.ts to process the response data such that:

  • An undefined labels field defaults to an empty array []
  • Labels formatted as [{name: value}] are turned to ["name: value"]
  • Type and protocol fields are optimally formatted (eg. 'postgres' -> 'PostgreSQL')

Call this makeDatabase() to process the response when fetching databases in the database service.

The route and route getter I defined in config.ts will be used in the next issue when registering the feature.

Demo

If makeDatabase() is given the following data:

{
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    protocol: 'postgres',
    type: 'rds',
    uri: 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432',
    labels: [
      { name: 'cluster', value: 'root' },
      { name: 'env', value: 'aws' },
    ],
}

it will return:

{
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    protocol: 'PostgreSQL',
    type: 'RDS',
    uri: 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432',
    tags: ['cluster: root',  'env: aws']
}

formatteddatabases

@rudream rudream linked an issue Apr 27, 2021 that may be closed by this pull request
5 tasks
@rudream rudream linked an issue Apr 27, 2021 that may be closed by this pull request
6 tasks
@rudream rudream requested a review from kimlisa April 28, 2021 03:14
@alex-kovoy
Copy link
Contributor

image

Lets combine these 2 fields into 1 and call it TYPE and make sure that search works when a user types rds/p for example.

RDS/PosgreSQL
GCP/PosgreSQL
MySQL

@rudream rudream force-pushed the yassine/route-endpoint-service branch from ffd2bbb to 736e9a5 Compare April 28, 2021 16:28
@rudream rudream force-pushed the yassine/route-endpoint-service branch from 736e9a5 to 949a8dc Compare April 28, 2021 16:29
@rudream
Copy link
Contributor Author

rudream commented Apr 28, 2021

Update

Upon @alex-kovoy 's suggestion, the type and protocol fields are now combined.

If makeDatabase() is given:

{
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    protocol: 'postgres',
    type: 'rds',
    uri: 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432',
    labels: [
      { name: 'cluster', value: 'root' },
      { name: 'env', value: 'aws' },
    ],
}

it will return:

{
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    type: 'RDS/PostgreSQL',
    uri: 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432',
    tags: ['cluster: root',  'env: aws']
}

Screenshot of new table

updateddatabases

@r0mant
Copy link
Contributor

r0mant commented Apr 28, 2021

@rudream @kimlisa I think combining type/protocol is a good idea. A couple of suggestions:

  • Let's remove the slash? So it would say Self-hosted MySQL, RDS PostgreSQL, etc. which reads a bit better.
  • Can we please also rename GCP to Cloud SQL? It would be more accurate. Ideally I need to rename it on the backend as well but I'm stuck with it for now. So for the frontend just translate "gcp" to "Cloud SQL" if possible.

@r0mant
Copy link
Contributor

r0mant commented Apr 28, 2021

@rudream @kimlisa Also, didn't we agree not to include the database endpoint (URI) in the table? I don't think it has much value for the user - e.g. tsh db ls doesn't show it by default.

Instead, we should have a Connect button on the very right of each row which would bring up a dialog with instructions for a user how to connect to the database.

@kimlisa
Copy link
Contributor

kimlisa commented Apr 28, 2021

@r0mant the connect button is in a separate issue: #277 (add database button is also a separate issue)

and @rudream along with other changes, lets remove the URI column, i must've forgotten about removing it, sorry about that :)

@rudream
Copy link
Contributor Author

rudream commented Apr 28, 2021

Update

After implementing @r0mant 's suggestions:

The DatabaseList no longer displays the URI column.

If makeDatabase() is given:

{
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    protocol: 'postgres',
    type: 'rds',
    uri: 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432',
    labels: [
      { name: 'cluster', value: 'root' },
      { name: 'env', value: 'aws' },
    ],
}

it will return:

{
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    type: 'RDS PostgreSQL',
    uri: 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432',
    tags: ['cluster: root',  'env: aws']
}

Screenshot of new table

updatedupdatedtable

@rudream rudream requested a review from kimlisa April 28, 2021 18:51
@rudream
Copy link
Contributor Author

rudream commented Apr 28, 2021

Update

After removing the uri field as suggested by @kimlisa

If makeDatabase() is given:

{
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    protocol: 'postgres',
    type: 'rds',
    uri: 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432',
    labels: [
      { name: 'cluster', value: 'root' },
      { name: 'env', value: 'aws' },
    ],
}

it will return:

{
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    type: 'RDS PostgreSQL',
    tags: ['cluster: root',  'env: aws']
}

@rudream rudream requested a review from kimlisa April 28, 2021 21:01
@rudream rudream requested a review from kimlisa April 28, 2021 21:57
@rudream rudream requested a review from kimlisa April 28, 2021 22:40
Copy link
Contributor

@kimlisa kimlisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one small nit: rename services/database/ to services/databases/ and you're good to go!

@rudream rudream merged commit 650da1f into feature/db Apr 28, 2021
@rudream rudream deleted the yassine/route-endpoint-service branch April 28, 2021 23:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DB Access 3] Define route, endpoint, and service
4 participants