Replies: 11 comments 33 replies
-
Since down migrations are going to be introduced, it would be useful to have a "reset" command that effectively just applies all down migrations. Just like in other ORMs like Prisma, this command would be only for development environments. |
Beta Was this translation helpful? Give feedback.
-
I hope to add default row migration |
Beta Was this translation helpful? Give feedback.
-
It would be nice to have auto-reversible migrations like in Rails or Django https://guides.rubyonrails.org/active_record_migrations.html#using-the-change-method |
Beta Was this translation helpful? Give feedback.
-
Two things:
A lot of projects are run by solo or small teams where migration conflicts are very rare. 14 digits are overkill for them. For this reason, Rails offers a config option to disable timestamp-based migration and keep using config.active_record.timestamped_migrations = false At a later time, as conflict concerns grow as your team size, you can just turn on the timestamp, and the sort order would still be maintained. (unless you reach 2024 migrations by then)
Also, I find timestamped migration names are poorly designed in ORMs, including Prisma. There's a balance in timestamp nomenclature: ISO-8601 exists because dashes between components are more human friendly.
To me, Or better yet, why not break down into folders, when you have hundreds of migrations?
I'd put the food for thoughts on the table. |
Beta Was this translation helpful? Give feedback.
-
I'm really looking forward to it being this:
|
Beta Was this translation helpful? Give feedback.
-
Hello and let me start by saying, I've tried drizzle for the first time on the new project and so far liking it very much. One thing that i just discovered and bothers me though is working with migrations, multiple branches and the merge of it. Let me give you an example to illustrate my point: Master contains migrations up to 30. A is merged in master => ok. Now the problem, you want to update branch B by rebasing on master.
So this is a real example I just did on my code and it very time consuming and very very error prone due to human intervention. I feel like I must have missed something completly, how are other people handling this use case ? If we had some down migrations I could have downed the migrations on B branch, remove the snapshots, journal entries and just kept the schema.ts then regenerated new snapshots from there, which would have made it less error prone. For context I am coming from other migration systems that considers the database as the source of truth so you don't have this problem of linked snapshot to fix. Please enlighten me, am I taking crazy pills here ? What did i miss ? |
Beta Was this translation helpful? Give feedback.
-
@AlexBlokh they actually do work beautifully, except that in Drizzle there's just 1 migration folder for the entire project. This is why conflicts happen all the time. Please check out Django, which resolves this in the vast majority of cases. Here's how it works: A single projects consists of different apps (let's call them “modules” here for simplicity) and each module has its own “models” file (in Drizzle's terms it's
This way, a developer working on the new articles feature is not conflicting with another developer who is working on account management. Each schema file can do imports from other modules, that is alright. And there can be dependencies between the modules, which is also fine. Note that I'm already using this kind of directory structure in drizzle for schema files, simply because it's better for code organization – you can have code that is related to some big feature next to its schema. All I need is drizzle to be able to generate migration files next to the schema files. Note that this is roughly how Django works (and has worked for years), and while conflicts can still happen sometimes (when developers change the schema for the same feature), for the most part they're completely eliminated. |
Beta Was this translation helpful? Give feedback.
-
Will there be any command for moving the current folder structure to |
Beta Was this translation helpful? Give feedback.
-
Hello there, I see there's been already quite a bit of discussions about this, so sorry if this question was already answered. We'd love to use Drizzle in our project, but the absence of Typescript/JavaScript migrations makes it completely impossible. Just want to know whether it makes sense to wait or continue to build up our app in Sequelize. |
Beta Was this translation helpful? Give feedback.
-
I have a question about the new folder structure:
If I understand this correctly, the Developer1 forks from the When they both merge their code, neither Am I misunderstanding how this is intended to work? |
Beta Was this translation helpful? Give feedback.
-
I'd like a way to store the latest version of a function, stored procedure, or other SQL primitive in a file so the team gets useful diffs on pull requests. The challenge is that if I reference that central file from a migration and then change the file, the migration is no longer a snapshot. One solution would be to have the slowly-changing SQL in one file, then when you run a migration that references it, it inherits a snapshot and generates a digest to prevent drift. Running the migration applies the snapshot. This may exist elsewhere, but I haven't found it. |
Beta Was this translation helpful? Give feedback.
-
Based on production feedback our migrations folder structure completely unusable due to git incompatibility
Current migrations folder structure looks like below
We have a journal which keeps track of migration snapshots as a linked list and this way we've being proactively searching for race conditions. Race condition is when you've generated several migrations on different branches from one parent schema.
Originally we were considering this a no go, we thought that you should merge one, then pull to the second branch, revert current migrations and generate new ones. This might be true but turns out for a very minor fraction of the real world cases, it's not a bug, it's a conscious decision and positive scenario which we're blocking for developers and are going to fix urgently.
What would be the new API
snapshot.json
,migration.sql
ormigration.ts
. Yes, in subsequent release we will add support fortypescript
migrations. We will also addmigration.down.sql
for sql down migrations andmigration.ts
files will haveup
anddown
migration functions.This also opens a way for you to easily drop unnecessary migration by just deleting a folder, which is a nice bonus and we will remove
drop
command fromdrizzle-kit
.drizzle-kit migrate
will apply lexicographically sorted migrations to the database and keep track of applied. Whenever there will be a migration to be applied which has an earlier timestamp than last one in applied migrations - we will throw an error, cause that's definitely an unexpected case for developers to solve. They will potentially regenerate migration and then apply to the database.new folder structure will look this way:
UPD 1:
While updated folder structure does not introduce any git conflicts, the way Drizzle is generating migration is now a problem
When generating migration - Drizzle will get the newest snapshot of the schema available in the codebase at the time, consume TypeScript schema and compare those 2, based on the difference - it will generate migrations and new snapshot. The problem with current approach is latest json snapshot might now be a forked version with race condition. To overcome this problem we now have 3 options:
database aware
migrations flow and have the ability to write js/ts migrations tooUPD 2:
After an extensive discussion, rnd and planning with @AndriiSherman - we came to the conclusion that neither of the ways you can do migrations is a silver bullet, either of those has pros and cons. Developers already use and love Drizzle way of generating and applying migrations, we just need to properly address downsides. Developers are now stuck in mostly the same ways they would be stuck with having
shadowdb
based migrations, we just need to properly communicate collision states and type out step by step guide for them to solve.We've came to an agreement to focus on current migrations flow, provide proper feedback on all err situation and provide a separate way for developers to manage their migrations without drizzle auto generation, with either a TS/JS builder or purely in SQL
TODO:
drizzle-kit check
upgrade to handle collision checks with detailed explanations and step by step guidedrizzle-kit check --db
check should be able to have access to db migrations table to be aware migrations applied to the database, that would enrich the feedback for the developerBeta Was this translation helpful? Give feedback.
All reactions