Skip to content

Commit 9203df6

Browse files
committed
📝 Update release notes
1 parent d6d77a9 commit 9203df6

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

docs/release-notes.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,68 @@
22

33
## Latest Changes
44

5-
* ✨ Document indexes and make them opt-in. PR [#205](https://github.com/tiangolo/sqlmodel/pull/205) by [@tiangolo](https://github.com/tiangolo).
5+
### Breaking Changes
6+
7+
**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).
8+
9+
Before this change, if you had a model like this:
10+
11+
```Python
12+
from typing import Optional
13+
14+
from sqlmodel import Field, SQLModel
15+
16+
17+
class Hero(SQLModel, table=True):
18+
id: Optional[int] = Field(default=None, primary_key=True)
19+
name: str
20+
secret_name: str
21+
age: Optional[int] = None
22+
```
23+
24+
...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).
25+
26+
If you depended on having an index for each one of those columns, now you can (and would have to) define them explicitly:
27+
28+
```Python
29+
class Hero(SQLModel, table=True):
30+
id: Optional[int] = Field(default=None, primary_key=True)
31+
name: str = Field(index=True)
32+
secret_name: str = Field(index=True)
33+
age: Optional[int] = Field(default=None, index=True)
34+
```
35+
36+
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:
37+
38+
```Python
39+
class Hero(SQLModel, table=True):
40+
id: Optional[int] = Field(default=None, primary_key=True)
41+
name: str = Field(index=True)
42+
secret_name: str
43+
age: Optional[int] = Field(default=None, index=True)
44+
```
45+
46+
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.
47+
48+
Depending on the database you are using, there will be a different way to find the available indexes.
49+
50+
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:
51+
52+
```SQL
53+
DROP INDEX ix_hero_secret_name
54+
```
55+
56+
or
57+
58+
```SQL
59+
DROP INDEX ix_hero_secret_name ON hero;
60+
```
61+
62+
Here's the new, extensive documentation explaining indexes and how to use them: [Indexes - Optimize Queries](https://sqlmodel.tiangolo.com/tutorial/indexes/).
63+
64+
### Docs
65+
66+
* ✨ 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).
667
* ✏ Fix typo in FastAPI tutorial. PR [#192](https://github.com/tiangolo/sqlmodel/pull/192) by [@yaquelinehoyos](https://github.com/yaquelinehoyos).
768
* 📝 Add links to the license file. PR [#29](https://github.com/tiangolo/sqlmodel/pull/29) by [@sobolevn](https://github.com/sobolevn).
869
* ✏ Fix typos in docs titles. PR [#28](https://github.com/tiangolo/sqlmodel/pull/28) by [@Batalex](https://github.com/Batalex).

0 commit comments

Comments
 (0)