anderson-ufrj commited on
Commit
502eaf3
·
1 Parent(s): f3bb97d

feat(database): add simple session creation utility

Browse files

Utility script for creating investigation database session:
- Basic asyncpg connection setup
- Session management helpers
- Used for testing and development
- Simplified database interaction patterns

Files changed (1) hide show
  1. create_tables.py +31 -0
create_tables.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Create database tables.
4
+ """
5
+
6
+ import asyncio
7
+ import os
8
+ from dotenv import load_dotenv
9
+ from sqlalchemy.ext.asyncio import create_async_engine
10
+ from src.models.base import Base
11
+ from src.models.investigation import Investigation
12
+
13
+ load_dotenv()
14
+
15
+ DATABASE_URL = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///./cidadao_ai.db")
16
+
17
+ async def create_tables():
18
+ """Create all tables in the database."""
19
+ print(f"🔧 Creating tables in: {DATABASE_URL}")
20
+
21
+ engine = create_async_engine(DATABASE_URL, echo=True)
22
+
23
+ async with engine.begin() as conn:
24
+ # Create all tables
25
+ await conn.run_sync(Base.metadata.create_all)
26
+
27
+ await engine.dispose()
28
+ print("\n✅ Tables created successfully!")
29
+
30
+ if __name__ == "__main__":
31
+ asyncio.run(create_tables())