]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
📝 Update release notes
authorSebastián Ramírez <tiangolo@gmail.com>
Tue, 28 Dec 2021 11:26:52 +0000 (12:26 +0100)
committerSebastián Ramírez <tiangolo@gmail.com>
Tue, 28 Dec 2021 11:26:52 +0000 (12:26 +0100)
docs/release-notes.md

index f2a66c242f43432d344d2631af4591f09636d34c..4008a218fe800a1afa62c0102014138d8428acc3 100644 (file)
@@ -2,7 +2,68 @@
 
 ## Latest Changes
 
-* ✨ Document indexes and make them opt-in. PR [#205](https://github.com/tiangolo/sqlmodel/pull/205) by [@tiangolo](https://github.com/tiangolo).
+### Breaking Changes
+
+**SQLModel** no longer creates indexes by default for every column, indexes are now opt-in. You can read more about it in PR [#205](https://github.com/tiangolo/sqlmodel/pull/205).
+
+Before this change, if you had a model like this:
+
+```Python
+from typing import Optional
+
+from sqlmodel import Field, SQLModel
+
+
+class Hero(SQLModel, table=True):
+    id: Optional[int] = Field(default=None, primary_key=True)
+    name: str
+    secret_name: str
+    age: Optional[int] = None
+```
+
+...when creating the tables, SQLModel version `0.0.5` and below, would also create an index for `name`, one for `secret_name`, and one for `age` (`id` is the primary key, so it doesn't need an additional index).
+
+If you depended on having an index for each one of those columns, now you can (and would have to) define them explicitly:
+
+```Python
+class Hero(SQLModel, table=True):
+    id: Optional[int] = Field(default=None, primary_key=True)
+    name: str = Field(index=True)
+    secret_name: str = Field(index=True)
+    age: Optional[int] = Field(default=None, index=True)
+```
+
+There's a high chance you don't need indexes for all the columns. For example, you might only need indexes for `name` and `age`, but not for `secret_name`. In that case, you could define the model as:
+
+```Python
+class Hero(SQLModel, table=True):
+    id: Optional[int] = Field(default=None, primary_key=True)
+    name: str = Field(index=True)
+    secret_name: str
+    age: Optional[int] = Field(default=None, index=True)
+```
+
+If you already created your database tables with SQLModel using versions `0.0.5` or below, it would have also created those indexes in the database. In that case, you might want to manually drop (remove) some of those indexes, if they are unnecessary, to avoid the extra cost in performance and space.
+
+Depending on the database you are using, there will be a different way to find the available indexes.
+
+For example, let's say you no longer need the index for `secret_name`. You could check the current indexes in the database and find the one for `secret_name`, it could be named `ix_hero_secret_name`. Then you can remove it with SQL:
+
+```SQL
+DROP INDEX ix_hero_secret_name
+```
+
+or
+
+```SQL
+DROP INDEX ix_hero_secret_name ON hero;
+```
+
+Here's the new, extensive documentation explaining indexes and how to use them: [Indexes - Optimize Queries](https://sqlmodel.tiangolo.com/tutorial/indexes/).
+
+### Docs
+
+* ✨ Document indexes and make them opt-in. Here's the new documentation: [Indexes - Optimize Queries](https://sqlmodel.tiangolo.com/tutorial/indexes/). This is the same change described above in **Breaking Changes**. PR [#205](https://github.com/tiangolo/sqlmodel/pull/205) by [@tiangolo](https://github.com/tiangolo).
 * ✏ Fix typo in FastAPI tutorial. PR [#192](https://github.com/tiangolo/sqlmodel/pull/192) by [@yaquelinehoyos](https://github.com/yaquelinehoyos).
 * 📝 Add links to the license file. PR [#29](https://github.com/tiangolo/sqlmodel/pull/29) by [@sobolevn](https://github.com/sobolevn).
 * ✏ Fix typos in docs titles. PR [#28](https://github.com/tiangolo/sqlmodel/pull/28) by [@Batalex](https://github.com/Batalex).