1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 16:19:35 +01:00

feat(inventory): Charge einbuchen (addBatch) (#5)

StockBatch als Child-Entity im Stock-Aggregat mit BatchReference
(batchId + batchType), Quantity, ExpiryDate und Status AVAILABLE.
POST /api/inventory/stocks/{stockId}/batches → 201.
This commit is contained in:
Sebastian Frick 2026-02-19 22:26:24 +01:00
parent 5224001dd7
commit 6feb3a9f1c
26 changed files with 1325 additions and 10 deletions

View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet id="014-create-stock-batches-table" author="effigenix">
<createTable tableName="stock_batches">
<column name="id" type="VARCHAR(36)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="stock_id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="batch_id" type="VARCHAR(100)">
<constraints nullable="false"/>
</column>
<column name="batch_type" type="VARCHAR(20)">
<constraints nullable="false"/>
</column>
<column name="quantity_amount" type="DECIMAL(19,6)">
<constraints nullable="false"/>
</column>
<column name="quantity_unit" type="VARCHAR(20)">
<constraints nullable="false"/>
</column>
<column name="expiry_date" type="DATE">
<constraints nullable="false"/>
</column>
<column name="status" type="VARCHAR(20)" defaultValue="AVAILABLE">
<constraints nullable="false"/>
</column>
<column name="received_at" type="TIMESTAMP WITH TIME ZONE">
<constraints nullable="false"/>
</column>
</createTable>
<addForeignKeyConstraint baseTableName="stock_batches" baseColumnNames="stock_id"
referencedTableName="stocks" referencedColumnNames="id"
constraintName="fk_stock_batches_stock"
onDelete="CASCADE"/>
<addUniqueConstraint tableName="stock_batches" columnNames="stock_id, batch_id, batch_type"
constraintName="uq_stock_batch_reference"/>
<createIndex tableName="stock_batches" indexName="idx_stock_batches_stock_id">
<column name="stock_id"/>
</createIndex>
<sql>
ALTER TABLE stock_batches ADD CONSTRAINT chk_stock_batch_type
CHECK (batch_type IN ('PRODUCED', 'PURCHASED'));
</sql>
<sql>
ALTER TABLE stock_batches ADD CONSTRAINT chk_stock_batch_status
CHECK (status IN ('AVAILABLE', 'EXPIRING_SOON', 'BLOCKED', 'EXPIRED'));
</sql>
</changeSet>
</databaseChangeLog>

View file

@ -18,5 +18,6 @@
<include file="db/changelog/changes/011-create-recipe-ingredients-table.xml"/>
<include file="db/changelog/changes/012-create-recipe-production-steps-table.xml"/>
<include file="db/changelog/changes/013-create-stock-schema.xml"/>
<include file="db/changelog/changes/014-create-stock-batches-table.xml"/>
</databaseChangeLog>