首页
12 条评论
chrisjc超过 3 年前
I've used a similar custom technique in the past, but only been able to deal with it from a read perspective. As a result I had to split schemas into read and write schemas which turned out wasn't too much off an issue since it was a data warehouse.<p>Read schemas were composed of mostly read objects: views, functions, procedures, external tables (backed by S3) and in some cases tables that were filled with static data (CSV/JSON/TSV from source-control ingested/copied into table). Views, functions, etc... all pointed out to a write schema that was managed traditionally (Flyway, CLI/Docker, etc).<p>If the read schema changed, I (CI/CD) would build out a new schema with the changes, leaving the existing schema unchanged. Every read schema was immutable and idempotent. In fact I would build a docker image with all of the DDLs and specific deployment tool (specific DB CLI version), publish and tag it. Worked perfectly for CI/CD (or manually if all else went wrong).<p>There were two options of making the new schema "live":<p>1) Swap old and new schema (not all DBs have this functionality). Swap back if something goes wrong.
2) Schemas are treated like artifacts with versions. It's up to the applications to decide which version they need to use, or matches their read service contracts. Swapping back to previous version goes hand in hand with the application release/rollback. Great for blue/green. Old schema would get dropped after a certain amount of time and sign-off.<p>This worked great, but having to split read and write schemas (even for data warehouses) and having two different database migration techniques eventually becomes problematic.<p>I really like your idea/approach of using a new schema for your new table, and adding triggers to your old table until you complete the migration. Do you have a way to rollback (without having to create a new migration that undoes the current migration)?<p>The only idea that I've come close to having about solving the write problem is by encapsulating write activities in a procedure that dual-writes to both old and new schemas/tables (hardly original). Problem with this is that for blue/green to continue working, it has to ensure that dual-write works in both schemas for a while (old-->new, new-->old) and there's the potential for split-brain. Moreover, adding dual-write capabilities to existing procedures means that the schema is no longer immutable. The whole process becomes more complex overall.
评论 #29838903 未加载
jfbaro超过 3 年前
Is there any migration scenario that you anticipate your view strategy won't be able to handle? Maybe add a "Limitations" section? Again..congrats. I am impressed and I hope someday this becomes part of PostgreSQL native feature set.
评论 #29837719 未加载
sidcool超过 3 年前
Important:
Note: Reshape is experimental and should not be used in production. It can (and probably will) destroy your data and break your application.
评论 #29840927 未加载
jeremyjh超过 3 年前
I've had some issues in the past with queries on top of views not properly using indexes in postgres. I wish I'd saved some examples but I'm now quite cautious about putting a lot of views between my queries and my tables (though the examples I had were not simple views, but views that joined several tables together). Are the views only used during the migration or are they used all the time?
评论 #29839334 未加载
shayonj超过 3 年前
This is very interesting, thanks for sharing. I had been noodling on the concept of zero downtime schema changes in postgres as well, and recently started <a href="https://github.com/shayonj/pg-online-schema-change" rel="nofollow">https://github.com/shayonj/pg-online-schema-change</a>. Its inspired by pg_repack and pt-online-schema-change (mysql).<p>I will give this a spin! Kudos
评论 #29838813 未加载
claytonjy超过 3 年前
This is so cool; wish I had this a few years ago when I implemented most of these features by hand on a per-migration basis!<p>I was using sqitch which worked well, but was thinking along the same lines as the author here, "can't this be automated?".<p>It's really nice to see both a confirmation of my approach and someone willing to explore the solution space.
评论 #29840945 未加载
jfbaro超过 3 年前
Wow! I love how elegant and powerful your strategy is. There is a lot of potential here and your tool might turn PostgreSQL into an even easier choice for new projects. Congratulations!
评论 #29837667 未加载
aargh_aargh超过 3 年前
IMHO this is the opposite to the ideal approach. The current schema version should contain tables and the old schema versions should contain views. Using the current form of Reshape is asking for maintainability and performance problems down the road as its approach doesn't let you easily drop old schemas and change indexes as new needs emerge.
评论 #29837102 未加载
smoe超过 3 年前
This looks really nice and I'm certainly going to try it out soon!<p>One thing that is not that clear to me, what the vision is on how to use Reshape once it is production ready. Is it meant to be used exclusively to handle you db schema (e.g. replacing alembic, sqitch, etc. completely) or alongside such tools to handle difficult migrations?
评论 #29852133 未加载
yakkomajuri超过 3 年前
Interesting, will give this a look. Have been digging into zero downtime migrations quite a bit lately.
评论 #29837741 未加载
ekzhu超过 3 年前
I am curious what is issue with existing migration tools? There are so many tools out there. What is the problem they are not solving?
评论 #29836526 未加载
tobias_irmer超过 3 年前
How do INSERTs work if you are migrating from `full_name` to `first_name` - `last_name`?
评论 #29836655 未加载