TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: What's wrong/right with Postgres migrations?

15 点作者 doganugurlu大约 1 年前
Background:<p>- About 9 months ago we burned 2 separate days handling migrations on Supabase. Supabase CLI version and&#x2F;or local Docker version change made it impossible for my teammate to bring up the db on their local. Migrations couldn&#x27;t be applied. Fresh pull didn&#x27;t work either. I thought this was a fluke.<p>- Working with a new team&#x2F;stack (flask, alembic, postgres). Twice in the last month I had to change the `alembic_version` in the db just to get the migrations to apply. I think we found ourselves in this situation because we rewrote the history by having the new new migration point to a previous revision (HEAD^) instead of the last one (HEAD). Not sure what our motivation was.<p>- What am&#x2F;are I&#x2F;we doing wrong? - What&#x27;s the right&#x2F;robust way to do this? - How are teams of size &gt;2 handling this? - Isn&#x27;t this scary?

5 条评论

konha大约 1 年前
&gt; How are teams of size &gt;2 handling this?<p>Directory with .sql files starting with a number. Each file contains a set of changes to the db. The db has a table with the number that was applied last. To migrate your db you check if you have a file with a number that is higher than the one in the db. Then you apply that file to your db. That’s it.<p>Sounds like you are working in a way that is not intended by your tool &#x2F; framework.
评论 #39629846 未加载
评论 #39629041 未加载
评论 #39631521 未加载
ianpurton大约 1 年前
I use dbmate and for a deployment I package up the migration files into a docker container which runs and then applies the changes.<p>Firstly I use a devcontainer for development so I know my versions line up. dbmate uses .sql files which also makes things a lot easier.<p>You can see my setup here <a href="https:&#x2F;&#x2F;github.com&#x2F;bionic-gpt&#x2F;bionic-gpt">https:&#x2F;&#x2F;github.com&#x2F;bionic-gpt&#x2F;bionic-gpt</a><p>Have a look at the CONTRIBUTING.md to get an idea of the dev workflow.
sethammons大约 1 年前
&gt; because we rewrote the history<p>Don&#x27;t rewrite shared history.<p>As for how migrations are ran. Last place, each team&#x2F;service had their own data store. Numbered sql files and forward compatible changes only. Sometimes this meant application code would have to write to two locations and in a later update change the read location.<p>Current gig, everything is managed by the django orm. Great when you have a single db; sucks to scale out to sharded tables, sharded db instances, and is a pain for migrating to new data stores.
sergiotapia大约 1 年前
I never experienced anything like this in Rails or Phoenix (Ecto) land.<p>The only time I had problems with database migrations were in javascript with Prisma. But that was because we had a local dev dataset, and the CEO had gone into past migration files and edited them manually. Prisma exploded every time and it was a pain to fix.<p>It sounds like your pains are also coming from people manually editing past migration files and committing them. Don&#x27;t do that!
ddorian43大约 1 年前
You can merge heads on alembic, nothing special. You just need tests for running migrations and its &quot;just&quot; like code conflict when merging.