You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR makes a few changes, all to support datetime fields better.
## Store datetime fields as NUMERIC data in Redis
Previously, we stored datetimes as TAGs (why, I don't know). This means any query you might think would work with dates would not actually work. Now, we convert datetime fields on models to and from NUMERIC fields in Redis, storing them as UNIX timestamps. This means we can support rich datetime queries by converting the input to a timestamp and comparing it against the stored timestamp.
## New data migrations system
Introduces a data migrations system and CLI command (`om migrate-data`). The first built-in data migration will migrate datetime fields indexed as TAG data to NUMERIC data. **Important:** You must run this migration in order to use this version of Redis OM with datetime fields, as the models will now expect to get NUMERIC data for datetimes fields.
## New top-level `om` CLI command
Moves OM CLI commands into a new top-level `om` command while preserving backwards compatibility for the old `migrate` command. This makes room for normal migration and now data migration commands.
## Expanded schema migrations system
To match the new `om migrate-data` sub-commands, such as `run` and `create`, we expand the schema migrations system to support these features through file-based migrations. This introduces the possibility to roll back migrations, as well as practical concerns like deploying migrations to different environments and checking whether or not they have applied.
Copy file name to clipboardExpand all lines: README.md
+12-14Lines changed: 12 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -216,7 +216,7 @@ Next, we'll show you the **rich query expressions** and **embedded models** Redi
216
216
217
217
Redis OM comes with a rich query language that allows you to query Redis with Python expressions.
218
218
219
-
To show how this works, we'll make a small change to the `Customer` model we defined earlier. We'll add `Field(index=True)` to tell Redis OM that we want to index the `last_name` and `age` fields:
219
+
To show how this works, we'll make a small change to the `Customer` model we defined earlier. We'll add `index=True` to the model class to tell Redis OM that we want to index all fields in the model:
220
220
221
221
```python
222
222
import datetime
@@ -225,18 +225,17 @@ from typing import Optional
225
225
from pydantic import EmailStr
226
226
227
227
from redis_om import (
228
-
Field,
229
228
HashModel,
230
229
Migrator
231
230
)
232
231
233
232
234
-
classCustomer(HashModel):
233
+
classCustomer(HashModel, index=True):
235
234
first_name: str
236
-
last_name: str= Field(index=True)
235
+
last_name: str
237
236
email: EmailStr
238
237
join_date: datetime.date
239
-
age: int= Field(index=True)
238
+
age: int
240
239
bio: Optional[str] =None
241
240
242
241
@@ -294,14 +293,13 @@ class Address(EmbeddedJsonModel):
0 commit comments