diff --git a/repositories/dbmodels/db_sanction_check.go b/repositories/dbmodels/db_sanction_check.go new file mode 100644 index 00000000..2d04d086 --- /dev/null +++ b/repositories/dbmodels/db_sanction_check.go @@ -0,0 +1,25 @@ +package dbmodels + +import ( + "time" + + "github.com/checkmarble/marble-backend/utils" +) + +const TABLE_SANCTION_CHECKS = "sanction_checks" + +var SelectSanctionChecksColumn = utils.ColumnList[DBSanctionCheck]() + +type DBSanctionCheck struct { + Id string `db:"id"` + DecisionId string `db:"decision_id"` + Status string `db:"status"` + SearchInput []byte `db:"search_input"` + SearchDatasets []string `db:"search_datasets"` + SearchThreshold float64 `db:"search_threshold"` + IsManual bool `db:"is_manual"` + RequestedBy string `db:"requested_by"` + IsArchived bool `db:"is_archived"` + CreatedAt time.Time `db:"created_at"` + UpdatedAt time.Time `db:"updated_at"` +} diff --git a/repositories/dbmodels/db_sanction_check_match.go b/repositories/dbmodels/db_sanction_check_match.go new file mode 100644 index 00000000..2dab78fb --- /dev/null +++ b/repositories/dbmodels/db_sanction_check_match.go @@ -0,0 +1,23 @@ +package dbmodels + +import ( + "time" + + "github.com/checkmarble/marble-backend/utils" +) + +const TABLE_SANCTION_CHECK_MATCHES = "sanction_check_matches" + +var SelectSanctionCheckMatchesColumn = utils.ColumnList[DBSanctionCheckMatch]() + +type DBSanctionCheckMatch struct { + Id string `db:"id"` + SanctionCheckId string `db:"sanction_check_id"` + OpenSanctionEntityId string `db:"opensanction_entity_id"` + Status string `db:"status"` + QueryIds []string `db:"query_ids"` + Payload []byte `db:"payload"` + ReviewedBy string `db:"reviewed_by"` + CreatedAt time.Time `db:"created_at"` + UpdatedAt time.Time `db:"updated_at"` +} diff --git a/repositories/dbmodels/db_sanction_match_comment.go b/repositories/dbmodels/db_sanction_match_comment.go new file mode 100644 index 00000000..0ee34cd0 --- /dev/null +++ b/repositories/dbmodels/db_sanction_match_comment.go @@ -0,0 +1,19 @@ +package dbmodels + +import ( + "time" + + "github.com/checkmarble/marble-backend/utils" +) + +const TABLE_SANCTION_CHECK_MATCH_COMMENTS = "sanction_check_match_comments" + +var SelectSanctionCheckMatchCommentsColumn = utils.ColumnList[DBSanctionCheckMatchComment]() + +type DBSanctionCheckMatchComment struct { + Id string `db:"id"` + SanctionCheckMatchId string `db:"sanction_check_match_id"` + CommentedBy string `db:"commented_by"` + Comment string `db:"comment"` + CreatedAt time.Time `db:"created_at"` +} diff --git a/repositories/migrations/20250116141900_sanction_check.sql b/repositories/migrations/20250116141900_sanction_check.sql new file mode 100644 index 00000000..7924d32d --- /dev/null +++ b/repositories/migrations/20250116141900_sanction_check.sql @@ -0,0 +1,83 @@ +-- +goose Up +-- +goose StatementBegin + +create table sanction_checks ( + id uuid default uuid_generate_v4(), + decision_id uuid not null, + + status text check (status in ('confirmed_hit', 'in_review', 'error')), + search_input jsonb, + search_datasets text[], + search_threshold float, + is_manual bool default false, + requested_by uuid null, + + is_archived bool default false, + created_at timestamp with time zone default now(), + updated_at timestamp with time zone default now(), + + primary key (id), + constraint fk_decision + foreign key (decision_id) + references decisions (id), + constraint fk_user + foreign key (requested_by) + references users (id) +); + +create index idx_sanction_checks_decision_id on sanction_checks (decision_id); + +create table sanction_check_matches ( + id uuid default uuid_generate_v4(), + sanction_check_id uuid not null, + + opensanction_entity_id text not null, + status text check (status in ('pending', 'confirmed_hit', 'no_hit')), + query_ids text[], + payload jsonb, + reviewed_by uuid, + + created_at timestamp with time zone default now(), + updated_at timestamp with time zone default now(), + + primary key (id), + constraint fk_sanction_check + foreign key (sanction_check_id) + references sanction_checks (id), + constraint fk_user + foreign key (reviewed_by) + references users (id) +); + +create index idx_sanction_check_matches_sanction_check_id on sanction_check_matches (sanction_check_id); + +create table sanction_check_match_comments ( + id uuid default uuid_generate_v4(), + sanction_check_match_id uuid not null, + + commented_by uuid not null, + comment text, + + created_at timestamp with time zone default now(), + + primary key (id), + constraint fk_sanction_check_match + foreign key (sanction_check_match_id) + references sanction_check_matches (id), + constraint fk_user + foreign key (commented_by) + references users (id) +); + +create index idx_sanction_check_match_comments_sanction_check_match_id on sanction_check_match_comments (sanction_check_match_id); + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin + +drop table sanction_checks; +drop table sanction_check_matches; +drop table sanction_check_match_comments; + +-- +goose StatementEnd \ No newline at end of file