NPC shop implimented

This commit is contained in:
2025-11-29 01:16:46 -06:00
parent 32af625d14
commit 8bd494a52f
17 changed files with 4265 additions and 17 deletions

View File

@@ -124,6 +124,15 @@ class DatabaseInitService:
logger.error("Failed to initialize combat_rounds table", error=str(e))
results['combat_rounds'] = False
# Initialize transactions table
try:
self.init_transactions_table()
results['transactions'] = True
logger.info("Transactions table initialized successfully")
except Exception as e:
logger.error("Failed to initialize transactions table", error=str(e))
results['transactions'] = False
success_count = sum(1 for v in results.values() if v)
total_count = len(results)
@@ -1084,6 +1093,174 @@ class DatabaseInitService:
code=e.code)
raise
def init_transactions_table(self) -> bool:
"""
Initialize the transactions table for tracking gold transactions.
Table schema:
- transaction_id (string, required): Unique transaction identifier (UUID)
- transaction_type (string, required): Type (shop_purchase, shop_sale, quest_reward, etc.)
- character_id (string, required): Character involved in transaction
- session_id (string, optional): Game session where transaction occurred
- amount (integer, required): Gold amount (negative=expense, positive=income)
- description (string, required): Human-readable description
- timestamp (string, required): ISO timestamp when transaction occurred
- metadata (string, optional): JSON metadata for additional context
Indexes:
- idx_character_id: Character-based lookups
- idx_session_id: Session-based lookups (for cleanup on session delete)
- idx_character_id_timestamp: Character transaction history
- idx_transaction_type: Filter by type
- idx_timestamp: Date range queries
Returns:
True if successful
Raises:
AppwriteException: If table creation fails
"""
table_id = 'transactions'
logger.info("Initializing transactions table", table_id=table_id)
try:
# Check if table already exists
try:
self.tables_db.get_table(
database_id=self.database_id,
table_id=table_id
)
logger.info("Transactions table already exists", table_id=table_id)
return True
except AppwriteException as e:
if e.code != 404:
raise
logger.info("Transactions table does not exist, creating...")
# Create table
logger.info("Creating transactions table")
table = self.tables_db.create_table(
database_id=self.database_id,
table_id=table_id,
name='Transactions'
)
logger.info("Transactions table created", table_id=table['$id'])
# Create columns
self._create_column(
table_id=table_id,
column_id='transaction_id',
column_type='string',
size=36, # UUID length
required=True
)
self._create_column(
table_id=table_id,
column_id='transaction_type',
column_type='string',
size=50, # TransactionType enum values
required=True
)
self._create_column(
table_id=table_id,
column_id='character_id',
column_type='string',
size=100,
required=True
)
self._create_column(
table_id=table_id,
column_id='session_id',
column_type='string',
size=100,
required=False # Optional - some transactions may not have a session
)
self._create_column(
table_id=table_id,
column_id='amount',
column_type='integer',
required=True
)
self._create_column(
table_id=table_id,
column_id='description',
column_type='string',
size=500,
required=True
)
self._create_column(
table_id=table_id,
column_id='timestamp',
column_type='string',
size=50, # ISO timestamp format
required=True
)
self._create_column(
table_id=table_id,
column_id='metadata',
column_type='string',
size=2000, # JSON metadata
required=False
)
# Wait for columns to fully propagate
logger.info("Waiting for columns to propagate before creating indexes...")
time.sleep(2)
# Create indexes for efficient querying
self._create_index(
table_id=table_id,
index_id='idx_character_id',
index_type='key',
attributes=['character_id']
)
self._create_index(
table_id=table_id,
index_id='idx_session_id',
index_type='key',
attributes=['session_id']
)
self._create_index(
table_id=table_id,
index_id='idx_character_id_timestamp',
index_type='key',
attributes=['character_id', 'timestamp']
)
self._create_index(
table_id=table_id,
index_id='idx_transaction_type',
index_type='key',
attributes=['transaction_type']
)
self._create_index(
table_id=table_id,
index_id='idx_timestamp',
index_type='key',
attributes=['timestamp']
)
logger.info("Transactions table initialized successfully", table_id=table_id)
return True
except AppwriteException as e:
logger.error("Failed to initialize transactions table",
table_id=table_id,
error=str(e),
code=e.code)
raise
def _create_column(
self,
table_id: str,