Initialize database schema.
()
| 401 | |
| 402 | |
| 403 | def init_database(): |
| 404 | """Initialize database schema.""" |
| 405 | conn = get_db_connection() |
| 406 | previous_autocommit = None |
| 407 | if using_postgres(): |
| 408 | previous_autocommit = conn.autocommit |
| 409 | conn.autocommit = True |
| 410 | cursor = conn.cursor() |
| 411 | |
| 412 | # Agents table |
| 413 | cursor.execute(""" |
| 414 | CREATE TABLE IF NOT EXISTS agents ( |
| 415 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 416 | name TEXT UNIQUE NOT NULL, |
| 417 | email TEXT, |
| 418 | token TEXT, |
| 419 | token_expires_at TEXT, |
| 420 | password_hash TEXT, |
| 421 | wallet_address TEXT, |
| 422 | role TEXT DEFAULT 'agent', |
| 423 | identity_status TEXT DEFAULT 'normal', |
| 424 | points INTEGER DEFAULT 0, |
| 425 | cash REAL DEFAULT 100000.0, |
| 426 | deposited REAL DEFAULT 0.0, |
| 427 | reputation_score INTEGER DEFAULT 0, |
| 428 | created_at TEXT DEFAULT (datetime('now')), |
| 429 | updated_at TEXT DEFAULT (datetime('now')) |
| 430 | ) |
| 431 | """) |
| 432 | |
| 433 | cursor.execute(""" |
| 434 | CREATE TABLE IF NOT EXISTS agent_leaderboard_exclusions ( |
| 435 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 436 | agent_id INTEGER NOT NULL UNIQUE, |
| 437 | reason TEXT NOT NULL, |
| 438 | details_json TEXT, |
| 439 | active INTEGER DEFAULT 1, |
| 440 | created_at TEXT DEFAULT (datetime('now')), |
| 441 | updated_at TEXT DEFAULT (datetime('now')), |
| 442 | FOREIGN KEY (agent_id) REFERENCES agents(id) |
| 443 | ) |
| 444 | """) |
| 445 | |
| 446 | # Agent messages table |
| 447 | cursor.execute(""" |
| 448 | CREATE TABLE IF NOT EXISTS agent_messages ( |
| 449 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 450 | agent_id INTEGER NOT NULL, |
| 451 | type TEXT NOT NULL, |
| 452 | content TEXT, |
| 453 | data TEXT, |
| 454 | read INTEGER DEFAULT 0, |
| 455 | created_at TEXT DEFAULT (datetime('now')), |
| 456 | FOREIGN KEY (agent_id) REFERENCES agents(id) |
| 457 | ) |
| 458 | """) |
| 459 | |
| 460 | # Agent tasks table |
no test coverage detected