Skip to content

Conversation

@gustaavik
Copy link
Member

This pull request introduces significant changes to the database configuration, development environment setup, and codebase structure. The most notable updates include transitioning from PostgreSQL to SQLite for local development, removing migration-related functionality, and simplifying database initialization across the application. Additionally, PayPal support has been removed, and new development commands have been added to the Makefile.

Database Configuration and Environment Updates:

  • .env.example: Switched local development database configuration from PostgreSQL to SQLite, added debug mode, and clarified production setup instructions. Removed MOBILEPAY_MARKET setting. [1] [2]
  • config/config.go: Added Driver and Debug fields to DatabaseConfig, updated LoadConfig to support SQLite, and removed PayPal-specific configuration and logic. [1] [2] [3]

Development Workflow Enhancements:

  • Makefile: Added SQLite-specific commands (dev-sqlite, run-docker-sqlite, etc.), removed migration-related commands (migrate-up, migrate-down, etc.), and updated dev-setup to focus on seeding data for PostgreSQL. [1] [2] [3] [4]

Codebase Simplification:

  • Removed cmd/migrate/main.go and cmd/recover/main.go, eliminating migration and checkout recovery functionality. [1] [2]
  • Updated database initialization logic across cmd/api/main.go and cmd/expire-checkouts/main.go to use a unified InitDB method. [1] [2]

Dockerfile Adjustments:

  • Dockerfile: Removed migration-related binaries and files (commercify-migrate and /app/migrations) from the build and final image. [1] [2]

Miscellaneous:

  • Added cmd/test-db/main.go for testing database connections and basic operations.

gustaavik added 30 commits June 29, 2025 16:58
- Added product_variant_id to cart_items for variant support.
- Implemented currency support with currencies, product_prices, and product_variant_prices tables.
- Updated order schema to include customer details and payment status.
- Introduced checkout and checkout_items tables to replace cart functionality.
- Enforced product variants requirement and added constraints for unique category names.
- Improved product deletion logic and ensured correct has_variants field values.
- Added checkout_session_id to orders for linking to checkout sessions.
- Fixed currency exchange rates to reflect accurate values.
- Added unique constraints to shipping rates to prevent duplicates.
…nts, orders, products, shipping, and users

- Implemented Create and Update requests for categories, checkouts, currencies, discounts, orders, products, and shipping methods.
- Added response structures for various operations including listing and retrieving entities.
- Introduced pagination and response DTOs for consistent API responses.
- Updated product handler to utilize new variant attributes structure.
- Refactored server initialization to use GORM instead of SQL package.
- Enhanced mock currency repository to align with new entity structures.
…tamp management and improve relationships

- Updated Currency, Discount, Order, Product, ProductVariant, ShippingMethod, ShippingRate, ShippingZone, User, and Webhook entities to embed gorm.Model for automatic ID and timestamp handling.
- Removed manual timestamp management in various methods across entities.
- Enhanced relationships between entities, including foreign key constraints and cascading behaviors.
- Introduced new methods for updating product variants and added price handling in ProductVariant.
- Added new repository methods for fetching products by SKU and ID with currency consideration.
- Updated API contracts to include prices in variant requests.
refactor: update config to remove PayPal settings and add DB_DRIVER

chore: add local docker-compose for SQLite development

chore: update main docker-compose for PostgreSQL configuration

docs: create DATABASE_SETUP.md for database configuration instructions

chore: update go.mod and go.sum for GORM and database drivers

refactor: simplify currency and product price entities

refactor: remove product price repository and related methods

refactor: enhance GORM initialization for SQLite and PostgreSQL

docs: update README for database setup and commands
…response DTOs

- Updated shipping_handler.go to replace dto with contracts for shipping options, methods, and rates.
- Removed unused shipping methods and routes in server.go.
- Refactored user_handler.go to utilize contracts for user registration and login responses.
- Simplified response creation in user registration and login by using new response functions.
- Cleaned up commented-out code for shipping methods and rates in server routes.
- Refactored PaymentTransactionRepository to TransactionRepository and updated method names.
- Added CategoryRepository for managing categories.
- Introduced CheckoutRepository for handling checkout operations.
- Created CurrencyRepository for currency management.
- Added DiscountRepository for managing discounts.
- Implemented OrderRepository for order-related operations.
- Developed ProductRepository for product management with variants.
- Created ProductVariantRepository for handling product variants.
- Added UserRepository for user management.
…-related migrations

- Deleted migrations for currency support, order customer details, product active status, default currency, cart tables, and checkout tables.
- Removed constraints and indexes related to legacy cart and checkout functionality.
- Cleaned up migrations for ensuring product variants and added unique constraints for shipping methods and categories.
- Updated migrations for adding currency and payment status to orders, including necessary indexes and data updates.
- Improved product deletion logic by removing unnecessary triggers and relying on application-level enforcement.
- Added a mock logger implementation to facilitate logging in tests.
- Created mock repositories for PaymentProvider, PaymentTransaction, Order, and Product to simulate database interactions.
- Developed a mock payment provider service to handle payment provider operations in tests.
- Implemented comprehensive test cases for each mock service to ensure expected behavior and error handling.
…ntities

- Implement tests for PaymentProvider including validation, methods, and constants.
- Add tests for PaymentTransaction covering creation, validation, metadata, and status updates.
- Create tests for Product and ProductVariant with focus on creation, validation, and variant management.
- Introduce tests for User entity covering creation, password management, and role validation.
- Ensure comprehensive coverage for all new functionalities and edge cases.
…orders, and discounts

- Implemented user seeding with role assignment and existence check.
- Added category seeding with hierarchical relationships.
- Enhanced product seeding to include variants and category mapping.
- Introduced order seeding with user and product variant associations.
- Added discount seeding with various types and constraints.
- Implemented shipping methods and zones seeding.
- Enhanced payment transaction seeding for completed orders.
- Improved checkout seeding with session management and item tracking.
- Updated clearData function to use DELETE for SQLite compatibility.
…, currencies, shipping, and users

- Implemented CategoryDTO for category representation.
- Created CheckoutDTO and related structures for checkout sessions.
- Added OrderDTO and OrderItemDTO for order management.
- Introduced ProductDTO and VariantDTO for product details.
- Developed DiscountDTO and AppliedDiscountDTO for discount handling.
- Established CurrencyDTO for currency representation.
- Created Shipping-related DTOs including ShippingMethodDetailDTO, ShippingZoneDTO, and ShippingRateDTO.
- Implemented UserDTO for user management.
- Generated TypeScript contracts for API interactions.
- Updated import paths for DTOs in various entity files to use the new location under internal/domain/dto.
- Removed old DTO files from internal/interfaces/api/contracts/dto as they have been migrated to internal/domain/dto.
- Added new DTO definitions for Category, Checkout, Common, Currency, Discount, Order, Product, Shipping, and User in the internal/domain/dto directory.
- Updated related contract files to reference the new DTOs.
- Cleaned up the readme and removed the todo file.
…scounts

- Updated Checkout and Order entities to store shipping and billing addresses as JSON.
- Introduced helper methods for setting and getting addresses and discounts in JSON format.
- Modified checkout and order processing logic to utilize new JSON methods for address and discount handling.
- Adjusted related use cases and repositories to accommodate changes in address storage.
- Enhanced webhook handling to allow requests without an Origin header.
- Separated webhook routes from main API routes for better organization and security.
… update PaymentTransaction to use it for metadata
gustaavik added 28 commits July 1, 2025 18:43
…iders

Migration cleanup payment providers
- Updated PaymentTransaction to allow multiple transactions per order type, enhancing support for partial captures and retries.
- Changed Metadata field in PaymentTransaction from common.StringMap to gorm.io/datatypes.JSONMap for better JSON handling.
- Modified Product entity to use gorm.io/datatypes.JSONSlice for Images, replacing common.StringSlice.
- Refactored ProductVariant to utilize gorm.io/datatypes for Attributes and Images, improving JSON storage.
- Implemented CreateOrUpdate method in PaymentTransactionRepository for upsert behavior, ensuring only one transaction per type per order.
- Updated payment provider service to accept map[string]interface{} for configuration, replacing common.JSONB.
- Enhanced repository methods to support JSON queries in a database-agnostic manner.
- Removed unused VariantAttributes struct and its associated methods from ProductVariant.
- Updated tests to reflect changes in transaction handling and repository methods.
…saction repository, and product repository

- Deleted the mock PaymentProviderService implementation used for testing payment provider functionalities.
- Removed the mock PaymentTransactionRepository implementation that handled payment transaction operations.
- Eliminated the mock ProductRepository implementation responsible for product management in tests.
… tracking

- Added idempotency key handling in MobilePay webhook events to prevent duplicate transactions.
- Implemented checks for existing transactions before recording new ones for authorization, capture, cancellation, expiration, and refund events.
- Introduced new tests for idempotency logic in MobilePay webhook handler.
- Enhanced transaction amount tracking in tests, ensuring accurate sums for authorized, captured, and refunded amounts.
- Updated Stripe webhook handler to include a placeholder for idempotency key.
Migrations cleanup and payment rewrite
@gustaavik gustaavik changed the title Development Almost complete project rewrite Jul 5, 2025
@gustaavik gustaavik merged commit c497ec5 into main Jul 5, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants