Declarative Schemas for simpler database management

https://news.ycombinator.com/rss Hits: 6
Summary

Today we’re releasing declarative schemas to simplify managing and maintaining complex database schemas. With declarative schemas, you can define your database structure in a clear, centralized, and version-controlled manner. Declarative schemas store the final desired state of the database in .sql files that can be saved and versioned alongside a project. For example, here is the declarative schema for a classic products table: _10create table "products" (_10 "id" serial primary key,_10 "name" text not null,_10 "price" numeric(10,2) not null,_10 "created_at" timestamp default now()_10alter table "products"_10enable row level security; Declarative schemas offer numerous benefits over making changes to your database schema directly: Single pane of glass. Maintain your entire database schema in one place, reducing redundancy and potential errors. Versioned migrations. Automatically generate migration files, ensuring consistent schema updated across environments. Store your declarative schema files alongside your project files in your version control system. Concise code reviews. Easily review changes to tables, views, and functions without manually repeating complex migration scripts. It's best practice to use Migrations to track and apply changes to databases. Every time you make a change, you create a new new file with all the changes, keeping changes versioned and reproducible. However, as the complexity of a database schemas grows, it becomes increasingly difficult to develop using versioned migrations as there isn't a single place to see the entire database schema. For example, at Supabase we have a complex and frequently-updated projects table. Here's partially what it looks like with RLS enabled: _32create table private.projects (_32 organization_id bigint not null,_32 inserted_at timestamp not null,_32 updated_at timestamp not null_32alter table private.projects_32enable row level security;_32create policy projects_insert_32with check auth.can_write(project_id...

First seen: 2025-04-03 18:57

Last seen: 2025-04-04 10:00