✨ Add configuration for Code Review Automation and enhance .gitignore. Introduce .coderabbit.yml for automated reviews with profiles for correctness, maintainability, security, and performance. Update paths to include relevant directories and exclude generated files. Modify .gitignore to include coverage reports and generated files. Refactor Docker Compose to use updated paths for database initialization scripts. Update Go module dependencies and enhance Makefile with new code generation tasks. Transition domain models to a new DTO structure for better separation of concerns.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"caatsm/internal/adapter"
|
||||
"caatsm/internal/adapter/mapper"
|
||||
"caatsm/internal/model"
|
||||
obsmetrics "caatsm/internal/observability/metrics"
|
||||
"caatsm/internal/adapter/dto"
|
||||
"caatsm/internal/port"
|
||||
obsmetrics "caatsm/internal/infra/metrics"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Repository implements the adapter.Repository interface using PostgreSQL
|
||||
// Repository implements the port.Repository interface using PostgreSQL
|
||||
type Repository struct {
|
||||
pool *pgxpool.Pool
|
||||
mapper *mapper.TelegramMapper
|
||||
@@ -27,7 +27,7 @@ type Repository struct {
|
||||
}
|
||||
|
||||
// ProvideRepository creates a PostgreSQL repository
|
||||
func ProvideRepository(pool *pgxpool.Pool, logger *zap.Logger) (adapter.Repository, error) {
|
||||
func ProvideRepository(pool *pgxpool.Pool, logger *zap.Logger) (port.Repository, error) {
|
||||
return &Repository{
|
||||
pool: pool,
|
||||
mapper: mapper.NewTelegramMapper(),
|
||||
@@ -36,7 +36,7 @@ func ProvideRepository(pool *pgxpool.Pool, logger *zap.Logger) (adapter.Reposito
|
||||
}
|
||||
|
||||
// InsertOne inserts a single telegram message
|
||||
func (r *Repository) InsertOne(ctx context.Context, msg *model.ParsedTelegram) error {
|
||||
func (r *Repository) InsertOne(ctx context.Context, msg *dto.ParsedTelegram) error {
|
||||
ctx, span := otel.Tracer("caatsm/postgres").Start(ctx, "Repository.InsertOne")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("db.table", "aviation.telegrams"))
|
||||
@@ -114,7 +114,7 @@ func (r *Repository) InsertOne(ctx context.Context, msg *model.ParsedTelegram) e
|
||||
}
|
||||
|
||||
// InsertBatch inserts multiple telegram messages in a batch using CopyFrom
|
||||
func (r *Repository) InsertBatch(ctx context.Context, msgs []*model.ParsedTelegram) error {
|
||||
func (r *Repository) InsertBatch(ctx context.Context, msgs []*dto.ParsedTelegram) error {
|
||||
ctx, span := otel.Tracer("caatsm/postgres").Start(ctx, "Repository.InsertBatch")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("db.table", "aviation.telegrams"))
|
||||
@@ -169,7 +169,7 @@ func (r *Repository) InsertBatch(ctx context.Context, msgs []*model.ParsedTelegr
|
||||
}
|
||||
|
||||
// InsertRaw inserts a failed telegram into aviation.telegrams_raw for post-processing.
|
||||
func (r *Repository) InsertRaw(ctx context.Context, msg *model.ParsedTelegram) error {
|
||||
func (r *Repository) InsertRaw(ctx context.Context, msg *dto.ParsedTelegram) error {
|
||||
ctx, span := otel.Tracer("caatsm/postgres").Start(ctx, "Repository.InsertRaw")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("db.table", "aviation.telegrams_raw"))
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
CREATE SCHEMA IF NOT EXISTS aviation;
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS timescaledb;
|
||||
|
||||
CREATE TABLE aviation.telegrams (
|
||||
uuid UUID NOT NULL,
|
||||
message_id TEXT,
|
||||
date_time TEXT,
|
||||
priority_indicator TEXT,
|
||||
primary_address TEXT,
|
||||
secondary_addresses TEXT,
|
||||
originator TEXT,
|
||||
originator_date_time TEXT,
|
||||
category TEXT,
|
||||
content TEXT,
|
||||
body_data JSONB,
|
||||
status TEXT NOT NULL DEFAULT 'parsed',
|
||||
error_reason TEXT,
|
||||
received_at TIMESTAMPTZ NOT NULL,
|
||||
parsed_at TIMESTAMPTZ,
|
||||
dispatched_at TIMESTAMPTZ,
|
||||
need_dispatch BOOLEAN,
|
||||
PRIMARY KEY (uuid, received_at)
|
||||
);
|
||||
|
||||
SELECT create_hypertable('aviation.telegrams', 'received_at', if_not_exists => TRUE);
|
||||
|
||||
-- Indexes for better query performance
|
||||
CREATE INDEX idx_telegrams_message_id ON aviation.telegrams (message_id);
|
||||
CREATE INDEX idx_telegrams_date_time ON aviation.telegrams (date_time);
|
||||
CREATE INDEX idx_telegrams_priority_indicator ON aviation.telegrams (priority_indicator);
|
||||
CREATE INDEX idx_telegrams_primary_address ON aviation.telegrams (primary_address);
|
||||
CREATE INDEX idx_telegrams_received_at ON aviation.telegrams (received_at);
|
||||
CREATE INDEX idx_telegrams_uuid ON aviation.telegrams (uuid);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS aviation.telegrams_raw (
|
||||
uuid UUID NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
error_reason TEXT,
|
||||
content TEXT NOT NULL,
|
||||
received_at TIMESTAMPTZ NOT NULL,
|
||||
metadata JSONB,
|
||||
PRIMARY KEY (uuid, received_at)
|
||||
);
|
||||
Reference in New Issue
Block a user