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.76k forks source link

cli: allow to track all tables/relationships #1418

Open benoitscherrer opened 5 years ago

benoitscherrer commented 5 years ago

When using Hasura with an existing database, it would be super useful to be able to track all tables and all relationship with the cli (instead of having to go in the console in the browser) (eg for scripts or functional tests)

dsandip commented 5 years ago

Similar request on Discord but with a schema as an argument for the command. Maybe have the option to specify a specific schema or all? @shahidhk

razakpm commented 5 years ago

@dsandip my existing database has 2 schemas, I like to have track-all table and relationships automatically without any user intervention, Any way for it. atleast waiting that as a CLI command.

dsandip commented 5 years ago

@razakpm This should be available in one of the next couple of releases.

shahidhk commented 5 years ago

@arvi3411301 Here is the usage:

# track all tables in public schema
hasura metadata track --all-tables [--schema public]

# track all tables and relationships in public schema
hasura metadata track --all-tables --all-relationships

# track only 2 tables and relationships among them
hasura metadata track --table author --table article --all-relationships

# track all tables in schema1 and schema2
hasura metadata track --all-tables --schema schema1 --schema schema2

# track only one table table1 from schema1
hasura metadata track --table table1 --schema schema1
shahidhk commented 5 years ago
# untrack all tables in a schema
hasura metadata untrack --all-tables --schema schema1

# untrack only 1 table
hasura metadata untrack --table table1 --schema schema1
ghost commented 5 years ago

@shahidhk would it make sense to have this is a start-up options, so that it can be turned on from docker-compose? triggering a cli tool is not exactly convenient in a containerized environment.

shahidhk commented 5 years ago

@yyunak You can track all tables once using the console, export the metadata and load it on the container using the migrations image. This metadata will be applied every time the server starts. See: https://docs.hasura.io/1.0/graphql/manual/migrations/auto-apply-migrations.html

c19 commented 5 years ago

any progress on this?

hasura metadata track --all-tables is still not available on 1.0.0-beta.2

shahidhk commented 5 years ago

@c19 This is still a work in progress. Some internals were changed in between and the current PR has to be reworked.

shahidhk commented 5 years ago

We are looking at some architecture changes for code re-use in console and cli. The current PR needs to be re-worked.

benoitscherrer commented 5 years ago

I think this feature is really needed/critical for anybody wanting to do automatic functional testing.

Also, in your rework, it would be fantastic if we can rename relations. The automatic way to name them fails with some words (eg, Series -> Sery) which in our case will also impair our ability to do automatic testing if we can't rename them with a cli.

Keep up the good work!

Thanks Best Benoit

On Tue, Sep 10, 2019, 08:13 Shahidh K Muhammed notifications@github.com wrote:

We are looking at some architecture changes for code re-use in console and cli. The current PR needs to be re-worked.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hasura/graphql-engine/issues/1418?email_source=notifications&email_token=AFSOI3QOL7JKOVJHW3Q4FADQI6FNDA5CNFSM4GRFS4Y2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6K3VAA#issuecomment-529906304, or mute the thread https://github.com/notifications/unsubscribe-auth/AFSOI3XJKKLWER3DYK6TBUTQI6FNDANCNFSM4GRFS4YQ .

dvasdekis commented 4 years ago

+1 to this. In my development environment, my workflow is currently:

  1. Make a schema change within my Postgres environment and forget to update the Hasura metadata
  2. Redeploy my full docker stack
  3. Hasura can't apply its migrations due to incorrect metadata. I have to read the log to see the failure.
  4. Delete the metadata.json file
  5. Redeploy my full docker stack
  6. Click 'track all' on tables and relationships in Hasura
  7. Export the metadata.json to my repo
  8. Redeploy my full docker stack

I would really really really love :) a way for Hasura to start by tracking all views and relationships with admin-only default permissions, and then I only need to add to the metadata migrations to create non-admin permissions on specific views.

ctwhome commented 4 years ago

@arvi3411301 Here is the usage:

# track all tables in public schema
hasura metadata track --all-tables [--schema public]

# track all tables and relationships in public schema
hasura metadata track --all-tables --all-relationships

# track only 2 tables and relationships among them
hasura metadata track --table author --table article --all-relationships

# track all tables in schema1 and schema2
hasura metadata track --all-tables --schema schema1 --schema schema2

# track only one table table1 from schema1
hasura metadata track --table table1 --schema schema1

this doesn't exist anymore

thelinuxlich commented 3 years ago

Was this given up because of something else?

jbek7 commented 3 years ago

This missing feature would help a lot for CI & CD automation.

86label commented 3 years ago

With a schema-first approach, and automating environment creation, not being able to track all tables and relations programatically makes for a very difficult CI/CD setup.

Any plans to allow track all via CLI again?

sepbot commented 1 year ago

i was able to get most of the way there by using results of this api: https://hasura.io/docs/latest/api-reference/metadata-api/relationship/#pg-suggest-relationships but even after i track all the suggested relationships that api returns, there are still some more suggested in the console.

i think this where the console puts together the suggestion list. wish that was in the backend instead haha: https://github.com/hasura/graphql-engine/blob/3e83370c96c2aba91ea695dc31046e15c1ea9735/frontend/libs/console/legacy-ce/src/lib/components/Services/Data/TableRelationships/autoRelations.js#L97

manasag commented 10 months ago

Thanks everyone for your comments and patience on this issue. We have been closely listening into all the feedback and requests from the community, and have been working on a re-imagined, re-architectured Hasura, that tackles many of these from ground up. We are pleased to announce that we are launching V3-Alpha of Hasura (Data Delivery Network) on our next Community call on Nov 30. V3 puts a lot of emphasise on local dev and CI/CD experiences. The V3 CLI and a brand new Visual Studio plugin in V3 is planned to support such requirements, and very soon. Also, the metadata authoring experience is entirely local and decoupled from live APIs, thus allowing you to iterate without affecting your production APIs. We would request to join this community call to learn more about Hasura V3. Post launch, we will update this issue with relevant details.

poka-IT commented 7 months ago

Hasura cli v2.37.0, still unable to autotrack new tables or just use CLI to track new tables in DB. Do you have news about this simple feature? Do you need help??

poka-IT commented 7 months ago

This is a script which track tables, relationships and functions: https://gist.github.com/poka-IT/0214518dc185370f52223c7dae2edffd

Maybe it could help peoples reading here...