News for hackers. Stuff that matters.
Re:What MongoDB got right (2015) by drinchev on Tuesday November 28, 2017 @05:11AM (#15795879)
> What is so hard in writing table migration, it is like a few minutes of your time

Wow, I wrote migration script for a couple of table rationalisation and it took me a week, to make it error-prone and to provide a revert option. Not to mention that you usually need to work with production data on your local to test if the migration will work without any errors.

And If you happen to have a migration error on your production database. It is a terrible experience, which usually includes downtime.

Maybe my lack of experience on writing SQL migrations increased that time, but isn't this the whole point of the OP in terms of dev first.

Re:What MongoDB got right (2015) by mrighele on Tuesday November 28, 2017 @07:52AM (#15796742)
Writing SQL migrations is not easy, I agree with that. But I don't think the issue is with SQL: in my opinion migrations _in general_ are difficult to do properly , regardless of the technology, expecially

Even when you use a schemaless db like MongoDB, you still have to manage your data (let's say the schema is implicit).

If for example you decide that the "phone number" field is no longer a string but a list of objects (containing each the phone number and the kind of number), you will have to update the old data to adapt it to the new model, incurring in the risk of messing up production data.

Of course you can (and it is what many people do) avoid the problem at the data level and "fix it" at the application level (for example, checking every time if you have a single string or the new list), but if you really want you can do the same with a SQL database (keep the "phone" field on the table, but add the new table for the list of numbers).

A disadvantage of the SQL approach is that many are less versed in it than in the application language, but there are many tools available to handle SQL migrations in your framework's language.

Re:What MongoDB got right (2015) by candiodari on Tuesday November 28, 2017 @08:09AM (#15796865)
> Even when you use a schemaless db like MongoDB, you still have to manage your data (let's say the schema is implicit).

Yes, the "secret" to MongoDB not having to write data migrations is simple: you get to simply have them as technical debt for later.

What could go wrong ?

Well, that's easy too: an accounting system where each method has a switch with 10+ cases, each case having 30+ lines of code inside of it, depending on something like "record version" or worse, on implicit tests.

And what could be worse ? Well, having a switch with only 9 cases in one of those methods ...

Re:What MongoDB got right (2015) by rockostrich on Tuesday November 28, 2017 @09:51AM (#15797702)
> Of course you can (and it is what many people do) avoid the problem at the data level and "fix it" at the application level (for example, checking every time if you have a single string or the new list), but if you really want you can do the same with a SQL database (keep the "phone" field on the table, but add the new table for the list of numbers).

This is essentially how my team handles things while using HBase as our main DB. At first it felt weird to not write a migration at the DB level and maintaining compatibility is certainly something that you have to keep in mind at all times, but we have a pretty solid internal library for handling de/serialization in Scala.

> A disadvantage of the SQL approach is that many are less versed in it than in the application language, but there are many tools available to handle SQL migrations in your framework's language.

I was surprised by this at my previous job. One of the first things I learned about when starting to do web development was database migrations (Miguel Grinberg's Flask tutorial). Sure, I had to learn Alembic when I started the job, but it's a pretty straight forward API and the main issue was the lack of transactional DDL in MySQL that we constantly had to keep in mind. Besides that it was just writing SQL statements wrapped in Python.

Re:What MongoDB got right (2015) by ssijak on Tuesday November 28, 2017 @05:25AM (#15795946)
What you wrote is data migration. Table/database migrations are just DDL scripts which are usually really small on an ongoing project. For example you add 2 columns in a sprint so you have that in the SQL migration file for that sprint.
Re:What MongoDB got right (2015) by jbergens on Tuesday November 28, 2017 @07:17AM (#15796512)
A real project usually have a lot of things that changes over time, including how to store the data. Adding columns and tables are basically the only simple things and not even new tables are always easy if they are connected to other tables and you have contraints that means they have to be pre-filled with something from the old database. Other things that can change is splitting one table into multiple table while keeping all data, splitting or joining columns while keeping data and so on. For large datasets this may cause headaches. Any error will also cause a lot of extra work.
Re:What MongoDB got right (2015) by dorfsmay on Tuesday November 28, 2017 @09:07AM (#15797367)
Adding a column is easy!

What about removing a column? What about if you've decided that you both current and next version of the code to work (then removing a column is a 3 step process, copy to new and use new, skip a version, remove old).

Migration can and is often hard.

Re:What MongoDB got right (2015) by yoz-y on Tuesday November 28, 2017 @11:21AM (#15798576)
Migration is hard, but I fail to see how something like MongoDB makes this easier.

Either you kick the can to the code, or do a migration script. Is there some magic style of coding that allows me to use the old data structures with the new code without having to do any special checks?

Re:What MongoDB got right (2015) by pvg on Tuesday November 28, 2017 @07:50AM (#15796732)
it took me a week, to make it error-prone

Well, there's your problem right there!