e84c73e6d7
Add a new projection for handling the creation of bands with support for upserts in the database. Update the README to document the DanceFinder domain package's architecture and naming conventions, aligning with Domain-Driven Design and Event Sourcing principles. New dependencies are included for database testing and event sourcing functionalities. refactor(schema): rename UUID columns to standard IDs Simplify database schema by removing dual identity system and standardizing column names. All tables now use a single UUID-type `id` column, with foreign keys renamed to `band_id` and `dance_hall_id`, enhancing clarity and consistency in identifying records. Update all related code to reflect these changes, improving developer experience and maintaining data integrity throughout the migration. feat: add truncate functionality for projection tables Add functions to truncate the band, dance_hall, event, and user preference tables to enable rebuilding projections from events. Eliminate foreign key constraints between read view tables to ensure referential integrity is maintained at the write side and allow independent resets of read models. Include documentation explaining the architectural decision against foreign key usage within the system. feat(migrations): rename UUID columns to id and simplify schema Update database schema by renaming UUID columns to 'id' across event, band, dance_hall, ignored_band, and ignored_dance_hall tables. Drop old numeric IDs and foreign key constraints to streamline the schema, ensuring UUIDs serve as primary identifiers. Recreate necessary foreign key constraints with the updated column names to maintain referential integrity. feat(database): replace integer IDs with UUIDs for events Update event and associated entities to use UUIDs instead of integer IDs. Modify SQL queries and data structures to ensure band and dance hall identifiers are UUIDs, enhancing the system's scalability and integration capabilities.
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package domain
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"gitlab.com/unboundsoftware/eventsourced/eventsourced"
|
|
)
|
|
|
|
// Band is the aggregate root for band entities
|
|
type Band struct {
|
|
eventsourced.BaseAggregate
|
|
Name string
|
|
Created time.Time
|
|
}
|
|
|
|
// Apply applies events to rebuild the Band aggregate state
|
|
func (b *Band) Apply(event eventsourced.Event) error {
|
|
switch e := event.(type) {
|
|
case *BandCreated:
|
|
b.SetIdentity(e.AggregateIdentity())
|
|
b.Name = e.Name
|
|
b.Created = e.When()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// BandCreated is the domain event when a band is created
|
|
type BandCreated struct {
|
|
eventsourced.BaseEvent
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// CreateBand is the command to create a new band
|
|
type CreateBand struct {
|
|
Name string
|
|
}
|
|
|
|
// Validate ensures the command is valid
|
|
func (c *CreateBand) Validate(ctx context.Context, aggregate eventsourced.Aggregate) error {
|
|
if c.Name == "" {
|
|
return ErrBandNameRequired
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Event produces the BandCreated event from this command
|
|
func (c *CreateBand) Event(ctx context.Context) eventsourced.Event {
|
|
return &BandCreated{
|
|
Name: c.Name,
|
|
}
|
|
}
|