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

Enable reflection on table type 'SYSTEM VERSIONED' #3571

Closed
wants to merge 1 commit into from

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Mar 28, 2023

Fixes #3570

There are no side effects to this PR since system versioned tables appear identical to base tables for any frontend.

I'm unsure if a test is possible since it requires a mariadb backend - but if it is possible, let me know.

@tgross35
Copy link
Contributor Author

I have confirmed locally that this works with the following:

CREATE TABLE foo (
    x serial,
    primary key (x)
) WITH SYSTEM VERSIONING;
$ target/debug/diesel print-schema --database-url="mysql://root:[email protected]:4000/db"

// @generated automatically by Diesel CLI.

diesel::table! {
    foo (x, row_end) {
        x -> Unsigned<Bigint>,
    }
}

Without this patch, no output is generated

@tgross35
Copy link
Contributor Author

tgross35 commented Mar 28, 2023

There is an interesting caveat with this: the hidden row_end column appears as part of the PK. This is accurate to the table, because adding SV does implicitely add the end row to the PK and the default row name is row_end. However, this of course does not compile in Rust because that row isn't reflected.

diesel::table! {
    tab_foo (x, row_end) {
        x -> Unsigned<Bigint>,
    }
}

I still think this simple PR is good to merge as-is because it at least means the tables are seen, and can just be tweaked with s/, row_end\)/)/g (major step up from doing all table definitions by hand). Long term, there could be a better solution for SV, but that would be blocked on MariaDB support

@weiznich weiznich requested a review from a team March 29, 2023 12:22
@weiznich
Copy link
Member

I still think this simple PR is good to merge as-is because it at least means the tables are seen, and can just be tweaked with s/, row_end)/)/g (major step up from doing all table definitions by hand). Long term, there could be a better solution for SV, but that would be blocked on MariaDB support

I would like to disagree here: The code generated by print-schema is expected to compile without modifications. So that needs to be fixed.

@tgross35
Copy link
Contributor Author

That makes sense too. I think that all that is needed is to ignore the last PK from the group for that table type, so I’ll take a look at how to do that.

I would expect there to be some edge cases but I think that simple change would at least handle the majority. And make it so the joinable macros also get generated, I recently realized they are missing.

@tgross35
Copy link
Contributor Author

Unfortunately I have not had a time to get back to this, anyone is welcome to pick this up if they are willing to

@tgross35 tgross35 closed this Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WITH SYSTEM VERSIONING (mariaDB) causes print-schema to fail
2 participants