How to export/import SQL schema (tables, RLS policies, functions) between two Supabase

I’m working on a project using Lovable.dev (basically a Supabase wrapper), and I’ve already set up my dev project with tables, row-level security (RLS) policies, and Postgres functions. However, Lovable doesn’t seem to provide a good built-in migration or schema syncing feature. I want to: Dump the entire SQL schema (including table definitions, RLS policies, and functions) from my dev project. Apply it to a new or existing project. Ensure it updates existing tables without dropping data (like adding/removing columns or updating policies). Has anyone done this between Supabase/Lovable projects? What’s the cleanest way to handle this? CLI? Manual SQL? pg_dump? Any caveats? Thanks in advance!
3 Replies
silentworks
silentworks4w ago
pg_dump and the CLI does this, but do note your comment of not wanting it to drop data whilsts updating existing tables isn't as straight forward as just getting a export and importing it back. This requires some planning.
HARISH
HARISHOP4w ago
Thanks! Just to clarify — if I use pg_dump or the Supabase CLI to export and apply changes: Will it update existing tables (like adding new columns) without dropping data? Will it also apply new RLS policies and Postgres functions? Also, could you explain how to do this properly using the CLI — especially in a way that handles updates safely? Appreciate any guidance on the right steps or flags to use!
silentworks
silentworks4w ago
There is no automatic way to guarantee existing tables not dropping data as you have to make sure that new columns are created with nullable and you would need to create the alter statements for the new columns you are adding. You are asking two different things here from what I'm getting as you are asking how to export and import but it seems you are after doing a diff with an existing database rather as this is the only way the CLI will be able to generate alter statements. You should first be clear as to what you are trying to accomplish and then maybe someone will come along to guide you in the right direction. For your original question of export/import, you can use the CLI or pg_dump, both are documented enough to get you started.

Did you find this page helpful?