diff --git a/db/schema/schema.sql b/db/schema/schema.sql index df62bba..41a6752 100644 --- a/db/schema/schema.sql +++ b/db/schema/schema.sql @@ -1,12 +1,13 @@ CREATE TABLE IF NOT EXISTS instruments ( id INTEGER PRIMARY KEY AUTOINCREMENT, - symbol TEXT NOT NULL UNIQUE, + symbol TEXT NOT NULL, asset_type TEXT NOT NULL, exchange TEXT, quote_currency TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP + deleted_at TIMESTAMP, + UNIQUE(symbol, exchange) ); CREATE TABLE IF NOT EXISTS portfolios ( diff --git a/internal/db/migrations/20260411114506_internal_db_migrations_sqlite.initial_setup.sql b/internal/db/migrations/20260411114506_internal_db_migrations_sqlite.initial_setup.sql index 362882e..269b512 100644 --- a/internal/db/migrations/20260411114506_internal_db_migrations_sqlite.initial_setup.sql +++ b/internal/db/migrations/20260411114506_internal_db_migrations_sqlite.initial_setup.sql @@ -2,13 +2,14 @@ -- +goose StatementBegin CREATE TABLE IF NOT EXISTS instruments ( id INTEGER PRIMARY KEY AUTOINCREMENT, - symbol TEXT NOT NULL UNIQUE, + symbol TEXT NOT NULL, asset_type TEXT NOT NULL, exchange TEXT, quote_currency TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - deleted_at TIMESTAMP + deleted_at TIMESTAMP, + UNIQUE(symbol, exchange) ); CREATE TABLE IF NOT EXISTS portfolios ( diff --git a/internal/repository/instrument_repo.go b/internal/repository/instrument_repo.go index f96f2d1..bc388aa 100644 --- a/internal/repository/instrument_repo.go +++ b/internal/repository/instrument_repo.go @@ -73,7 +73,7 @@ func (r *InstrumentRepository) Create(ctx context.Context, in Instrument) (Instr "instrument %q on exchange %q: %w", in.Symbol, in.Exchange, - domain.ErrPositionAlreadyExists, + domain.ErrInstrumentAlreadyExists, ) }