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

Removing SQLAlchemy 1 #2690

Merged
merged 24 commits into from Mar 23, 2023
Merged

Removing SQLAlchemy 1 #2690

merged 24 commits into from Mar 23, 2023

Conversation

mathemancer
Copy link
Contributor

@mathemancer mathemancer commented Mar 16, 2023

Related to #2737

This removes SQLAlchemy imports from:

  • db.tables.operations.alter and
  • db.tables.operations.drop.

Technical details

This also adds some scaffolding functions in db.connection that can be used to avoid wrangling around function signatures until later in the process. These help us run the new functions with old SQLAlchemy objects.

It also has a couple of prototype database functions for

  • Getting the joinable tables, and
  • Setting up the Mathesar Views we'll use for DQL operations in the future.

The SQL scripts setting these up need to be run manually if you want to use them, since they're not yet integrated into the overall project.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop 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 a review from dmos62 March 16, 2023 07:49
@pavish pavish added status: draft pr-status: review A PR awaiting review and removed status: draft labels Mar 16, 2023
@pavish pavish added this to the Backlog milestone Mar 16, 2023
Copy link
Contributor

@dmos62 dmos62 left a comment

Choose a reason for hiding this comment

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

Interesting read. Didn't manage to get through everything tonight, will finish next week.

db/sql/prototype.sql Outdated Show resolved Hide resolved
db/sql/prototype.sql Outdated Show resolved Hide resolved
-- Update table primary key sequence to latest -----------------------------------------------------

CREATE OR REPLACE FUNCTION
__msar.update_pk_sequence_to_latest(table_name text, column_ text) RETURNS text AS $$/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this compatible with multi-column PKs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is a direct port of the current python function (which also doesn't handle multi-column primary keys).

My plan is to get the current logic ported over while making minimal changes. I'm hoping to use pretty much the same test suite.

However, reviewing all this is a great opportunity to write up bugs and issues about exactly this sort of thing.

I'm pretty sure (hoping) that this function is only called when we're already sure it's a single-column primary key, namely when we've set the default id column as SERIAL PRIMARY KEY after the splitting logic runs. If that's wrong, we definitely need a bug report issue for this.

viewname, viewcols, __msar.get_table_name(table_id)
);
END;
$$ LANGUAGE plpgsql RETURNS NULL ON NULL INPUT;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do I understand this correctly? A Mathesar view is a reflection of a user table. A Mathesar view is algorithmically named according to the user table's oid. Its column values are the reflected user table's column values, and its columns' names are the corresponding reflected table columns' attnums. Would be great to put this in a docstring somewhere around here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You understand correctly. I'll figure out some reasonable way to document the purpose of these views, and how they work.

Copy link
Contributor

@dmos62 dmos62 left a comment

Choose a reason for hiding this comment

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

Approving. Also asked for a non-critical improvement.

db/install.py Outdated
@@ -30,6 +35,8 @@ def install_mathesar(
if database_created:
print(f"Installing Mathesar on PostgreSQL database {database_name} at host {hostname}...")
install.install_mathesar_on_database(user_db_engine)
with open(PROTOTYPE_FILE) as f, engine.begin() as conn:
conn.execute(text(f.read()))
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 export executing the prototype SQL into a function and replace this block and the indentical blocks on line 23 and on conftest.py:79 with that? Will make it easier to maintain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Naturally. This bit was a little too prototypey.

@mathemancer mathemancer marked this pull request as ready for review March 22, 2023 03:01
@mathemancer mathemancer changed the title Sql prototyping Removing SQLAlchemy 1 Mar 22, 2023
@dmos62
Copy link
Contributor

dmos62 commented Mar 22, 2023

Looking good. Ping me if you think this needs a last review.

@rajatvijay rajatvijay assigned mathemancer and unassigned dmos62 Mar 22, 2023
@rajatvijay rajatvijay added pr-status: revision A PR awaiting follow-up work from its author after review and removed pr-status: review A PR awaiting review labels Mar 22, 2023
@mathemancer
Copy link
Contributor Author

@dmos62 Code-wise, this is ready. I'm just setting up some of the surrounding (meta)issues and project stuff so that I can note them in the PR description here for the convenience of future code archaeologists.

@mathemancer mathemancer added this pull request to the merge queue Mar 23, 2023
@mathemancer mathemancer merged commit f62dd21 into develop Mar 23, 2023
@mathemancer mathemancer deleted the sql_prototyping branch March 23, 2023 06:43
@mathemancer mathemancer mentioned this pull request Jun 19, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: revision A PR awaiting follow-up work from its author after review
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants