Document indexes and make them opt-in (#205)

This commit is contained in:
Sebastián Ramírez
2021-12-28 11:48:03 +01:00
committed by GitHub
parent 3d7b74746c
commit 155c6178cd
91 changed files with 1755 additions and 142 deletions

View File

@@ -1,4 +1,6 @@
from fastapi.testclient import TestClient
from sqlalchemy import inspect
from sqlalchemy.engine.reflection import Inspector
from sqlmodel import create_engine
from sqlmodel.pool import StaticPool
@@ -166,3 +168,16 @@ def test_tutorial(clear_sqlmodel):
assert response.status_code == 200, response.text
assert data == openapi_schema
# Test inherited indexes
insp: Inspector = inspect(mod.engine)
indexes = insp.get_indexes(str(mod.Hero.__tablename__))
expected_indexes = [
{"name": "ix_hero_name", "column_names": ["name"], "unique": 0},
{"name": "ix_hero_age", "column_names": ["age"], "unique": 0},
]
for index in expected_indexes:
assert index in indexes, "This expected index should be in the indexes in DB"
# Now that this index was checked, remove it from the list of indexes
indexes.pop(indexes.index(index))
assert len(indexes) == 0, "The database should only have the expected indexes"

View File

@@ -1,4 +1,6 @@
from fastapi.testclient import TestClient
from sqlalchemy import inspect
from sqlalchemy.engine.reflection import Inspector
from sqlmodel import create_engine
from sqlmodel.pool import StaticPool
@@ -166,3 +168,16 @@ def test_tutorial(clear_sqlmodel):
assert response.status_code == 200, response.text
assert data == openapi_schema
# Test inherited indexes
insp: Inspector = inspect(mod.engine)
indexes = insp.get_indexes(str(mod.Hero.__tablename__))
expected_indexes = [
{"name": "ix_hero_age", "column_names": ["age"], "unique": 0},
{"name": "ix_hero_name", "column_names": ["name"], "unique": 0},
]
for index in expected_indexes:
assert index in indexes, "This expected index should be in the indexes in DB"
# Now that this index was checked, remove it from the list of indexes
indexes.pop(indexes.index(index))
assert len(indexes) == 0, "The database should only have the expected indexes"