Can't generate the types using the cli if I don't have a local instance running
Bug report
Describe the bug
I can't generate typescript types with the cli, if I don't have a local supabase setup
When I run this command, i get the following output
> supabase gen types typescript --db-url 'postgres://postgres:[my-db-password]@db.[my-project-id].supabase.co:6543/postgres' > types.ts
Error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Run the command above without. having a local instance of supabase installed.
Expected behavior
I want to generate the types based on the remote project I have running
System information
- OS: macOs
- Version of supabase-cli: 1.0.7
Hi @julianpoma , could you confirm that you have docker installed and accessible? The cli doesn't require supabase to be started, but it needs to run the Postgres meta container to generate types.
Hey @sweatybridge, I don't have Docker installed because we don't use it. Also I have a M1 chip macbook and I am not 100% if it is even compatible.
Is it possible to make this command run without needing docker?
My understanding is that most operations in the CLI require you to have docker installed. Your concern about the M1 macbooks is, as far as my personal experience goes, largely a thing of the past -- many developers use Docker + M1 these days, AFAIU.
I still believe that users should not be forced to install Docker just to get types. Types are an integral part of the new supabase-js v2.
At least we can improve the documentation regarding types, like providing a boilerplate of the database interface expected by the supabase client. By digging into the codebase, I came up with the following schema, hopefully someone finds it useful!
export interface Database {
public: {
Tables: {
profiles: {
// Fields returned by select operations
Row: {
id: string
email: string
name: string | null
created_at: string
}
// Fields accepted for insert operations. id is optional because is autogenerated.
Insert: {
email: string
name: string | null
}
// All types are optional because you might want to just update the name of a profile
Update: {
email?: string
name?: string
}
}
}
Functions: {}
}
}
It would be awesome I agree, but the hard part is to generate types that are consistent with the fully-migrated version of a database, you need to run the migrations on that database.
On Thu, Aug 18, 2022, 1:17 PM neucoas @.***> wrote:
I still believe that users should not be forced to install Docker just to get types. Types are an integral part of the new supabase-js v2.
At least we can improve the documentation regarding types, like providing a boilerplate of the database interface expected by the supabase client. By digging into the codebase, I came up with the following schema, hopefully someone finds it useful!
export interface Database { public: { Tables: { profiles: { // Fields returned by select operations Row: { id: string email: string name: string | null created_at: string } // Fields accepted for insert operations. id is optional because is autogenerated. Insert: { email: string name: string | null } // All types are optional because you might want to just update the name of a profile Update: { email?: string name?: string } } } Functions: {} }}
— Reply to this email directly, view it on GitHub https://github.com/supabase/cli/issues/384#issuecomment-1219740001, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPRLLPS46NBR7AVJYLA72TVZZV3RANCNFSM565HTTKQ . You are receiving this because you commented.Message ID: @.***>
Turning this into an enhancement since it is working as intended for the current version.
Needing docker for type gen feels overly complex when compared to v1 + openapi-typescript, and it isn't very clear what the gains are (the blog post mentions "a lot of detailed information").
MHO: Since Docker is the main distribution channel for all the other tools bundled within the CLI I find it reasonable to also use docker for the type generation.
Starting to use different distribution systems (npm, cargo, brew...) could lead to a big mess in a few years
I have a couple of question regarding the new type generation just to wrap my head around the whole thing
Looking at the source code
- a container of postgres-meta is started locally
- a command is sent to the container to start a script (check here and here) that generate the file inside the container
- the generated file is copied from container to your machine
This is different that the previous approach of exposing swagger (open-api) route accessible by other tools
example of old behaviour
npx openapi-typescript https://your-project.supabase.co/rest/v1/?apikey=your-anon-key --output types/supabase.ts
To my understanding there are other scenarios worth exploring that don't requires the usage of Docker
- the script executed inside the container doesn't have dependencies on pg-meta internals so a script could be created to use the postgres-meta client to connect to DB and generate the typings. It could be used use as as npx binary such as
npx supabase-type-gen URLAs it's happening here - expose an endpoint that generated and return the type (similar to open-api json)
- downside, could be resource intensive on the supabase hosted side
- query the
postgres-metaserver via http and generate the output string in this cli using go templates
of course this have the downside of generating types from what is currently in production as mentioned by @Marviel, but I think the majority of people would be fine with that (as they did with open-api), who have a proper flow where migration are applied and tested locally is already used to docker stuff for the local setup
did the choice to not expose it as an api from postgres-meta have a deeper story?
Let's wait and see if Docker becomes somehow a blocker for adoption of the feature? Maybe is just a little annoyance and people can live with as they are not supposed to deal with it directly
I still believe that users should not be forced to install Docker just to get types. Types are an integral part of the new
supabase-js v2.At least we can improve the documentation regarding types, like providing a boilerplate of the database interface expected by the supabase client. By digging into the codebase, I came up with the following schema, hopefully someone finds it useful!
export interface Database { public: { Tables: { profiles: { // Fields returned by select operations Row: { id: string email: string name: string | null created_at: string } // Fields accepted for insert operations. id is optional because is autogenerated. Insert: { email: string name: string | null } // All types are optional because you might want to just update the name of a profile Update: { email?: string name?: string } } } Functions: {} } }
Thank you for this. The new types have been frustrating to even try to use (to say the absolute least) because this very basic information is nowhere to be found, and frankly getting the CLI to work just to generate types has been enough for me to consider stop using Supabase entirely.
I'm running into Error: error running container
I didn't have Docker before. I'd tend to agree that installing Docker just for migrations seems like a big ask.
I faced this issue (trap). Now I could generate types with starting docker + $ supabase start.
The generated type is really better than openapi-typescript one. I hope this can be used without starting docker and the doc will be updated.
:tada: This issue has been resolved in version 1.8.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Hey all, you can now use the command with --linked and --project-id - these don't require Docker or supabase init (you still need to supabase login). Let us know if it works!
Also let us know if you're still bumping into Error: error running container above.