I'm currently rewriting the piccolo agsi new setup for FastAPI. Do you still need the create_tables() or create_db_tables() function to run, as well as the create_admin function?
I've changed a few things:
app = FastAPI(
routes=[
Route("/", HomeEndpoint),
Mount(
"/admin/",
create_admin(
tables=APP_CONFIG.table_classes,
# Required when running under HTTPS:
# allowed_hosts=['my_site.com']
),
),
Mount("/static/", StaticFiles(directory="static")),
],
lifespan=lifespan,
)
Becomes (using the FastAPI packages rather than Starlette)
app = FastAPI()
admin = create_admin(tables=APP_CONFIG.table_classes) #! (3)
app.mount("/admin", admin) # (2)
app.mount("/static", StaticFiles(directory="static"), name="static")
And piccolo_app.py
from piccolo.conf.apps import AppConfig
from tasks.tables import Task
APP_CONFIG = AppConfig(
app_name="tasks",
table_classes=[Task],
migrations_folder_path=None,
migration_dependencies=[],
commands=[]
)
I'm trying to remove anything I feel is unnecessary or using Python "magic" so perhaps I've inadvertently broken something. Running the below code as well as create_admin seems to work, but the piccolo agsi new FastAPI example seems to have no create tables function that I can see.
@asynccontextmanager
async def lifespan(app: FastAPI):
await create_db_tables(Task, if_not_exists=True)
yield
I've changed a few things:
Becomes (using the FastAPI packages rather than Starlette)
And
piccolo_app.pyI'm trying to remove anything I feel is unnecessary or using Python "magic" so perhaps I've inadvertently broken something. Running the below code as well as
create_adminseems to work, but thepiccolo agsi newFastAPI example seems to have no create tables function that I can see.