diff --git a/migrations/000011_create_data_sources.down.sql b/migrations/000011_create_data_sources.down.sql new file mode 100644 index 0000000..6edc870 --- /dev/null +++ b/migrations/000011_create_data_sources.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS data_sources; diff --git a/migrations/000011_create_data_sources.up.sql b/migrations/000011_create_data_sources.up.sql new file mode 100644 index 0000000..1fa2ab5 --- /dev/null +++ b/migrations/000011_create_data_sources.up.sql @@ -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); diff --git a/migrations/up/000011_create_data_sources.up.sql b/migrations/up/000011_create_data_sources.up.sql new file mode 100644 index 0000000..1fa2ab5 --- /dev/null +++ b/migrations/up/000011_create_data_sources.up.sql @@ -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); diff --git a/src/db_models.py b/src/db_models.py index ee92b8b..4175af7 100644 --- a/src/db_models.py +++ b/src/db_models.py @@ -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 # ---------------------------------------------------------------------------