hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.09k stars 2.77k forks source link

RFC: Community library of data models, postgres functions and constraints for the console #4180

Open coco98 opened 4 years ago

coco98 commented 4 years ago

While setting up a database schema or doing data modelling in general, it would be immensely useful to be able to be able to use a best-practices reference schema to use as a starting point.

I imagine the experience to be something like this:

  1. On the data tab on the console, I can browse a library of community contributed schemas
  2. I can search for and import a schema into the console
  3. This schema could consist of Postgres data models and Hasura metadata
  4. These models and metadata get added to my current schema
  5. I can then iterate on the few models that I have to shape it into something I need
  6. I can also select a bunch of tables and "publish" the schema. The console will automatically detect the dependent objects to those tables and let me choose if I want to share tables, dependent views, functions, associated relationships, permissions etc

I imagine the schemas in the library to be a combination of full blown schemas or maybe even a few related tables put together.

Here are some examples that I think could be useful:

  1. ecommerce stripe checkout
  2. calendar: recurring events, events, cancelled events
  3. realtime user and taxis (partial uber type schema)
  4. trello schema (optimised for an offline first)

These examples can come with any combination of tables, views, functions, hasura relationships, hasura permissions.

In my mind I'm imagining a UI that's kind of like a combination of a searchable marketplace combined with a dbdiagram.io!

This idea can also be extended to:

Where are the "modules" in this library stored?

  1. It would be the simplest to think of these as github repositories that have a migrations folder containing an up.sql/down.sql and a metadata/ folder that contains the metadata files. Upon import, the console can "merge" the metadata and apply the SQL migrations
  2. Postgres functions and check constraints could be a set of files in the hasura/graphql-engine/community repo that can be pulled in to the console

Questions to others!

What kinds of reference schemas, hasura metadata examples, postgres functions/utilties would have helped you as you were using Hasura?

leoalves commented 4 years ago

Why not have the data model and the remote_schema/action code, instead of only the data model.

Hasura could define a template on how a developer should structure their Github repo and use that in the console.

Let's say I want to add a Firebase Authentication to the marketplace. I could have a Github repository with the following structuture:

The console could read that repo, apply the migrations/metadata changes, and show the Markdown of how to deploy the the code to the available providers. Providers could also be a filter on the marketplace search.

I think that having the database structure and the code that goes along with it will be more useful than just the data model.

I can see a lot of things that could go into this marketplace that would make a lot easier for beginners to get started with Hasura.

More experienced users could also benefit from it sharing their code and implementations.

weyert commented 4 years ago

Sounds like a great plan! Really interested in the calendar one. If anyone wants to discuss and brainstorm about this in Discord give me a shout :)

leoalves commented 4 years ago

I saw this on HackerNews today and remembered about this issue https://drawsql.app/templates