Aurabase News

Aurabase - The European alternative to Supabase, a Backend as a Service

Moving from Firebase to PostgreSQL: a schema design guide

A careful migration starts with the queries your app needs, then turns document paths into relational tables without forcing every value into a rigid shape.

Illustration principale : Moving from Firebase to PostgreSQL: a schema design guide — Aurabase News
By Léa Blanchard·November 3, 2026·4 min read
What matters here
  1. Model frequently queried relationships as PostgreSQL tables and foreign keys, not copied document fields.
  2. Keep genuinely variable attributes in JSONB when they do not need relational constraints or frequent filtering.
  3. Treat auth, realtime behavior, file storage and access rules as separate migration workstreams.

Moving from Firebase’s document model to PostgreSQL is not a matter of translating each document into one row. Documents often combine fields that belong to different entities, repeat data to make reads convenient, and nest child records along paths. A relational design separates those concerns around the questions the application must answer.

That change can pay off when the product needs joins, constraints, reporting, or reliable updates across related records. It also adds design work. If the app mostly reads and writes self-contained documents, and its current access patterns are simple, staying with a document database may be the more direct choice. The right answer depends on query patterns and operational requirements, not on a general ranking of database types.

Start with reads and writes, not the document tree

Inventory the application’s actual queries before drawing tables. For each screen or service, note which records it loads, which fields it filters or sorts by, and which writes must succeed together. Include background jobs and administrative reports; they often reveal relationships hidden by a client-first document layout.

Suppose a project document contains a customer name, a list of members, and recent events. If customers have many projects, members can belong to multiple projects, and events need independent retention, represent those as separate entities: customers, projects, users, project membership, and events. A membership table can hold the relationship between users and projects. An event can refer to its project through a foreign key.

This structure avoids copying the customer name into every project or storing an ever-growing event list inside one record. It also makes the intended relationships explicit. Use unique constraints for values that must be unique and foreign keys where a reference must point to an existing row. Those rules belong in the database when they are central to data integrity.

Translate nested collections into relationships

A nested collection is often a one-to-many relationship in disguise. A path such as a project’s tasks can become a tasks table with a project ID. If a task can have several labels and each label applies to many tasks, use a join table rather than a list of duplicated label objects. This gives the database a clear way to enforce and query the relationship.

Do not normalize mechanically. Some repeated values are deliberate snapshots: an invoice may need to preserve the customer’s address as it was when the invoice was issued. Keep that historical value where the business rule requires it, even if the current address lives elsewhere. Schema design follows the meaning of the data, not a rule that duplication is always wrong.

Use JSONB for flexibility, not as a second document database

PostgreSQL’s JSONB type can hold attributes whose shape varies, such as optional metadata supplied by different integrations. It is useful when the application needs to preserve flexible input while keeping core entities relational. It is less useful when important fields are routinely filtered, joined, validated, or updated independently. Those fields are usually better as typed columns.

A practical test is whether the application needs the database to understand a value. If it needs a constraint, a stable index, or a relationship to another record, model that value explicitly. If it is opaque metadata that is read and written as a unit, JSONB may be a reasonable boundary. Define and validate its shape in application code where needed; a flexible column does not automatically provide a complete data contract.

Plan for behavior beyond the schema

A database migration does not automatically move authentication, file handling, realtime subscriptions, or authorization behavior. List each Firebase-dependent capability and decide where it will live after the move. Recreate access checks deliberately, and test them with realistic user roles. A relational schema alone does not preserve the security behavior of the old application.

For the data transfer itself, map source records to target rows, preserve stable identifiers when that helps existing references, and make the import safe to rerun. Compare record counts and representative relationships. Then test application queries against the new schema before switching writes. A staged period with a defined source of truth can reduce risk, but dual writes need careful handling: partial failures can leave the two systems disagreeing.

Choose the backend that fits the team

Keeping Firebase suits teams whose data is naturally document-shaped, whose existing application depends on its surrounding services, and who want to avoid a broad migration now. PostgreSQL managed separately can suit teams that want direct control over database choices and are prepared to assemble and operate the surrounding services. A backend-as-a-service built around PostgreSQL may suit teams seeking relational data alongside managed application services, while accepting the platform’s constraints and service model.

Aurabase is one option in that last category. It is hosted in Europe and provides PostgreSQL, authentication, realtime APIs, S3-compatible storage, functions, AI tools, and notifications. Its package, @aurabase/aurabase-js, and Rust Crate are available, and it generates TypeScript definitions from database schemas. Those capabilities may reduce the amount of backend integration work for a team building on PostgreSQL. They do not make an existing Firebase application a drop-in migration: the schema, application queries, authorization rules, and service behavior still need review. Aurabase is free to get started with no credit card required.

Teams weighing typed database contracts can also find useful context in this paper’s discussion of generated types and the database-to-UI contract. In any migration, generated types help connect schema changes to application code, but they do not replace a sound relational model.

The strongest migration is usually incremental. Start with one bounded workflow, model it around real queries, and validate correctness and access controls before moving more data. If the document model still fits the product, there is no need to migrate for its own sake. If relationships and constraints have become central, PostgreSQL gives them a first-class place in the design.

More from Aurabase News