Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions migrations/000011_create_data_sources.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS data_sources;
22 changes: 22 additions & 0 deletions migrations/000011_create_data_sources.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE IF NOT EXISTS data_sources (
source_id SERIAL PRIMARY KEY,
partner_id INTEGER REFERENCES partners(partner_id) ON DELETE SET NULL,
created_by_user_id INTEGER REFERENCES users(user_id) ON DELETE SET NULL,
source_type VARCHAR(50) NOT NULL,
entity_type VARCHAR(50) NOT NULL,
entity_id INTEGER NOT NULL,
title VARCHAR(255) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'unknown'
CHECK (status IN ('active', 'paused', 'error', 'deleted', 'unknown')),
last_data_at TIMESTAMP WITH TIME ZONE,
last_error TEXT,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE (entity_type, entity_id)
);

CREATE INDEX idx_data_sources_partner_id ON data_sources(partner_id);
CREATE INDEX idx_data_sources_entity ON data_sources(entity_type, entity_id);
CREATE INDEX idx_data_sources_source_type ON data_sources(source_type);
CREATE INDEX idx_data_sources_status ON data_sources(status);
22 changes: 22 additions & 0 deletions migrations/up/000011_create_data_sources.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE IF NOT EXISTS data_sources (
source_id SERIAL PRIMARY KEY,
partner_id INTEGER REFERENCES partners(partner_id) ON DELETE SET NULL,
created_by_user_id INTEGER REFERENCES users(user_id) ON DELETE SET NULL,
source_type VARCHAR(50) NOT NULL,
entity_type VARCHAR(50) NOT NULL,
entity_id INTEGER NOT NULL,
title VARCHAR(255) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'unknown'
CHECK (status IN ('active', 'paused', 'error', 'deleted', 'unknown')),
last_data_at TIMESTAMP WITH TIME ZONE,
last_error TEXT,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE (entity_type, entity_id)
);

CREATE INDEX idx_data_sources_partner_id ON data_sources(partner_id);
CREATE INDEX idx_data_sources_entity ON data_sources(entity_type, entity_id);
CREATE INDEX idx_data_sources_source_type ON data_sources(source_type);
CREATE INDEX idx_data_sources_status ON data_sources(status);
5 changes: 0 additions & 5 deletions src/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,6 @@ class DataSource(Base):
UniqueConstraint("entity_type", "entity_id", name="uq_source_entity"),
)

"""
Дополнение к db_models.py — модели OccupancyObservation и Forecast.
Добавь этот блок в конец существующего src/db_models.py.
"""

# ---------------------------------------------------------------------------
# Occupancy Observations
# ---------------------------------------------------------------------------
Expand Down
Loading