-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
sqlite rowid support #2149
Comments
This is because SQLite doesn't expose this to us. Tables can be created without rowids, and we have no way of knowing whether that was the case or not. You should explicitly specify a primary key if you'd like to use Diesel to access that table, otherwise you can add it to the list of tables to ignore. |
It would be nice to reopen this. To figure out which tables are rowid table one can use something like this: SELECT name, NOT EXISTS(SELECT 1 FROM pragma_index_xinfo(x.name)) AS 'hasRowid'
FROM sqlite_schema AS x
WHERE type='table'
ORDER BY name; With this information, diesel could implicitly add a primary key to the schema if there is none available explicitly. |
@longsleep Can you explain how that would be different to what's implemented in #3680? |
Oh great thanks for pointing to that MR. I did not check the "unreleased" changes. I just tested the current "master" and diesel print-schema generates an invalid schema as it only picks up rowid half the way.
generates:
Which is missing the I will investigate further and open a dedicated ticket for this should be conclusion be that some functionality is still missing for implicit rowid support. |
It turned out that the test for this When adding it:
This is the same result I get when trying with my table from above and the conclusion is that the feature implemented in #3680 is incomplete or at least partly non-functional. |
Thanks for trying that out. That likely means that I will remove the relevant code in the next few days. If there is interest in having this feature I'm open to accepting another PR for this. |
Whenever sqlite uses an implicit rowid it also need to be added as column to the corresponding schema. This change fixes the implicit primary key generator added in diesel-rs#3680 which was never tested as the test added in this pull request never actually is run. This change enables the test and enhances the schema printer to generate the missing column if the primary key is an implicit rowid column. Related: diesel-rs#2149
Whenever sqlite uses an implicit rowid it also need to be added as column to the corresponding schema. This change fixes the implicit primary key generator added in diesel-rs#3680 which was never tested as the test added in this pull request never actually is run. This change enables the test and enhances the schema printer to generate the missing column if the primary key is an implicit rowid column. Related: diesel-rs#2149
Whenever sqlite uses an implicit rowid it also need to be added as column to the corresponding schema. This change fixes the implicit primary key generator added in diesel-rs#3680 which was never tested as the test added in this pull request never actually is run. This change enables the test and enhances the schema printer to generate the missing column if the primary key is an implicit rowid column. Related: diesel-rs#2149
Whenever sqlite uses an implicit rowid it also need to be added as column to the corresponding schema. This change fixes the implicit primary key generator added in diesel-rs#3680 which was never tested as the test added in this pull request never actually is run. This change enables the test and enhances the schema printer to generate the missing column if the primary key is an implicit rowid column. Related: diesel-rs#2149
Whenever sqlite uses an implicit rowid it also need to be added as column to the corresponding schema. This change fixes the implicit primary key generator added in diesel-rs#3680 which was never tested as the test added in this pull request never actually is run. This change enables the test and enhances the schema printer to generate the missing column if the primary key is an implicit rowid column. Related: diesel-rs#2149
Setup
Versions
Feature Flags
Problem Description
diesel doesn't know that sqlite generates a PK for each table called rowid. I don't need to specify a PK.
What are you trying to accomplish?
create a table
What is the expected output?
migrations are ok
What is the actual output?
Diesel only supports tables with primary keys. Table poster has no primary key
Are you seeing any additional errors?
no
Steps to reproduce
migration:
running
diesel migration run
causes the error.Checklist
closed if this is not the case)
The text was updated successfully, but these errors were encountered: