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

Sqlite: Make AUTOINCREMENT accurate #22245

Merged
1 commit merged into from
Aug 26, 2020
Merged

Sqlite: Make AUTOINCREMENT accurate #22245

1 commit merged into from
Aug 26, 2020

Conversation

smitpatel
Copy link
Member

Turns out SqlServer:Identity is also not first class. It is computed based on ValueGenerationStrategy and ValueGenerated flag.
Aligned Sqlite to do the same to compute AutoIncrement only when applicable

Resolves #10228

@smitpatel
Copy link
Member Author

@Pilchie for RC1 approval

@Pilchie
Copy link
Member

Pilchie commented Aug 26, 2020

Approved for RC1 (pending CI completion)

Turns out SqlServer:Identity is also not first class. It is computed based on ValueGenerationStrategy and ValueGenerated flag.
Aligned Sqlite to do the same to compute AutoIncrement only when applicable

Resolves #10228
@ghost
Copy link

ghost commented Aug 26, 2020

Hello @smitpatel!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@bricelam
Copy link
Contributor

bricelam commented Aug 26, 2020

This is good, but I want to do more for #10228. In SqlServer, we have SqlServerValueGenerationStrategy.Identity and None you can use to turn on and off IDENTITY in the model. You currently can't turn off AUTOINCREMENT in the same way.

@smitpatel
Copy link
Member Author

smitpatel commented Aug 26, 2020

I can add SqliteValueGenerationStrategy.AutoIncrement/None
Should I go that route?

Also UseAutoIncrement() API.

@smitpatel
Copy link
Member Author

Side question, can you set a column as auto increment which is not int PK?

@bricelam
Copy link
Contributor

Side question, can you set a column as auto increment which is not int PK?

No, it must be a non-composite integer primary key.

@smitpatel
Copy link
Member Author

So should there be an API, UseAutoIncrement on key (which verifies that it is non-composite, int PK only when setting) and use that info to generate the column syntax?

@bricelam
Copy link
Contributor

bricelam commented Aug 26, 2020

There are several ways the ValueGenerated.OnAdd could be satisifed on SQLite:

  • INTEGER PRIMARY KEY (rowid alias)
  • INTEGER PRIMARY KEY AUTOINCREMENT (rowid alias without value reuse)
  • DEFAULT
  • TRIGGER...AFTER UPDATE
  • Virtual table modules
  • Client-side

@bricelam
Copy link
Contributor

  • Fluent API (and an annotation) that also sets ValueGeneratedOnAdd
modelBuilder.Entity<MyEntity>().Property(e => e.Id).UseAutoincrement();
modelBuilder.Entity<MyOtherEntity>().Property(e => e.Id).UseAutoincrement(false);
  • A convention to add it by default to non-composite integer primary key columns

  • Validation to make sure you don't set it to true on a non-integer or composite primary key, or non-primary key property

@bricelam
Copy link
Contributor

At least that matches SQL Server. We might need a design meeting to discuss whether it should be on the property or primary key

@smitpatel
Copy link
Member Author

Needs-design? out of 5.0? Merge this (or leave this) and keep issue open to discuss design for next release?

@bricelam
Copy link
Contributor

Merge this--it fixes a bug. Keep the issue open to iterate on later. I'll copy my notes into the issue.

Copy link
Contributor

@bricelam bricelam left a comment

Choose a reason for hiding this comment

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

I don't think there was ever a functional bug here--just some extra clutter in the Migration. Migrations SQL generation wouldn't try to use the annotation unless it was on an integer primary key property

@ghost ghost merged commit 2fd5874 into release/5.0 Aug 26, 2020
@ghost ghost deleted the smit/autoincrement branch August 26, 2020 20:51
This pull request was closed.
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.

SQLite: Make AUTOINCREMENT more first-class
3 participants