Demonstrates how to create custom tables with foreign key relationships to the App Server's SHOPWARE_SHOP table.
Prerequisite: Understand custom-db-migration first. This example builds on those concepts.
- Store shop-specific data - Track information per registered shop
- Ensure referential integrity - Prevent orphaned records
- Automatic cleanup - Related data removed when shop unregisters
db-shop-reference-example/
├── src/main/java/com/appbackend/
│ ├── entity/EventLog.java # JPA entity with FK to SHOPWARE_SHOP
│ └── repository/EventLogRepository.java
├── src/main/resources/db/changelog/
│ └── changesets/0001-add-event-log.xml # Table with FK constraint
├── manifest.xml # Webhooks for event logging
└── build.gradle
cd examples/db-shop-reference-example
./gradlew bootRunThe server will start on http://localhost:8080.
<column name="SHOP_ID" type="BIGINT">
<constraints nullable="false"
foreignKeyName="fk_event_log_shop"
references="SHOPWARE_SHOP(ID)"/>
</column>See EventLog.java:
@Column(name = "SHOP_ID", nullable = false)
private Long shopId; // References SHOPWARE_SHOP.IDNote: We use Long shopId instead of @ManyToOne because SHOPWARE_SHOP is managed internally by the App Server.
List<EventLog> findByShopIdOrderByReceivedAtDesc(Long shopId);- Zip the
DatabaseExampleAppdirectory - Upload via Shopware Administration → Extensions → My Extensions → Upload Extension
To trigger events in Shopware:
Create/edit an order:
- Go to Orders in Shopware Administration
- Create or edit an order →
order.writtenevent is logged
Create/edit a product:
- Go to Products
- Create or edit a product →
product.writtenevent is logged
Create/edit a customer:
- Go to Customers
- Create or edit a customer →
customer.writtenevent is logged
Check the logs:
sqlite3 shopware_app.db "SELECT * FROM EVENT_LOG ORDER BY RECEIVED_AT DESC"| Problem | Solution |
|---|---|
FOREIGN KEY constraint failed |
Shop must exist before inserting events |
Table SHOPWARE_SHOP doesn't exist |
Include app-server-changelog-master.xml first in your changelog |
- custom-db-migration example - Migration basics
- Shopware App Server Documentation