Skip to content
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

Implement schema .setNullable/.dropNullable. Fixes #1218 #1327

Closed
wants to merge 6 commits into from

Conversation

wubzz
Copy link
Member

@wubzz wubzz commented Apr 2, 2016

This adds .setNullable(column, [true|false]) to alter a columns nullable constraint.
This adds .setNullable(column) and .dropNullable(column) to alter a columns nullable constraint.

I'm not too happy with the implementation having to call SELECT 1, but this was the only way I found to support async actions, which are required in this case. See for example renameColumn for a similar case.

This is built around the information gathered in #1218 , so feel free to correct if anything is wrong.

@wubzz wubzz force-pushed the feature/schema_setnullable branch from f1194e0 to f3a0245 Compare April 2, 2016 14:10
@wubzz
Copy link
Member Author

wubzz commented Apr 2, 2016

TODO

  • Probably change this to .dropNullable(column) / .setNullable(column) instead
  • Try find different approach for the promises Requires a lot of changes in the library that would not be fitting to do in this PR/feature.
  • Research more on sqlite Does not support alterations as far as I can tell.

@wubzz wubzz changed the title An attempt to implement .setNullable. Fixes #1218 Implement schema .setNullable/.dropNullable. Fixes #1218 Apr 2, 2016
@wubzz wubzz force-pushed the feature/schema_setnullable branch from a5e62a6 to 88a9c01 Compare April 2, 2016 14:34
@wubzz wubzz added the schema label Apr 4, 2016
let nullableType = nullable ? 'null' : 'not null';
let columnType = columnInfo.type + (columnInfo.maxLength ? `(${columnInfo.maxLength})` : '');
let defaultValue = (columnInfo.defaultValue !== null && columnInfo.defaultValue !== void 0) ? `default '${columnInfo.defaultValue}'` : '';
let sql = `alter table ${tableName} modify column ${columnName} ${columnType} ${nullableType} ${defaultValue}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is quite a lot copy-paste between this and mssql implementation... could "modify column" string be moved to separate variable and just that variable would be overridden in mssql dialect?

@wubzz
Copy link
Member Author

wubzz commented Apr 5, 2016

@elhigu Good points, fixed! 👍

@tgriesser I saw #46 earlier today and wish I had seen it earlier. You probably notice this code is very similar to renameColumn. Do you want to hold of on this PR for now given your comments in that issue?

@rhys-vdw
Copy link
Member

rhys-vdw commented May 5, 2016

@wubzz This is consistent with renameColumn.

I could see the appeal of something more chainable:

table.changeColumn('some_column').null(false).default('empty').unique(false);

I think we can merge this though. What do you think?

@wubzz
Copy link
Member Author

wubzz commented May 5, 2016

@rhys-vdw Yeah I read #46 after doing this PR, and I agree a lot of what is mentioned in that issue can and would be better chainable. Would also allow for less duplicated code.

I think we should merge it for now, and then move the code out later on if we end up doing some alter-column specific chaining.

@nrempel
Copy link

nrempel commented Jun 20, 2016

Any update on this pull request? This feature would be very nice to have.

@loong
Copy link

loong commented Jul 9, 2016

@nrempel agree here. Any updates? Looking forward for a merge.

@wubzz
Copy link
Member Author

wubzz commented Jul 9, 2016

Leaving the decision up to @tgriesser on this one, considering #46 .

@wubzz wubzz mentioned this pull request Oct 27, 2016
@nabilfreeman
Copy link

Hi guys! any updates here?

@elhigu
Copy link
Member

elhigu commented Apr 24, 2017

I think this was implemented different way by .alter() column syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants