Skip to content

Add accounting, AI, and core catalog database schema#98

Merged
Santiago1010 merged 7 commits into
developfrom
feature/migrations
Apr 13, 2026
Merged

Add accounting, AI, and core catalog database schema#98
Santiago1010 merged 7 commits into
developfrom
feature/migrations

Conversation

@Santiago1010
Copy link
Copy Markdown
Owner

📋 Summary

This PR introduces comprehensive database migrations for the accounting module, AI agent infrastructure, and unified core catalog. It establishes the foundational schema for chart of accounts, journal entries, fiscal periods, counterparties, documents, AI providers/models/agents/sessions/usage tracking, items with attributes/variants/categories, addresses, branches, and legal entities. Additionally, it standardizes collation to utf8mb4_general_ci on two existing tables.

🎯 Type of Change

  • New feature (adds functionality)
  • Code refactoring (no functional changes)
  • Bug fix (non-breaking change)
  • Breaking change (breaks existing functionality)
  • Documentation update
  • Performance improvement
  • Test coverage improvement
  • Build system changes
  • CI/CD changes

🔍 What Changed

Added

  • Accounting module migrations:

    • acct_account_types – defines account categories (asset, liability, equity, revenue, expense) with normal balance and financial statement classification.
    • acct_accounts – chart of accounts with hierarchical parent-child relationships, posting controls, and system protection.
    • acct_counterparties – third parties involved in transactions (customers, suppliers, employees, banks, etc.).
    • acct_documents – business documents (invoices, receipts, payments) linking to journal entries and counterparties.
    • acct_document_applications – links payments to documents for settlement tracking.
    • acct_document_sequences – configurable numbering sequences for document codes.
    • acct_document_lines – line items within documents with account mapping and inventory references.
    • acct_document_types – defines document behavior (affects accounting, requires counterparty, auto-post).
    • acct_fiscal_periods – fiscal years, quarters, months with closing status and hierarchy.
    • acct_journal_entries – core accounting transactions with status (draft/posted/reversed), source, and fiscal period linkage.
    • acct_journal_entry_lines – debit/credit lines with multi-currency support and counterparty association.
    • acct_settings – versioned accounting configuration (base currency, FX gain/loss accounts, rounding precision).
  • AI module migrations:

    • ai_providers – catalog of AI service providers (Anthropic, OpenAI, Google, etc.).
    • ai_models – specific models per provider with capabilities (tools, vision, JSON mode) and cost tracking.
    • ai_agents – AI agent identities with type (assistant/task/pipeline) and account scoping.
    • ai_agent_versions – versioned snapshots of agent configuration (model, system prompt, hyperparameters).
    • ai_sessions – execution context for agent interactions, tracking token usage and cost.
    • ai_messages – (implied via foreign key references in tool calls and usage logs).
    • ai_tool_calls – records every tool invocation made by an agent with arguments and results.
    • ai_usage_logs – immutable ledger of every AI provider API call for cost analysis and audit.
  • Core module migrations:

    • core_addresses – reusable physical addresses for accounts, counterparties, orders, and billing.
    • core_items – unified catalog for physical goods, digital products, and services.
    • core_item_variants – sellable variants of items (e.g., size/color combinations).
    • core_item_attributes – attribute definitions with data types and variant-axis flags.
    • core_item_attribute_options – predefined selectable values for attributes.
    • core_item_attribute_values – EAV storage for item attribute values.
    • core_item_categories – hierarchical category tree for item classification.
    • core_legal_entities – legal entities for multi-entity operations.
    • core_branches – operational branches linked to legal entities.

Changed

  • migrations/20260125165529-create-credentials-table.js – collation changed from utf8mb4_0900_ai_ci to utf8mb4_general_ci.
  • migrations/20260125170536-create-otp-codes-table.js – collation changed from utf8mb4_0900_ai_ci to utf8mb4_general_ci.

Fixed

  • None.

Removed

  • None.

🧪 Testing

  • Manual testing completed
  • Unit tests added/updated
  • Integration tests added/updated
  • All tests passing

Test Instructions:

  1. Run migrations against a clean database.
  2. Verify all tables are created with correct schemas, indexes, and foreign key constraints.
  3. Confirm collation changes on credentials and otp_codes tables are applied without data loss.
  4. Check that down migrations successfully drop tables in reverse order without constraint errors.

🔗 Related Issues

  • Closes # (Add issue number if applicable)
  • Related to accounting-module
  • Related to ai-infrastructure
  • Related to core-catalog

📝 Additional Notes

  • The accounting schema follows double-entry principles with soft deletes and audit timestamps.
  • AI module supports multi-tenant agent configurations and detailed usage cost tracking.
  • Core catalog unifies items across inventory, assets, and services with extensible attributes.
  • Collation standardization improves compatibility and reduces charset-related edge cases.

✅ Checklist

  • Follows project style guidelines
  • Self-reviewed my code
  • Commented complex logic
  • Updated documentation
  • No new warnings
  • Existing and new tests pass locally

- Create acct_account_types, acct_accounts, acct_counterparties tables
- Add acct_documents, acct_document_lines, acct_document_sequences
- Implement acct_document_types, acct_document_applications
- Add acct_fiscal_periods and acct_journal_entries with foreign keys
… tables

- Create acct_journal_entry_lines table with debit/credit and currency handling
- Add acct_settings for versioned accounting configuration (base currency, fx accounts)
- Implement AI module: agents, models, providers, versions, sessions, tool calls
- Add ai_usage_logs for immutable API call tracking and cost calculation
…nagement

- Create core_addresses table with geolocation and ownership links
- Add core_items unified catalog with physical/digital/service classification
- Implement core_item_variants and variant attribute values
- Add core_branches and core_legal_entities for multi-entity structure
- Create core_item_attributes, options, values, and category relationships
- Add core_item_categories hierarchy and items-categories mapping
- Create crm_accounts, crm_contacts, crm_leads, crm_opportunities
- Add foreign keys to usr_accounts, usr_users, acct_counterparties
- Unify collation to utf8mb4_general_ci across existing migrations
- Create hr_employees master record with account and counterparty links
- Add hr_contracts, hr_departments, hr_job_levels, hr_positions
- Implement hr_employee_assignments for organizational history tracking
- Add hr_compensation_items, hr_employee_benefits, hr_employee_loans
- Create hr_employee_identifications, hr_employee_leaves
- Add competency catalog: hr_competency_categories, hr_competencies, hr_competency_levels
- Implement performance review cycles, rating scales, cycle employees, review assignments
- Add hr_employee_objectives and progress tracking
- Add hr_performance_review_templates, template_sections, template_questions
- Create hr_performance_reviews, review_responses, review_results and details
- Add hr_positions, hr_salary_history, hr_terminations and termination_settlements
- Normalize collation to utf8mb4_general_ci across existing hr tables
@Santiago1010 Santiago1010 self-assigned this Apr 13, 2026
@Santiago1010 Santiago1010 added documentation Improvements or additions to documentation enhancement New feature or request automation Code automation and/or deployment tasks. labels Apr 13, 2026
  Auto-generated by GitHub Actions workflow
  PR: #98
  Workflow: Auto Version & Changelog
  Run ID: 24351672797
@github-actions
Copy link
Copy Markdown

🚀 Auto-versioning complete!

📦 New version: 1.26.0
📋 CHANGELOG.md and package.json updated
👤 Author: Santiago1010
✅ Approved by: DiegoAlejandroNino

This PR is ready for merging.

@Santiago1010 Santiago1010 merged commit c0d5396 into develop Apr 13, 2026
@Santiago1010 Santiago1010 deleted the feature/migrations branch April 13, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Code automation and/or deployment tasks. documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants