feat: завершён этап 1 - Фундамент Core Service

- Удалены зависимости: grpc, redis, prometheus
- Упрощена конфигурация (Server, Database, JWT)
- Создан логгер на основе logrus
- Добавлено подключение к PostgreSQL
- Создана миграция с базовыми таблицами
- Обновлены модели с валидацией
- Создан базовый API сервер с health check
- Добавлен .env.example

Готово для этапа 2 - Аутентификация
This commit is contained in:
2025-08-27 14:40:48 +04:00
parent 725d4c4474
commit 9777114e16
10 changed files with 521 additions and 164 deletions

View File

@@ -0,0 +1,72 @@
-- Initial schema for ERP MVP
-- Migration: 001_initial_schema.sql
-- Enable UUID extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- Organizations table
CREATE TABLE organizations (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name VARCHAR(255) NOT NULL,
type VARCHAR(100),
settings JSONB,
created_at TIMESTAMP DEFAULT NOW()
);
-- Users table
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
organization_id UUID REFERENCES organizations(id) ON DELETE CASCADE,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
role VARCHAR(50) DEFAULT 'user',
created_at TIMESTAMP DEFAULT NOW()
);
-- Storage locations table
CREATE TABLE storage_locations (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
organization_id UUID REFERENCES organizations(id) ON DELETE CASCADE,
parent_id UUID REFERENCES storage_locations(id) ON DELETE CASCADE,
name VARCHAR(255) NOT NULL,
address VARCHAR(100) NOT NULL,
type VARCHAR(50) NOT NULL,
coordinates JSONB,
created_at TIMESTAMP DEFAULT NOW()
);
-- Items table
CREATE TABLE items (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
organization_id UUID REFERENCES organizations(id) ON DELETE CASCADE,
name VARCHAR(255) NOT NULL,
description TEXT,
category VARCHAR(100),
created_at TIMESTAMP DEFAULT NOW()
);
-- Item placements table
CREATE TABLE item_placements (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
organization_id UUID REFERENCES organizations(id) ON DELETE CASCADE,
item_id UUID REFERENCES items(id) ON DELETE CASCADE,
location_id UUID REFERENCES storage_locations(id) ON DELETE CASCADE,
quantity INTEGER DEFAULT 1,
created_at TIMESTAMP DEFAULT NOW()
);
-- Indexes for better performance
CREATE INDEX idx_users_organization_id ON users(organization_id);
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_storage_locations_organization_id ON storage_locations(organization_id);
CREATE INDEX idx_storage_locations_parent_id ON storage_locations(parent_id);
CREATE INDEX idx_storage_locations_address ON storage_locations(address);
CREATE INDEX idx_items_organization_id ON items(organization_id);
CREATE INDEX idx_items_name ON items(name);
CREATE INDEX idx_items_category ON items(category);
CREATE INDEX idx_item_placements_organization_id ON item_placements(organization_id);
CREATE INDEX idx_item_placements_item_id ON item_placements(item_id);
CREATE INDEX idx_item_placements_location_id ON item_placements(location_id);
-- Unique constraints
CREATE UNIQUE INDEX idx_storage_locations_org_address ON storage_locations(organization_id, address);