ponder-sh / ponder

A backend framework for crypto apps
https://ponder.sh
MIT License
613 stars 95 forks source link

[Idea] Database schema selection #1154

Open 0xOlias opened 6 days ago

0xOlias commented 6 days ago

With the 0.6 release, we removed the "publish schema" concept in an attempt to reduce complexity. Unfortunately, a number of users relied on the publish schema for zero downtime deployments with 1) direct SQL and 2) ponder serve. There are workarounds, but they are complex and manual - definitely a regression.

We'd like to unblock these users as quickly as possible.

TL;DR

Here's the new proposal.

Detailed proposal

Requirements

Instance behavior

With those in mind, here is yet another proposal for how Ponder could work at the database layer.

The implementation is more complex - there lots of edge cases to consider around locking, table name collisions, caching, and the reorg log tables (though we've solved most of this already).

Pros

Cons

We're using views as a "table alias" which is not what they are designed for. Ideally, the live/latest data would be a table. There's still a bit of magic here that I don't like.

Alternatives

Rename tables instead of using views

With this design, when an instance goes live it would rename its tables from the instance-specific version to the bare version. During a redeployment, the new live instance would need to forcefully rename the current live tables back to their instance-specific version, then rename its own tables.

The key benefit of this approach is that the latest data is an actual table, not a view. However, the implementation would be much more complex, bug-prone in crash scenarios, and I think more difficult to reason about.

kyscott18 commented 5 days ago

Few questions: