-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should Granite have a built in Migrator? #182
Comments
@eliasjpr Granite actually did have this but it was impossible to know the intent of the developer so we removed in favor of micrate. An example is renaming a column in the db. You can create a new column but the old one should not be removed until the data is migrated. The technique I used when I built this was that the migrations were always additive unless you included a flag to perform a cleanup to remove old columns. This sorta worked but required much more care and handling than just supporting migration scripts. |
Well, I think a migration system using crystal is a bit overloaded since crystal is compiled and not an scripting language, so every time you need to run a migration action you would need to compile it first 😅 Currently, I just edit the SQL and run So, by example, If I want to execute migrations in Heroku, and I want to change something for the migration itself, (some type, bugfix, etc), I can't because I would need to compile the migrations first. Another example, if you try to use Lucky record you will notice that |
I'm not opposed to granite having a migrator library, but it seems like there are a lot more places which need time and energy at the moment. Micrate isn't a pretty, DSLy solution, but it is simple, functional and doesn't seem like it's going to be a maintenance problem. |
Ruby starts some time too, and running migration is like start Ruby and then run script. So I thing speed will be very similar when you compile migration and then run it. Crystal already can do something like crystal run src/my/main.cr ... Also if there is more than one migration it will start Ruby once and run all migrations. Migration in Crystal can do the same. |
The question which kept coming to mind while considering this is "Is it faster in Crystal or in SQL?" In deliberating on ☝️ with myself, I realized that the Migrator for Crystal would only be sugar on SQL. This would mean that over time, the Migrator may begin to struggle to do what SQL does best. Also, leaving the migrations in SQL forces the developer to think about their data from a data perspective — this is one of the few things which attracted me to Amber, as opposed to Rails where everything is Rails-y I believe having migrations in Crystal may constrain what developers can do with their databases. |
@igbanam I agree with you! But we are in the minority. I have heard several complaints from self proclaimed "lazy" rails developers that don't want to use SQL DDL (Data Definition) or DML (Data Manipulation) and prefer the framework handle it for you. We have already introduced |
@drujensen …but this is Amber, not Rails 🙂 |
@igbanam Food for thought: What about allowing multiple types of migrations, detected either by a hint at the top of the migration file or by extension (i.e. Thus, it leaves it up to the developer to choose which type of migrations preferred, and could consider using both as necessary interchangeably. Though take with a grain of salt because I'm not exactly authoritative on this and I have not put much thought into the deeper implementation details here. |
Hi. I thing you miss one benefit of DSL migrations and this is switching between databases ... You develop on Mysql or SQLITE and have production in PostgreSql ... I using SQL migration you can't do that ... Customers are paying for short time dev. and reliable app and you are doing definitely more mistakes in plain SQL then in AR - so it takes more time to make something working. So you are more expensive and less able to compete. I don't see any advantage in that for business. ;) |
@Pepan Yes, very aware of the benefits of a DSL but I think you may not be aware of the downside. The biggest one is that the developer doesn't know what is going on. They write the code completely unaware the SQL is even being used. I have seen too many rails projects considered What I think we need is a balance. We need to provide the ease of I've been playing around with a DSL that directly mimics the SQL. Something like:
This provides a clean separation of the SQL query being generated and the ORM mapping. Obviously, we could do the same for migrations or DDL. |
@drujensen We know about N+1 problem ale if it is in case we optimise it for this problem, but if it is no bottle neck, we don't care (f.e. if it is on small table little often used). Also devs have University education so It is expectable that they know about SQL :) AR can in this days do same thing like |
@Pepan Right, you would think these are easily solvable problems. ;-) I'm just stating my anecdotal observations here in the U.S. Maybe my concerns are not founded. |
I'm split on this. The reason I think it would be good to have a migrator comes up mostly because of the Migrate shard. Don't get me wrong I think is a great project but it still has its limitations. One of them being executing multiple queries.+ |
Migrations written in the app language (eg: Ruby) and with the framework (eg: Rails) loaded up, do offer a lot of convenience:
I love the idea and philosophy behind what @drujensen is saying. When I first saw SQL migrations in Granite (while learning Amber) my thought was "Nice, great idea. SQL Migrations should be the default.". Not just because of performance but also because of simplicity. But then I also thought about all those times in Rails where I wrote migrations that needed to access my AR models or other objects (like services) in order to migrate data. I wondered what I would do in situations like that with Amber & Granite. Perhaps there is a clear workaround for this that I haven't considered @drujensen ? Anyway, my current +1 is on supporting both PS: It's also a bit inconsistent having a seeds file which is |
To my experience, one of the best features of SQL migrations is that your models and app code aren't available. Data migration logic should live elsewhere, not in with the schema migrations. |
Why would you develop for a different database than what you have in production?
Shorter != faster. It can easily be tested by pasting it into a database console. None of that is true for a custom migration DSL. +1 for keeping Amber migrations in plain SQL rather than |
Hey
So developer using DSL is faster, happier, more productive and doing less errors against otherone using pure SQL. For customer is developer using DSL much more interesting, because deliver safer product in shorter time and that is what is counting ... |
I don't know why you keep using query examples, this ticket is about migrations (DDL). You seem to be focussed on developers who are unfamiliar with SQL. |
Closing this ticket since Granite already has a way to migrate the database via Micrate and adding a new DSL is not desired at this time. Benefits of Micrate
Drawbacks of Micrate
Desires
|
Given this PR #172 and #168 which as basic support for table migration and bulk import, I have been wondering if Granite should fully support migrations?
I think is time :)
Open implementation detail discussion
The text was updated successfully, but these errors were encountered: