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

Controlled casting #127

Merged
merged 9 commits into from
May 18, 2021
Merged

Controlled casting #127

merged 9 commits into from
May 18, 2021

Conversation

mathemancer
Copy link
Contributor

Fixes #126

This adds a number of DB functions, and replaces the column alteration logic to use them. These functions give us more precise control over what is done when casting one type to another (mostly to make things safer).

Technical details

This requires knocking out your Mathesar DB and reinstalling, since we still don't have upgrade functionality working.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the master branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@mathemancer mathemancer requested review from a team, kgodey and pavish May 14, 2021 08:54
Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

@mathemancer I added some comments but I'm approving to unblock merge. If I'm around when you're done making changes, feel free to ask me to rereview before merge.



def get_supported_alter_column_types(engine):
dialect_types = engine.dialect.ischema_names
Copy link
Contributor

Choose a reason for hiding this comment

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

Datetimes should be fairly simple to add too, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather leave those for a separate issue / PR, since there'll be some complexity around dates vs times vs datetimes, and TZs (how to decide whether a column of times should be imported with the local TZ, assuming UTC, etc.)

Copy link
Contributor Author

@mathemancer mathemancer May 18, 2021

Choose a reason for hiding this comment

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

I know we've discussed the plan w.r.t. TZs, but I think having dates/times/datetimes separated out in a well-documented PR might benefit future code archaeologists.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense.

create_varchar_casts(engine)


def create_boolean_casts(engine):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you document what this function (and other similar functions) are doing in comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

Copy link
Contributor Author

@mathemancer mathemancer May 18, 2021

Choose a reason for hiding this comment

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

I documented them with docstrings to make it visible using the help function. I also considered documenting them in comments in the PL/pgSQL functions themselves instead, but I think folks are more likely to be able to (or want to) read the python docstrings than comments in the SQL. Do you agree?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, agreed.

@mathemancer mathemancer requested a review from kgodey May 18, 2021 09:42
Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

Looks great, @mathemancer



def get_supported_alter_column_types(engine):
dialect_types = engine.dialect.ischema_names
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense.

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

Successfully merging this pull request may close these issues.

Controlled Casting
2 participants