mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 12:25:05 +03:00
Add blog post for launch week 5
This commit is contained in:
1 parent
b386cace99
commit
8fa241efe6
1 file changed
+118
@@ -0,0 +1,118 @@
|
||||
# LW5: CLI v1 and Admin API beta
|
||||
|
||||
Today we are moving the Supabase CLI v1 out of beta. The Supabase CLI is capable of managing database migrations and generating TypeScript types. Follow these [install instructions](https://github.com/supabase/cli#getting-started) to get started.
|
||||
|
||||
In addition, we are also announcing the Admin API beta. The Admin API is a REST API that allows you to manage organizations, projects, Edge Functions, and more. You can read the [docs](https://www.notion.so/Docs-ca2dbdd3f4954da49132d44bead83f1e) or interact with the Admin API from the Supabase CLI v1.
|
||||
|
||||
## Manage organizations, projects, Edge Functions, and more
|
||||
|
||||
If you’ve used [Supabase Edge Functions](https://supabase.com/blog/2022/03/31/supabase-edge-functions#quickstart), you’ve used the Supabase CLI. We’re extending it to let you manage organizations and projects.
|
||||
|
||||
```bash
|
||||
supabase login
|
||||
supabase orgs list
|
||||
supabase projects create my-project --org-id cool-green-pqdr0qc --db-password ******** --region us-east-1
|
||||
```
|
||||
|
||||
Once created, link your Supabase project locally to begin development.
|
||||
|
||||
```bash
|
||||
supabase link --project-ref <project-id>
|
||||
```
|
||||
|
||||
You can also [call the Admin API endpoint directly](#admin-api) to create a project.
|
||||
|
||||
View the [Supabase CLI docs](https://supabase.com/new-docs/reference/cli) for the full list of available commands.
|
||||
|
||||
## Schema migrations
|
||||
|
||||
You asked for more database migration support, and we listened. We’ve made improvements to manually-written migrations and auto generated schema diffs.
|
||||
|
||||
### Schema diff-ing
|
||||
|
||||
Previously we supported schema diff-ing using PgAdmin. We found that the tool did not account for default privileges when generating role grants. This leads to verbose statements when diff-ing complex schema changes.
|
||||
|
||||
To improve the usability of `db diff` command, we are introducing another tool, [migra](https://github.com/djrobstep/migra), via the `--use-migra` experimental flag. We found that `migra` runs faster and produces more concise DDL statements. While the generated scripts are [not perfect](https://supabase.com/blog/supabase-cli#migrations), we hope this tool helps you iterate quicker on your migration scripts.
|
||||
|
||||
```bash
|
||||
$ supabase db diff --use-migra --file file_name
|
||||
# Creates a DDL script: supabase/migrations/<datetime_string>_file_name.sql
|
||||
```
|
||||
|
||||
Running the above command diffs the `public` schema of your local development database against a fresh shadow database. You may specify other schema by passing in the `--schema` flag multiple times or as a comma separate list. More details in our [migration guide](https://www.notion.so/Guide-local-staging-prod-workflow-b6666956d5b6432ebf1126e2b98d76c7).
|
||||
|
||||
In the long-term we hope to consolidate on a single diff-ing tool which is perfect, but diff-ing is hard so we would need your help and feedback to improve tooling.
|
||||
|
||||
### Manual migrations
|
||||
|
||||
For manual migrations, you can now test them out locally without the fear of losing unsaved data. Run the following commands to clone your local database to a new branch.
|
||||
|
||||
```bash
|
||||
supabase db branch new my_branch
|
||||
supabase db branch switch my_branch
|
||||
```
|
||||
|
||||
Now you can run any DDL statements from Studio UI’s SQL Editor. To undo the changes, simply switch back and delete the new branch.
|
||||
|
||||
```bash
|
||||
supabase db branch switch main
|
||||
supabase db branch delete my_branch
|
||||
```
|
||||
|
||||
## CI / CD
|
||||
|
||||
Automating migrations and tests on your CI / CD pipeline gives developers more confidence that each PR contains a working migration script. CLI v1 focuses on both local and [GitHub Action](https://github.com/supabase/setup-cli) support for the following workflows.
|
||||
|
||||
Testing all migrations on a fresh local database
|
||||
|
||||
```bash
|
||||
supabase init
|
||||
supabase start
|
||||
```
|
||||
|
||||
Releasing schema changes to staging and production
|
||||
|
||||
```bash
|
||||
$ supabase link --project-ref <project-id>
|
||||
$ supabase db push
|
||||
```
|
||||
|
||||
We created an [example project](https://github.com/supabase/supabase-action-example) showing how to set up GitHub Actions to test and migrate with Supabase CLI v1.
|
||||
|
||||
## Type generation
|
||||
|
||||
You can now generate TypeScript types using the CLI:
|
||||
|
||||
```bash
|
||||
# in a project set up with the CLI:
|
||||
supabase gen types typescript --local
|
||||
supabase gen types typescript --db-url $SUPABASE_DB_URL
|
||||
```
|
||||
|
||||
Of course, the types aren’t very useful on its own, you need some way to consume it. For that, stay tuned for tomorrow! 😉
|
||||
|
||||
# Admin API
|
||||
|
||||
The CLI is the first consumer of our new admin API. Over the next few weeks, we’ll be adding all the endpoints needed to programmatically add, remove, and update your Supabase projects. This is ideal for CI/CD workflows and spinning up test environments.
|
||||
|
||||
Here’s an example of how you can deploy a new project from the command line, you can generate your access tokens from [Supabase dashboard](https://app.supabase.com/account/tokens).
|
||||
|
||||
```bash
|
||||
curl 'https://api.supabase.com/v1/projects' \
|
||||
-H 'Authorization: Bearer <[your-access-token](https://app.supabase.com/account/tokens)>' \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "my-project", "organization_id": "cool-green-pqdr0qc", "region": "us-east-1", "plan": "free", "db_pass": "********"}'
|
||||
|
||||
# Response JSON:
|
||||
{
|
||||
"id": "abcdefghijklmnopqrst",
|
||||
"organization_id": "cool-green-pqdr0qc",
|
||||
"name": "hello",
|
||||
"region": "us-east-1",
|
||||
"created_at": "2022-08-12T17:37:11.88819Z"
|
||||
}
|
||||
```
|
||||
|
||||
Check out the API docs to browse all the functionality added so far.
|
||||
|
||||
The new API also opens the door to a whole new suite of integrations, including Zapier, Terraform, Pulumi etc. we’re looking forward to seeing how the dev community interacts with these new public endpoints.
|
||||
Reference in new issue
Block a user