-
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
Extract Migrator#create and #drop sql into separate methods #326
Conversation
But alas, as per Murphy's Law, "If something can go wrong, it will." It did. Fix coming right up |
There, obvious mistake on my end 😅. Fixed now |
@Jens0512 This is a nice added feature. What do you think about adding a test to show that these methods are working as expected? |
Well, while that's a great idea, I'm not quite great enough at SQL to know what the should return... |
@Jens0512 Its pretty easy. It would however depend on what the current adapter is. Assuming for a model like: class Post < Granite::Base
adapter pg
table_name posts
field name : String
field body : String
timestamps
end
Could pretty much get away with running it, seeing what the output is and use that as the expected string. We can review it afterwards so shouldn't be a problem. Ideally we would use a model that has all data types in it to fully test the migrator (which i dont think it is atm?). |
@Blacksmoke16 is right about the technique "run the method, copy the output, and assert that the result is always the output". Typically, I wouldn't say that's a good practice, but in this case we already know it's working (if only by experience). So asserting that the output is consistent will do the job of ensuring that no accidental changes to the output of the methods are introduced without raising a warning. |
Sounds good to me, as long as we know the initial output is correct. Thanks a ton for the help @Blacksmoke16.
Shall I create one and put it in |
@Jens0512 Yea that would be fine. Be sure to also test the PG array types. There is already a model that has them defined. Will have to scope it to run on PG only since the other DBs dont support it. Can reference https://github.com/amberframework/granite/blob/master/spec/granite_spec.cr#L261-L321 |
(Seems there was a model with all types already: Review) |
The formatting of the generated SQL is terrible to behold haha Did I miss anything? |
Oh no, ameba has detected a terrible line of whitespace... |
Maybe mention somewhere in the README that you should run ameba before you push. Just in case you put a 2-3 extra white spaces anywhere... :D |
@Jens0512 This is looking great thanks! I remembered there would be two other cases we should test.
Would you mind adding specs for those as well? |
Nothing to be sorry about :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was good. Took the time to look through each driver's docs and found some discrepancies we should fix. The fixes for the comments are pretty simple, just have to add an override to the that driver's file's TYPES
constant. So that when it goes to lookup the type, it would use the driver specific one versus the defaults we setup in base.cr
.
Thanks for this!
Thanks for the feedback, anything else? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good as far as I can tell. Would like another reviewer tho. @drujensen @robacarp @amberframework/granite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @Jens0512
Fixes #319.
I haven't managed to run the specs (difficulties with docker), but the changes shouldn't change any behaviour, only expose functionality.